Sha256: 5d80cb401eedebafdc474134d4d2635a46a23e2afa798c490ea72571a5f89427

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

require 'rest-client'
require 'oj'

module SiebelDonations
  class Base

    def initialize(json)
      json.each do |key, value|
        instance_variable_set("@#{key.underscore}", value)
      end
    end

    def self.get(path, params)
      raise 'You need to configure SiebelDonations with your oauth_token.' unless SiebelDonations.oauth_token
      url = SiebelDonations.base_url + path
      RestClient.get(url, {params: params, timeout: -1, authorization: "Bearer #{SiebelDonations.oauth_token}"}) { |response, request, result, &block|
        case response.code
        when 200
          Oj.load(response)
        else
          puts response.inspect
          puts request.inspect
          raise result.inspect
        end
      }
    end

    def self.find(params)
      get(path, params).collect { |json| new(json) }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
siebel_donations-1.0.0 lib/siebel_donations/base.rb