Module: Dnsimple::Client::Users

Included in:
UsersService
Defined in:
lib/dnsimple/client/users.rb

Instance Method Summary collapse

Instance Method Details

#exchange_token(otp_token, options = {}) ⇒ String

Requests a new two-factor authentication exchange token.

The exchange-token is required to validate API requests using HTTP Basic Authentication when the account has two-factor authentication enabled.

Examples:

Request an Exchange Token

Dnsimple::User.two_factor_exchange_token('0000000')
# => "cda038832591e34f5df642ce2b61dc78"

Parameters:

  • otp_token (String)

    the two-factor one time (OTP) token.

Returns:

  • (String)

    The two-factor API exchange token.

Raises:

See Also:



31
32
33
34
35
# File 'lib/dnsimple/client/users.rb', line 31

def exchange_token(otp_token, options = {})
  options  = Extra.deep_merge(options, headers: { Client::HEADER_2FA_STRICT => "1", Client::HEADER_OTP_TOKEN => otp_token })
  response = client.get(Client.versioned("/user"), options)
  response.headers[Client::HEADER_EXCHANGE_TOKEN]
end

#user(options = {}) ⇒ Struct::User

Fetches the information about the authenticated user.

Returns:

Raises:



10
11
12
13
14
# File 'lib/dnsimple/client/users.rb', line 10

def user(options = {})
  response = client.get(Client.versioned("/user"), options)

  Struct::User.new(response["user"])
end