Class: ElectionBuddy::Client
- Inherits:
-
Object
- Object
- ElectionBuddy::Client
- Defined in:
- lib/election_buddy/client.rb
Overview
HTTP client for the ElectionBuddy API
Constant Summary collapse
- BASE_URL =
"https://secure.electionbuddy.com/api/v2"
Instance Method Summary collapse
- #connection ⇒ Object private
-
#initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
-
#voter_list ⇒ VoterListResource
Returns the voter list resource for handling voter-related operations.
Constructor Details
#initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 |
# File 'lib/election_buddy/client.rb', line 16 def initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key || ElectionBuddy.configuration.api_key @adapter = adapter @stubs = stubs end |
Instance Method Details
#connection ⇒ Object (private)
31 32 33 34 35 36 37 38 |
# File 'lib/election_buddy/client.rb', line 31 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.headers["authorization"] = @api_key conn.request :json conn.response :json, content_type: /\bjson$/ conn.adapter @adapter, @stubs end end |
#voter_list ⇒ VoterListResource
Returns the voter list resource for handling voter-related operations
25 26 27 |
# File 'lib/election_buddy/client.rb', line 25 def voter_list VoterListResource.new(connection) end |