2012-02-10 5 views
0

と非RailsのRESTのAPIを消費...実際にも、「休息」の部分は疑問であるが、彼らは試してみました:は、私は非RailsのRESTのAPIに対してActiveResourceを使用していますActiveResource

Although RESTful applications are ideally stateless, the ALM platform requires sessions to manage locking, client life time, and perform other basic tasks. Session management is performed using a cookie named QCSession.

をとにかく、私は必要1つのGETを「認証ポイント/認証」に発行してユーザーを認証し、クッキーを取り戻すこと。どのようにそれを行うか分からない。ここに私のものがありますが、私は404エラーを受け取ります:

class AlmActiveResource < ActiveResource::Base 
    attr_accessor :lwsso_cookie, :qcsession_cookie 

    self.site  = "http://alm_url/qcbin/" 
    self.user  = "name" 
    self.password = "pw" 

    def self.authentication 
    @auth_point = "authentication-point/authenticate" 
    self.prefix(@auth_point) 
    meow = self.get(:authenticate) 
    Rails.logger.debug("Meow: #{meow.inspect}") 

    end 
end 

答えて

2

私はまったく同じ問題を抱えていました。私はついにそれをALMと話すためにすべてのものをコントローラーに入れなければなりませんでした。それは最高ではありませんが、それは動作します。ここでReleaseCyclesコントローラ内のindexアクションです:

def index 
    conn=getAuthenticatedCurl 
    conn.url="#{$HPQC_REST_URL}/release-cycles" 
    conn.perform 
    results=conn.response_code 
    hash=Hash.from_xml(conn.body_str) 
    respond_to do |format| 
     format.html { render :xml => hash } 
     format.xml { render :xml => hash } 
     format.json { render :json => hash } 
    end 
    conn.url=$HPQC_LOGOUT_URL 
    conn.perform 
    conn.close 
    return results 
end 

私は、get ApplicationControllerにで "getAuthenticatedCurl" を作成しました。それはきれいではありませんが、それが動作し、それが高速です

$HPQC_HOST = "http://<your_alm_server>:8080" 
    $HPQC_REST_URL = "#{$HPQC_HOST}/qcbin/rest/domains/<DOMAIN>/projects/<PROJECT>" 
    $HPQC_LOGIN_URL = "#{$HPQC_HOST}/qcbin/authentication-point/authenticate" 
    $HPQC_LOGOUT_URL = "#{$HPQC_HOST}/qcbin/authentication-point/logout" 

    def getAuthenticatedCurl 
    @_conn = Curl::Easy.new($HPQC_LOGIN_URL) 
    @_conn.verbose = true 
    @_conn.http_auth_types = :basic 
    @_conn.userpwd = '<username>:<password>' 
    @_conn.enable_cookies = true 
    @_conn.cookiejar = 'cookies.txt' 
    @_conn.perform #creates the first cookie instance, which allows subsequent calls to the HPQC API 
    puts "connected...." 
    return @_conn 
    end 

:ように見えます。私の次のステップは、ActiveResourceと同じことをすることです。希望と幸運を願っています!

+0

Mad props!ありがとうございました。 – ScottJShea

関連する問題