class Upwork::Api::Client
Client
for accessing API
Constants
- DATA_FORMAT
- OVERLOAD_VAR
- URI_ATOKEN
- URI_AUTH
- URI_RTOKEN
Attributes
epoint[RW]
url_atoken[R]
url_auth[R]
url_rtoken[R]
Public Class Methods
new(config)
click to toggle source
Init client
Arguments:
config: (Config)
# File lib/upwork/api/client.rb, line 35 def initialize(config) $LOG.i('initializing client') @config = config @epoint = Upwork::Api::DEFAULT_EPOINT @url_auth, @url_rtoken, @url_atoken = URI_AUTH, URI_RTOKEN, URI_ATOKEN @tenant_id = nil @oauth2_client = OAuth2::Client.new( @config.client_id, @config.client_secret, :site => Upwork::Api::BASE_HOST, :authorize_url => @url_auth, :token_url => @url_atoken, :connection_opts => { :headers => {'User-Agent' => 'Github Upwork API Ruby Client' }} ) end
Public Instance Methods
delete(uri, params = {})
click to toggle source
Run DELETE request
Arguments:
uri: (String) param: (Hash)
# File lib/upwork/api/client.rb, line 121 def delete(uri, params = {}) send_request(uri, :delete, params) end
get(uri, params = {})
click to toggle source
Run GET request
Arguments:
uri: (String) param: (Hash)
# File lib/upwork/api/client.rb, line 94 def get(uri, params = {}) send_request(uri, :get, params) end
get_access_token(authz_code = nil)
click to toggle source
Finish auth process and get access token
Arguments:
authz_code: (String)
# File lib/upwork/api/client.rb, line 63 def get_access_token(authz_code = nil) if @config.grant_type == 'client_credentials' $LOG.i "getting access token" @access_token = @oauth2_client.client_credentials.get_token $LOG.i "got access token", @access_token else $LOG.i "getting access and refresh token pair" @access_token = @oauth2_client.auth_code.get_token(authz_code, :redirect_uri => @config.redirect_uri) $LOG.i "got access and refresh token pair", @access_token end refresh_config_from_access_token @access_token end
get_actual_config()
click to toggle source
Get actual client config
# File lib/upwork/api/client.rb, line 80 def get_actual_config @config end
post(uri, params = {})
click to toggle source
Run POST request
Arguments:
uri: (String) param: (Hash)
# File lib/upwork/api/client.rb, line 103 def post(uri, params = {}) send_request(uri, :post, params) end
put(uri, params = {})
click to toggle source
Run PUT request
Arguments:
uri: (String) param: (Hash)
# File lib/upwork/api/client.rb, line 112 def put(uri, params = {}) send_request(uri, :put, params) end
set_org_uid_header(tenant_id)
click to toggle source
Configure X-Upwork-API-TenantId header
# File lib/upwork/api/client.rb, line 85 def set_org_uid_header(tenant_id) @tenant_id = tenant_id end