Class: FulfilApi::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil_api/access_token.rb

Overview

The Fulfil::AccessToken provides information about the type of access token

that is provided to access the Fulfil API.

Defined Under Namespace

Classes: TypeInvalid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, type: :personal) ⇒ AccessToken

Returns a new instance of AccessToken.

Parameters:

  • value (String)

    The raw access token contents

  • type (Symbol, String) (defaults to: :personal)

    The access token type (personal or oauth)



13
14
15
16
# File 'lib/fulfil_api/access_token.rb', line 13

def initialize(value, type: :personal)
  @type = type.to_sym
  @value = value
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/fulfil_api/access_token.rb', line 7

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/fulfil_api/access_token.rb', line 7

def value
  @value
end

Instance Method Details

#to_http_headerHash

Builds the HTTP headers for the access token based on the #type.

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
# File 'lib/fulfil_api/access_token.rb', line 21

def to_http_header
  case type
  when :personal
    { "X-API-KEY" => value }
  when :oauth
    { "Authorization" => "Bearer #{value}" }
  else
    raise TypeInvalid, "#{type} is not a valid access token type. Use :personal or :oauth instead."
  end
end