Class: DnB::Direct::Two

Inherits:
Object
  • Object
show all
Defined in:
lib/dnb/direct/two.rb

Constant Summary collapse

BASE_URL =
'https://direct.dnb.com'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_base_urlObject

Returns the value of attribute api_base_url.



8
9
10
# File 'lib/dnb/direct/two.rb', line 8

def api_base_url
  @api_base_url
end

.connObject

Returns the value of attribute conn.



8
9
10
# File 'lib/dnb/direct/two.rb', line 8

def conn
  @conn
end

.passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/dnb/direct/two.rb', line 8

def password
  @password
end

.tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/dnb/direct/two.rb', line 8

def token
  @token
end

.usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/dnb/direct/two.rb', line 8

def username
  @username
end

Class Method Details

.api_tokenObject

Fetches the token from the authorization service.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
# File 'lib/dnb/direct/two.rb', line 11

def api_token
    raise ArgumentError, 'username is missing' if username.blank?
    raise ArgumentError, 'password is missing' if password.blank?
    response = connection.post do |req|
        req.url '/Authentication/V2.0'
        req.headers['x-dnb-user'] = username
        req.headers['x-dnb-pwd'] = password
    end
    response.headers['Authorization']
end