Class: ThreeSixty::Client
- Inherits:
-
Object
- Object
- ThreeSixty::Client
- Defined in:
- lib/three-sixty/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#session_token ⇒ Object
readonly
Returns the value of attribute session_token.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #authenticate!(username, password) ⇒ Object
-
#initialize(api_key, api_secret, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #request(resource_url, params = {}) ⇒ Object
Constructor Details
#initialize(api_key, api_secret, opts = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/three-sixty/client.rb', line 14 def initialize(api_key, api_secret, opts = {}) opts = .update(opts) @api_key = api_key @api_secret = api_secret @endpoint = opts[:endpoint] @version = opts[:version] @format = opts[:format] @logger = opts[:logger] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
12 13 14 |
# File 'lib/three-sixty/client.rb', line 12 def access_token @access_token end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/three-sixty/client.rb', line 11 def api_key @api_key end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
11 12 13 |
# File 'lib/three-sixty/client.rb', line 11 def endpoint @endpoint end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
11 12 13 |
# File 'lib/three-sixty/client.rb', line 11 def logger @logger end |
#session_token ⇒ Object (readonly)
Returns the value of attribute session_token.
12 13 14 |
# File 'lib/three-sixty/client.rb', line 12 def session_token @session_token end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
11 12 13 |
# File 'lib/three-sixty/client.rb', line 11 def version @version end |
Instance Method Details
#authenticate!(username, password) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/three-sixty/client.rb', line 25 def authenticate!(username, password) account = ThreeSixty::Core::Account.new(self) tokens = account.client_login(username, generate_passwd(password)) @access_token = tokens['accessToken'] @session_token = tokens['sessionToken'] end |
#request(resource_url, params = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/three-sixty/client.rb', line 32 def request(resource_url, params = {}) params[:format] = @format uri = URI(generate_url(resource_url, params)) @logger.debug "Resquest url #{uri.to_s}" req = Net::HTTP::Post.new(uri, headers = generate_headers) retry_counter = 0 begin @logger.debug "Sending headers #{headers}" res = Net::HTTP.start(uri.host) do |http| http.request(req) end process_response(res) rescue Net::ReadTimeout => e # Some requests can take a while, so just retry a few times raise e unless retry_counter < 5 retry_counter += 1 retry end end |