class Myparcel::Authentication

Creates authentication headers

Attributes

api_key[RW]

Public Class Methods

new(api_key = ENV['MYPARCEL_API_KEY']) click to toggle source
# File lib/myparcel/authentication.rb, line 6
def initialize(api_key = ENV['MYPARCEL_API_KEY'])
  @api_key = api_key
end

Public Instance Methods

auth_token() click to toggle source
# File lib/myparcel/authentication.rb, line 14
def auth_token
  Base64.urlsafe_encode64(api_key)
end
headers() click to toggle source
# File lib/myparcel/authentication.rb, line 10
def headers
  { 'Authorization' => "basic #{auth_token}" }
end
host() click to toggle source
# File lib/myparcel/authentication.rb, line 28
def host
  'https://api.myparcel.nl'
end
invalid?() click to toggle source
# File lib/myparcel/authentication.rb, line 24
def invalid?
  !valid?
end
valid?() click to toggle source

Could have used api_key.present? but it wasn’t avavailable in 1.9.3 yet for Object nor for String

# File lib/myparcel/authentication.rb, line 20
def valid?
  !api_key.nil? && api_key.size > 0
end