Class: OpenFecApi::Client
- Inherits:
-
Object
- Object
- OpenFecApi::Client
- Includes:
- HTTParty
- Defined in:
- lib/open_fec_api/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#candidates(options = {}) ⇒ Object
Candidates Endpoint.
- #configured? ⇒ Boolean
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/open_fec_api/client.rb', line 9 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/open_fec_api/client.rb', line 5 def api_key @api_key end |
Instance Method Details
#candidates(options = {}) ⇒ Object
Candidates Endpoint
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/open_fec_api/client.rb', line 40 def candidates( = {}) query = {'api_key' => @api_key} request_params = ["sort", "sort_hide_null", "year", "office", "candidate_status", "party", "state", "cycle", "district", "incumbent_challenge", "name", "candidate_id", "page", "per_page"] = .select{|k,v| request_params.include?(k.to_s)} .each do |k,v| query.merge!({k.to_s => v}) end response = self.class.get("/candidates", query: query) return Response.new(response) end |
#configured? ⇒ Boolean
13 14 15 |
# File 'lib/open_fec_api/client.rb', line 13 def configured? !self.api_key.nil? end |