Class: Centaman::Wrapper
- Inherits:
-
Object
- Object
- Centaman::Wrapper
- Includes:
- HTTParty
- Defined in:
- lib/centaman/wrapper.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- FIXIE =
URI.parse(ENV['FIXIE_URL'])
Instance Attribute Summary collapse
-
#api_password ⇒ Object
readonly
Returns the value of attribute api_password.
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#api_username ⇒ Object
readonly
Returns the value of attribute api_username.
Instance Method Summary collapse
- #after_init(args = {}) ⇒ Object
- #generate_token ⇒ Object
- #headers ⇒ Object
-
#initialize(args = {}) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #options ⇒ Object
- #options_hash ⇒ Object
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_password ⇒ Object (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_token ⇒ Object (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_username ⇒ Object (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_token ⇒ Object
27 28 29 |
# File 'lib/centaman/wrapper.rb', line 27 def generate_token Base64.encode64("#{api_username}:#{api_password}") end |
#headers ⇒ Object
23 24 25 |
# File 'lib/centaman/wrapper.rb', line 23 def headers { 'authorization' => "Basic #{api_token}", 'Content-Type' => 'application/json' } end |
#options ⇒ Object
31 32 33 |
# File 'lib/centaman/wrapper.rb', line 31 def [] # overwritten by children end |
#options_hash ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/centaman/wrapper.rb', line 35 def hash = {} .each do |option_hash| next unless option_hash[:value].present? hash[option_hash[:key]] = option_hash[:value] end hash end |