Class: JustGiving::Client
- Inherits:
-
Object
- Object
- JustGiving::Client
- Defined in:
- lib/justgiving/client.rb
Direct Known Subclasses
Account, Charity, Country, Currency, Donation, Event, Fundraising, Project, Search, Team
Instance Method Summary collapse
-
#initialize(token, environment = nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(token, environment = nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/justgiving/client.rb', line 9 def initialize(token, environment=nil) if environment.nil? || environment == :production environment = :production @base_url = "https://api.justgiving.com/#{@token}/v1/" elsif environment == :staging @base_url = "https://api-staging.justgiving.com/#{@token}/v1/" elsif environment == :sandbox @base_url = "https://api-sandbox.justgiving.com/#{@token}/v1/" else raise Error::InvalidEnvironment end @token = token @environment = environment @connection_defaults = { url: @base_url, headers: { 'User-Agent' => 'Ruby REST client', 'Content-Type' => 'application/json' } } @connection = Faraday.new(@connection_defaults) do |connection| connection.request :json connection.response :json, :content_type => /\bjson$/ connection.use Error::RaiseError connection.use Logger connection.adapter Faraday.default_adapter end end |