Class: Myparcel::Authentication
- Inherits:
-
Object
- Object
- Myparcel::Authentication
- Defined in:
- lib/myparcel/authentication.rb
Overview
Creates authentication headers
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #auth_token ⇒ Object
- #headers ⇒ Object
- #host ⇒ Object
-
#initialize(api_key = ENV['MYPARCEL_API_KEY']) ⇒ Authentication
constructor
A new instance of Authentication.
- #invalid? ⇒ Boolean
-
#valid? ⇒ Boolean
Could have used api_key.present? but it wasn’t avavailable in 1.9.3 yet for Object nor for String.
Constructor Details
#initialize(api_key = ENV['MYPARCEL_API_KEY']) ⇒ Authentication
Returns a new instance of Authentication.
6 7 8 |
# File 'lib/myparcel/authentication.rb', line 6 def initialize(api_key = ENV['MYPARCEL_API_KEY']) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/myparcel/authentication.rb', line 4 def api_key @api_key end |
Instance Method Details
#auth_token ⇒ Object
14 15 16 |
# File 'lib/myparcel/authentication.rb', line 14 def auth_token Base64.urlsafe_encode64(api_key) end |
#headers ⇒ Object
10 11 12 |
# File 'lib/myparcel/authentication.rb', line 10 def headers { 'Authorization' => "basic #{auth_token}" } end |
#host ⇒ Object
28 29 30 |
# File 'lib/myparcel/authentication.rb', line 28 def host 'https://api.myparcel.nl' end |
#invalid? ⇒ Boolean
24 25 26 |
# File 'lib/myparcel/authentication.rb', line 24 def invalid? !valid? end |
#valid? ⇒ Boolean
Could have used api_key.present? but it wasn’t avavailable in 1.9.3 yet for Object nor for String
20 21 22 |
# File 'lib/myparcel/authentication.rb', line 20 def valid? !api_key.nil? && api_key.size > 0 end |