Sha256: 8df181f7ed0e95fd55b8348ec4245d155b375b659beafafb2ced95450d50ca89

Contents?: true

Size: 830 Bytes

Versions: 5

Compression:

Stored size: 830 Bytes

Contents

require 'uri'
require 'json'
require 'cgi'
require 'net/http'

module Pricesphere
  class Base
    def initialize(api_key = '', version = 'v1')
      raise Error.new("Missing API Key", 'You did not supply an API ey, please sign up for an account at https://www.pricesphere.com') if api_key == ''
      @api_key = api_key
      @version = version
    end

    private

    def get(endpoint, params)
      request_params = ""
      params.each do |name, value|
        request_params += "&#{CGI.escape(name.to_s)}=#{CGI.escape(value.to_s)}"
      end
      request_params.gsub!(/^&/, '')
      base_url = "#{Pricesphere.base_url}/api/#{@version}"
      request_url = "#{base_url}/#{endpoint}?#{request_params}&token=#{@api_key}"

      response = Net::HTTP.get(URI request_url)

      result = JSON.parse(response)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pricesphere-0.2.3 lib/pricesphere/base.rb
pricesphere-0.2.2 lib/pricesphere/base.rb
pricesphere-0.2.1 lib/pricesphere/base.rb
pricesphere-0.2.0 lib/pricesphere/base.rb
pricesphere-0.1.0 lib/pricesphere/base.rb