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



36
37
38
# File 'lib/gman_client/utility.rb', line 36

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

#convert_payload(response) ⇒ Object



30
31
32
33
34
# File 'lib/gman_client/utility.rb', line 30

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

#get(resource, params) ⇒ Object



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

def get(resource, params)
  request
    .api
    .v1
    .send(resource)
    .get(params: params)
end

#requestObject



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

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

#tokenObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/gman_client/utility.rb', line 19

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