Class: Odesk::Api::Client
- Inherits:
-
Object
- Object
- Odesk::Api::Client
- Defined in:
- lib/odesk/api/client.rb
Overview
Client for accessing API
Constant Summary collapse
- DATA_FORMAT =
'json'
- OVERLOAD_VAR =
"http_method"
- URI_AUTH =
"/services/api/auth"
- URI_RTOKEN =
"/auth/v1/oauth/token/request"
- URI_ATOKEN =
"/auth/v1/oauth/token/access"
Instance Attribute Summary collapse
-
#epoint ⇒ Object
Returns the value of attribute epoint.
-
#url_atoken ⇒ Object
readonly
Returns the value of attribute url_atoken.
-
#url_auth ⇒ Object
readonly
Returns the value of attribute url_auth.
-
#url_rtoken ⇒ Object
readonly
Returns the value of attribute url_rtoken.
Instance Method Summary collapse
-
#delete(uri, params = {}) ⇒ Object
Run DELETE request.
-
#full_url(uri) ⇒ Object
Get full URL.
-
#get(uri, params = {}) ⇒ Object
Run GET request.
-
#get_access_token(verifier) ⇒ Object
Finish auth process and get access token.
-
#get_authorization_url ⇒ Object
Start auth process and get authorization token.
-
#get_uri_with_format(uri) ⇒ Object
Get URI with :format.
-
#initialize(config) ⇒ Client
constructor
Init client.
-
#post(uri, params = {}) ⇒ Object
Run POST request.
-
#put(uri, params = {}) ⇒ Object
Run PUT request.
Constructor Details
#initialize(config) ⇒ Client
Init client
Arguments:
config: (Config)
36 37 38 39 40 41 |
# File 'lib/odesk/api/client.rb', line 36 def initialize(config) $LOG.i('initializing client') @config = config @epoint = Odesk::Api::DEFAULT_EPOINT @url_auth, @url_rtoken, @url_atoken = Odesk::Api::BASE_HOST + URI_AUTH, self.full_url(URI_RTOKEN), self.full_url(URI_ATOKEN) end |
Instance Attribute Details
#epoint ⇒ Object
Returns the value of attribute epoint.
29 30 31 |
# File 'lib/odesk/api/client.rb', line 29 def epoint @epoint end |
#url_atoken ⇒ Object (readonly)
Returns the value of attribute url_atoken.
30 31 32 |
# File 'lib/odesk/api/client.rb', line 30 def url_atoken @url_atoken end |
#url_auth ⇒ Object (readonly)
Returns the value of attribute url_auth.
30 31 32 |
# File 'lib/odesk/api/client.rb', line 30 def url_auth @url_auth end |
#url_rtoken ⇒ Object (readonly)
Returns the value of attribute url_rtoken.
30 31 32 |
# File 'lib/odesk/api/client.rb', line 30 def url_rtoken @url_rtoken end |
Instance Method Details
#delete(uri, params = {}) ⇒ Object
Run DELETE request
Arguments:
uri: (String)
param: (Hash)
109 110 111 |
# File 'lib/odesk/api/client.rb', line 109 def delete(uri, params = {}) send_request(uri, :delete, params) end |
#full_url(uri) ⇒ Object
Get full URL
114 115 116 |
# File 'lib/odesk/api/client.rb', line 114 def full_url(uri) # :nodoc: Odesk::Api::BASE_HOST + '/' + (@epoint) + get_uri_with_format(uri); end |
#get(uri, params = {}) ⇒ Object
Run GET request
Arguments:
uri: (String)
param: (Hash)
82 83 84 |
# File 'lib/odesk/api/client.rb', line 82 def get(uri, params = {}) send_request(uri, :get, params) end |
#get_access_token(verifier) ⇒ Object
Finish auth process and get access token
Arguments:
verifier: (String)
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/odesk/api/client.rb', line 65 def get_access_token(verifier) $LOG.i "getting access token pair" @access_token = @request_token.get_access_token(:oauth_verifier => verifier) $LOG.i "got access token pair", @access_token $LOG.i "save access token data in config object" @config.access_token = @access_token.token @config.access_secret = @access_token.secret @access_token end |
#get_authorization_url ⇒ Object
Start auth process and get authorization token
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/odesk/api/client.rb', line 44 def $LOG.i "requesting autorization token" @consumer=OAuth::Consumer.new @config.consumer_key, @config.consumer_secret, {:site => Odesk::Api::BASE_HOST, :request_token_path => '/' + Odesk::Api::DEFAULT_EPOINT + URI_RTOKEN, :access_token_path => '/' + Odesk::Api::DEFAULT_EPOINT + URI_ATOKEN, :authorize_path => URI_AUTH, :signature_method => @config.signature_method} @request_token = @consumer.get_request_token $LOG.i "got request token pair", @request_token $LOG.i "building authorization url, which is", @request_token. @request_token. end |
#get_uri_with_format(uri) ⇒ Object
Get URI with :format
119 120 121 |
# File 'lib/odesk/api/client.rb', line 119 def get_uri_with_format(uri) # :nodoc: uri + ((@epoint == 'api') ? '.' + DATA_FORMAT : '') end |
#post(uri, params = {}) ⇒ Object
Run POST request
Arguments:
uri: (String)
param: (Hash)
91 92 93 |
# File 'lib/odesk/api/client.rb', line 91 def post(uri, params = {}) send_request(uri, :post, params) end |
#put(uri, params = {}) ⇒ Object
Run PUT request
Arguments:
uri: (String)
param: (Hash)
100 101 102 |
# File 'lib/odesk/api/client.rb', line 100 def put(uri, params = {}) send_request(uri, :put, params) end |