Class: Centaman::Wrapper

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/centaman/wrapper.rb

Overview

:nodoc:

Direct Known Subclasses

Service

Constant Summary collapse

FIXIE =
URI.parse(ENV['FIXIE_URL'])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Wrapper

Returns a new instance of Wrapper.



15
16
17
18
19
20
21
# File 'lib/centaman/wrapper.rb', line 15

def initialize(args = {})
  @api_username = ENV['CENTAMAN_API_USERNAME']
  @api_password = ENV['CENTAMAN_API_PASSWORD']      
  @api_token = ENV.fetch('CENTAMAN_API_TOKEN', generate_token)
  self.class.base_uri ENV['CENTAMAN_API_URL']
  after_init(args)
end

Instance Attribute Details

#api_passwordObject (readonly)

Returns the value of attribute api_password.



13
14
15
# File 'lib/centaman/wrapper.rb', line 13

def api_password
  @api_password
end

#api_tokenObject (readonly)

Returns the value of attribute api_token.



13
14
15
# File 'lib/centaman/wrapper.rb', line 13

def api_token
  @api_token
end

#api_usernameObject (readonly)

Returns the value of attribute api_username.



13
14
15
# File 'lib/centaman/wrapper.rb', line 13

def api_username
  @api_username
end

Instance Method Details

#after_init(args = {}) ⇒ Object



44
45
46
# File 'lib/centaman/wrapper.rb', line 44

def after_init(args = {})
  # hook method for subclasses
end

#generate_tokenObject



27
28
29
# File 'lib/centaman/wrapper.rb', line 27

def generate_token
  Base64.encode64("#{api_username}:#{api_password}")
end

#headersObject



23
24
25
# File 'lib/centaman/wrapper.rb', line 23

def headers
  { 'authorization' => "Basic #{api_token}", 'Content-Type' => 'application/json' }
end

#optionsObject



31
32
33
# File 'lib/centaman/wrapper.rb', line 31

def options
  [] # overwritten by children
end

#options_hashObject



35
36
37
38
39
40
41
42
# File 'lib/centaman/wrapper.rb', line 35

def options_hash
  hash = {}
  options.each do |option_hash|
    next unless option_hash[:value].present?
    hash[option_hash[:key]] = option_hash[:value]
  end
  hash
end