Module: GmanClient::Utility

Included in:
Gman::Client
Defined in:
lib/gman_client/utility.rb

Instance Method Summary collapse

Instance Method Details

#attempt(retry_count) ⇒ Object



28
29
30
# File 'lib/gman_client/utility.rb', line 28

def attempt(retry_count)
  with_retries(max_tries: retry_count) { yield }
end

#convert_payload(response) ⇒ Object



22
23
24
25
26
# File 'lib/gman_client/utility.rb', line 22

def convert_payload(response)
  response.map do |hash_request|
    Hashie.symbolize_keys!(hash_request.to_h)
  end
end

#requestObject



3
4
5
6
7
8
9
# File 'lib/gman_client/utility.rb', line 3

def request
  Blanket.wrap(
    @url,
    extension: :json,
    headers: { 'Authorization' => "Bearer #{token}" }
  )
end

#tokenObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/gman_client/utility.rb', line 11

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