Class: FulfilApi::AccessToken
- Inherits:
-
Object
- Object
- FulfilApi::AccessToken
- 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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, type: :personal) ⇒ AccessToken
constructor
A new instance of AccessToken.
-
#to_http_header ⇒ Hash
Builds the HTTP headers for the access token based on the #type.
Constructor Details
#initialize(value, type: :personal) ⇒ AccessToken
Returns a new instance of AccessToken.
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
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/fulfil_api/access_token.rb', line 7 def type @type end |
#value ⇒ Object (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_header ⇒ Hash
Builds the HTTP headers for the access token based on the #type.
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 |