Module: GmanClient::Utility
- Included in:
- Gman::Client
- Defined in:
- lib/gman_client/utility.rb
Instance Method Summary collapse
- #attempt(retry_count) ⇒ Object
- #convert_payload(response) ⇒ Object
- #get(resource, params) ⇒ Object
- #request ⇒ Object
- #token ⇒ Object
Instance Method Details
#attempt(retry_count) ⇒ Object
38 39 40 |
# File 'lib/gman_client/utility.rb', line 38 def attempt(retry_count) with_retries(max_tries: retry_count) { yield } end |
#convert_payload(response) ⇒ Object
32 33 34 35 36 |
# File 'lib/gman_client/utility.rb', line 32 def convert_payload(response) response.map do |hash_request| Hashie.symbolize_keys!(hash_request.to_h) end end |
#get(resource, params) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/gman_client/utility.rb', line 5 def get(resource, params) request .api .v1 .send(resource) .get(params: params) end |
#request ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gman_client/utility.rb', line 13 def request Blanket.wrap( @url, extension: :json, headers: { 'Authorization' => "Bearer #{token}" } ) end |
#token ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gman_client/utility.rb', line 21 def token return @token if @token response = RestClient.post(@token_url, grant_type: 'client_credentials', client_id: @client_id, client_secret: @client_secret) @token = JSON.parse(response)['access_token'] end |