Sha256: 30e04a041427e5f60f9d59f0f3c88c1c18b8a33ebbc19b952b0a8fae3b4f5013

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module AbsorbApi
  class Base
    def initialize(attributes, &block)
      attributes.each do |k,v|
        instance_variable_set("@#{k.to_s.underscore}", v) unless v.nil?
      end
      yield self if block_given?
    end

    def self.authorize
      @authorize ||= Faraday.new(:url => AbsorbApi.configuration.url) do |faraday|
        faraday.request :url_encoded
        faraday.response :logger
        faraday.adapter :typhoeus
      end.post do |req|
        req.url 'Authenticate', { username: AbsorbApi.configuration.absorbuser, password: AbsorbApi.configuration.absorbpass, privateKey: AbsorbApi.configuration.absorbkey }
        req.headers['Content-Type'] = 'application/json'
        req.headers["accept"] = "json"
      end.body.delete('\\"')
    end

    def self.api
      @api ||= Faraday.new(:url => AbsorbApi.configuration.url, :parallel_manager => Typhoeus::Hydra.new(:max_concurrency => 200)) do |faraday|
        faraday.request :json
        faraday.response :json, :content_type => /\bjson$/
        faraday.adapter :typhoeus
        faraday.headers = {"Authorization" => authorize }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
absorb_api-0.1.2 lib/absorb_api/base.rb
absorb_api-0.1.1 lib/absorb_api/base.rb
absorb_api-0.1.0 lib/absorb_api/base.rb