Sha256: 8b5ad7e35b12fffa7361e82031d36d987c0a90bd8a35f755e51d010e08a4beff

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Dnsimple
  class Client
    module Users

      # Fetches the information about the authenticated user.
      #
      # @return [Struct::User] The authenticated user.
      # @raise  [RequestError] When the request fails.
      def user
        response = client.get("v1/user")

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

      # 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.
      #
      # @see http://developer.dnsimple.com/authentication/#twofa
      #
      # @example Request an Exchange Token
      #   Dnsimple::User.two_factor_exchange_token('0000000')
      #   # => "cda038832591e34f5df642ce2b61dc78"
      #
      # @param  [String] otp_token the two-factor one time (OTP) token.
      #
      # @return [String] The two-factor API exchange token.
      # @raise  [AuthenticationFailed] if the provided OTP token is invalid.
      def exchange_token(otp_token)
        response = client.get("v1/user", headers: { Client::HEADER_2FA_STRICT => "1", Client::HEADER_OTP_TOKEN => otp_token })
        response.headers[Client::HEADER_EXCHANGE_TOKEN]
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dnsimple-2.0.0 lib/dnsimple/client/users.rb
dnsimple-2.0.0.alpha5 lib/dnsimple/client/users.rb
dnsimple-2.0.0.alpha4 lib/dnsimple/client/users.rb