Class: Freelancer::Client
- Inherits:
-
Object
- Object
- Freelancer::Client
- Extended by:
- API
- Defined in:
- lib/freelancer/client.rb
Instance Attribute Summary collapse
-
#consumer_options ⇒ Object
readonly
Returns the value of attribute consumer_options.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
-
#consumer_token ⇒ Object
readonly
Returns the value of attribute consumer_token.
Instance Method Summary collapse
-
#access_token ⇒ Object
Get the current oAuth access token.
-
#api_get(method, options = {}) ⇒ Object
Execute a GET-request for the specified API method.
-
#api_get_raw(method, options = {}) ⇒ Object
Execute a GET-request for the specified API method and return the raw result.
-
#authorize_from_access(access_token, access_secret) ⇒ Object
Authorize a user from an oAuth access token.
-
#authorize_from_request(request_token, request_secret, verifier) ⇒ Object
Authorize a user from an oAuth request.
-
#consumer ⇒ Object
Get the current oAuth consumer instance.
-
#initialize(consumer_token, consumer_secret, consumer_options = {}) ⇒ Client
constructor
Initialize a new Freelancer API client.
-
#request_token(options = {}) ⇒ Object
Get the current oAuth request token.
-
#set_callback_url(url) ⇒ Object
Set the callback URL for an oAuth request.
Methods included from API
Constructor Details
#initialize(consumer_token, consumer_secret, consumer_options = {}) ⇒ Client
Initialize a new Freelancer API client
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/freelancer/client.rb', line 21 def initialize(consumer_token, consumer_secret, = {}) = { :request_token_path => "/RequestRequestToken/requestRequestToken.xml", :authorize_url => "http://www.sandbox.freelancer.com/users/api-token/auth.php", :access_token_path => "/RequestAccessToken/requestAccessToken.xml", :scheme => :query_string, :http_method => :get } @consumer_token, @consumer_secret, @consumer_options = consumer_token, consumer_secret, .merge() @api_endpoint = "http://api.sandbox.freelancer.com" end |
Instance Attribute Details
#consumer_options ⇒ Object (readonly)
Returns the value of attribute consumer_options.
18 19 20 |
# File 'lib/freelancer/client.rb', line 18 def @consumer_options end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
18 19 20 |
# File 'lib/freelancer/client.rb', line 18 def consumer_secret @consumer_secret end |
#consumer_token ⇒ Object (readonly)
Returns the value of attribute consumer_token.
18 19 20 |
# File 'lib/freelancer/client.rb', line 18 def consumer_token @consumer_token end |
Instance Method Details
#access_token ⇒ Object
Get the current oAuth access token
62 63 64 |
# File 'lib/freelancer/client.rb', line 62 def access_token @access_token_instance ||= ::OAuth::AccessToken.new(consumer, @access_token, @access_secret) end |
#api_get(method, options = {}) ⇒ Object
Execute a GET-request for the specified API method
72 73 74 75 76 |
# File 'lib/freelancer/client.rb', line 72 def api_get(method, = {}) response = access_token.get(to_uri(method, )) raise_api_errors!(response) return response.body end |
#api_get_raw(method, options = {}) ⇒ Object
Execute a GET-request for the specified API method and return the raw result.
80 81 82 83 84 |
# File 'lib/freelancer/client.rb', line 80 def api_get_raw(method, = {}) response = access_token.get(to_uri(method, )) raise_api_errors!(response) response.body end |
#authorize_from_access(access_token, access_secret) ⇒ Object
Authorize a user from an oAuth access token
67 68 69 |
# File 'lib/freelancer/client.rb', line 67 def (access_token, access_secret) @access_token, @access_secret = access_token, access_secret end |
#authorize_from_request(request_token, request_secret, verifier) ⇒ Object
Authorize a user from an oAuth request
53 54 55 56 57 58 59 |
# File 'lib/freelancer/client.rb', line 53 def (request_token, request_secret, verifier) request_token = ::OAuth::RequestToken.new(consumer, request_token, request_secret) access_token = request_token.get_access_token(:oauth_verifier => verifier) @access_token, @access_secret = access_token.token, access_token.secret end |
#consumer ⇒ Object
Get the current oAuth consumer instance
37 38 39 |
# File 'lib/freelancer/client.rb', line 37 def consumer @consumer ||= ::OAuth::Consumer.new(consumer_token, consumer_secret, { :site => @api_endpoint }.merge()) end |
#request_token(options = {}) ⇒ Object
Get the current oAuth request token
48 49 50 |
# File 'lib/freelancer/client.rb', line 48 def request_token( = {}) @request_token_instance ||= consumer.get_request_token() end |
#set_callback_url(url) ⇒ Object
Set the callback URL for an oAuth request
42 43 44 45 |
# File 'lib/freelancer/client.rb', line 42 def set_callback_url(url) clear_request_token request_token :oauth_callback => url end |