Sha256: 4a78fb91573ca21fe5a692401a59dd06b7beacae73b7f7afd3f8ee982ba62743

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

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

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

    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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gman_client-0.4.1 lib/gman_client/utility.rb
gman_client-0.4.0 lib/gman_client/utility.rb