Sha256: 90d184912447f6d517af844bb740101d5edbad59beb26abaf601a8e10c452d2c

Contents?: true

Size: 872 Bytes

Versions: 4

Compression:

Stored size: 872 Bytes

Contents

module Targetdata
  module Api
    module Auth
      def token
        response = HTTP.headers(auth_headers).post(Targetdata::BASE_URL + '/token', form: auth_body)
        parsed = JSON.parse(response.body.to_s)
        parsed["access_token"]
      end

      private
        def auth_body
          {
            grant_type: Targetdata.configuration.grant_type,
            client_id: Targetdata.configuration.client_id,
            client_secret: Targetdata.configuration.client_secret,
            username: Targetdata.configuration.username,
            password: Targetdata.configuration.password,
            empresa: Targetdata.configuration.company_id
          }
        end
    
        def auth_headers
          {
            'Content-Type':'application/x-www-form-urlencoded',
            'Accept': 'application/json'
          }
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
targetdata-0.3.1 lib/targetdata/api/auth.rb
targetdata-0.3.0 lib/targetdata/api/auth.rb
targetdata-0.2.1 lib/targetdata/api/auth.rb
targetdata-0.2.0 lib/targetdata/api/auth.rb