Sha256: 96f01bbda1d722c5b5fd2aa88e54fc9d8e9ef3f83081d5ae7e8c3957ff941c09

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'httparty'
require 'json'

module CheckIssuing
  class Request
    include HTTParty

    def get(path, options={})
      set_auth(options)
      @response = self.class.get(CheckIssuing.endpoint + path, options)
    end

    def post(path, options={})
      set_auth(options)
      @response = self.class.post(CheckIssuing.endpoint + path, options)
    end

    def put(path, options={})
      set_auth(options)
      @response = self.class.put(CheckIssuing.endpoint + path, options)
    end

    def delete(path, options={})
      set_auth(options)
      @response = self.class.delete(CheckIssuing.endpoint + path, options)
    end

    def response
      @response
    end

    def parsed_response
      self.response.parsed_response if self.response.present?
    end

    private

    def set_auth(options)
      options[:body] ||= {}
      options[:body][:akey] ||= CheckIssuing.api_key
      options[:body][:client_id] ||= CheckIssuing.client_id


      options[:http_proxyaddr] = CheckIssuing.proxy_host if CheckIssuing.proxy_host.present?
      options[:http_proxyport] = CheckIssuing.proxy_port if CheckIssuing.proxy_port.present?
      options[:http_proxyuser] = CheckIssuing.proxy_user if CheckIssuing.proxy_user.present?
      options[:http_proxypass] = CheckIssuing.proxy_password if CheckIssuing.proxy_user.present?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
check_issuing-1.0.3 lib/check_issuing/request.rb
check_issuing-1.0.2 lib/check_issuing/request.rb