Sha256: 04faf3325b04de162cccc91394d8a78cbdfc39d2fb8fb0ed43cb9ee4eaf985c1

Contents?: true

Size: 1.07 KB

Versions: 20

Compression:

Stored size: 1.07 KB

Contents

module Centaman
  #:nodoc:
  class Wrapper
    include HTTParty

    if ENV['FIXIE_URL']
      FIXIE = URI.parse(ENV['FIXIE_URL'])
      http_proxy FIXIE.host, FIXIE.port, FIXIE.user, FIXIE.password
    end

    attr_reader :api_username, :api_password, :api_token

    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

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

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

    def options
      [] # overwritten by children
    end

    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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
centaman-5.0.3 lib/centaman/wrapper.rb
centaman-5.0.2 lib/centaman/wrapper.rb
centaman-5.0.1 lib/centaman/wrapper.rb
centaman-5.0.0 lib/centaman/wrapper.rb
centaman-4.0.5 lib/centaman/wrapper.rb
centaman-4.0.4 lib/centaman/wrapper.rb
centaman-4.0.3 lib/centaman/wrapper.rb
centaman-4.0.2 lib/centaman/wrapper.rb
centaman-4.0.1 lib/centaman/wrapper.rb
centaman-3.1.2 lib/centaman/wrapper.rb
centaman-3.1.1 lib/centaman/wrapper.rb
centaman-3.1.0 lib/centaman/wrapper.rb
centaman-3.0.0 lib/centaman/wrapper.rb
centaman-2.1.0 lib/centaman/wrapper.rb
centaman-2.0.0 lib/centaman/wrapper.rb
centaman-1.0.0 lib/centaman/wrapper.rb
centaman-0.2.3 lib/centaman/wrapper.rb
centaman-0.2.2 lib/centaman/wrapper.rb
centaman-0.2.1 lib/centaman/wrapper.rb
centaman-0.2.0 lib/centaman/wrapper.rb