Class: Matroid::MatroidClient
- Inherits:
-
Object
- Object
- Matroid::MatroidClient
- Defined in:
- lib/matroid.rb
Instance Method Summary collapse
- #account_info ⇒ Object
-
#initialize(options) ⇒ MatroidClient
constructor
A new instance of MatroidClient.
- #retrieve_token ⇒ Object
Constructor Details
#initialize(options) ⇒ MatroidClient
Returns a new instance of MatroidClient.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/matroid.rb', line 7 def initialize() @base_url = [:base_url] @client_id = [:client_id] @client_secret = [:client_secret] @request = HTTParty @endpoints = { token: { method: :post, uri: "#{@base_url}/oauth/token" }, account_info: { method: :get, uri: "#{@base_url}/account" } } end |
Instance Method Details
#account_info ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/matroid.rb', line 33 def account_info endpoint = @endpoints[:account_info] headers = { "Authorization" => } opts = { headers: headers } response = @request.send(endpoint[:method], endpoint[:uri], opts) response.parsed_response end |
#retrieve_token ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/matroid.rb', line 19 def retrieve_token endpoint = @endpoints[:token] opts = { body: { client_id: @client_id, client_secret: @client_secret, grant_type: 'client_credentials' } } response = @request.send(endpoint[:method], endpoint[:uri], opts) = "#{response['token_type']} #{response['access_token']}" response.parsed_response end |