Class: OpenFecApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/open_fec_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (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

Examples:

OpenFecApi::Client.new(:api_key => API_KEY).candidates(:page => 1, :per_page => 100)

Parameters:

  • options (Hash) (defaults to: {})

    option options Array :sort Provide a field to sort by. Use - for descending order. option options Boolean :sort_hide_null Hide null values on sorted column(s). option options String :year See records pertaining to a particular year. option options Array :office Governmental office candidate runs for: House (H), Senate (S) or President (P). option options Array :candidate_status One letter code explaining if the candidate is: present ©, future (F), not yet (N), or prior (P). option options Array :party Three letter code for the party under which a candidate ran for office. option options Array :state U.S. State candidate or territory where a candidate runs for office. option options Array :cycle Two-year election cycle in which a candidate runs for office. Calculated from FEC form 2. option options Array :district Two digit district number. option options Array :incumbent_challenge One letter code explaining if the candidate is an incumbent (I), a challenger ©, or if the seat is open (O). option options String :q Text to search all fields for. option options String :name Candidate’s name (full or partial). option options Array :candidate_id A unique identifier assigned to each candidate registered with the FEC. If a person runs for several offices, that person will have separate candidate IDs for each office. option options Integer :page For paginating through results, starting at page 1. option options Integer :per_page The number of results returned per page. Defaults to 20.



40
41
42
43
44
45
46
47
48
49
# File 'lib/open_fec_api/client.rb', line 40

def candidates(options = {})
  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"]
  request_options = options.select{|k,v| request_params.include?(k.to_s)}
  request_options.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

Returns:

  • (Boolean)


13
14
15
# File 'lib/open_fec_api/client.rb', line 13

def configured?
  !self.api_key.nil?
end