open_fec_api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 124251aad3027ab11a34736940eadde4bc61ed1a
4
- data.tar.gz: efd3d0bbad721efb73c40f33862ee35b964c03bd
3
+ metadata.gz: f6b7e9d0218b14ebc38cd51976b5449d58e06c3a
4
+ data.tar.gz: f428c2254ab332bf979d988637be4622c0a12757
5
5
  SHA512:
6
- metadata.gz: b30b9116a9d873685d781228d73c292d43014b397063061c210e4a0f6581aaeb22d6956571348e3eb95d09553f89b17a3859960503583ccde2fe53a1805764d5
7
- data.tar.gz: 18e3e371fe7c2fb84039196cb6bda871cb22398f84c1f104d19a7771a0f37954fe8beed943405656eb484f84a99d47e3d514c23146d73ab5f682fd16a48655cb
6
+ metadata.gz: d8c64d72556ec3c475055dd403dc8f0a28f404b56a2ea5161fb60ae8dee9de152abd9321e5bc1348eefe7c41d304c300d1d7cb3fa6023c87e0c7b008dbed28f6
7
+ data.tar.gz: 89306135e2e84f82237c807bfdb8e7997e89cb2deee4031f8e25416b4b0d0795b7aefd3166359bb5d4b7900065e4a353bbe303a5da40b1fd7679c4926a45629b
data/README.md CHANGED
@@ -18,8 +18,15 @@ Obtain an [API key](https://api.data.gov/signup/).
18
18
 
19
19
  ```` rb
20
20
  client = OpenFecApi::Client.new("api_key_123")
21
+
21
22
  candidates_response = client.candidates
23
+
24
+ candidate_response = client.candidate("P00003392")
25
+
22
26
  committees_response = client.committees
27
+
28
+ committees_response = client.committee("C00571372")
29
+
23
30
  ````
24
31
  ### Configuration Options
25
32
 
@@ -45,7 +52,7 @@ response = client.candidates(options)
45
52
 
46
53
  ## Contributing
47
54
 
48
- Help wrap all the [endpoints](ENDPOINTS.md)!
55
+ Help establish and maintain full API endpoint coverage.
49
56
 
50
57
  Browse existing issues or create a new issue to communicate bugs, desired features, etc.
51
58
 
data/lib/open_fec_api.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "open_fec_api/version"
2
2
  require "open_fec_api/client"
3
3
  require "open_fec_api/response"
4
+ require "open_fec_api/responses/candidate_response"
4
5
  require "open_fec_api/responses/candidates_response"
6
+ require "open_fec_api/responses/committee_response"
5
7
  require "open_fec_api/responses/committees_response"
6
8
 
7
9
  module OpenFecApi
@@ -43,7 +43,7 @@ module OpenFecApi
43
43
  # option options Integer :per_page The number of results returned per page. Defaults to 20.
44
44
  #
45
45
  def get_response(endpoint, options = {})
46
- endpoint_name = endpoint.gsub("/","")
46
+ endpoint_name = (endpoint.split("/") - [""]).first
47
47
  request_options = options.select{|k,v| request_params.include?(k.to_s)}
48
48
 
49
49
  # Parse/compile query params.
@@ -62,25 +62,104 @@ module OpenFecApi
62
62
  response_class_name = endpoint_name.capitalize.concat("Response")
63
63
  return OpenFecApi.const_get(response_class_name).new(response) # response_class_name.constantize.new(response)
64
64
  end
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
65
85
 
66
86
  # Candidates Endpoint
67
87
  #
68
88
  # https://api.open.fec.gov/developers#!/candidate/get_candidates
69
89
  #
70
90
  # @example
71
- # OpenFecApi::Client.new(:api_key => API_KEY).candidates(:page => 1, :per_page => 100)
91
+ # OpenFecApi::Client.new(:api_key => API_KEY).candidates({:page => 1, :per_page => 100})
72
92
  def candidates(options = {})
73
93
  get_response("/candidates", options)
74
94
  end
75
95
 
96
+ # Candidate Endpoint
97
+ #
98
+ # https://api.open.fec.gov/developers/#!/candidate/get_candidate_candidate_id
99
+ #
100
+ # @param [String] candidate_id
101
+ #
102
+ # @example
103
+ # OpenFecApi::Client.new(:api_key => API_KEY).candidate("P00003392", {:page => 1, :per_page => 100})
104
+ def candidate(candidate_id, options = {})
105
+ get_response("/candidate/#{candidate_id}", options)
106
+ end
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
76
122
  # Committees Endpoint
77
123
  #
78
124
  # https://api.open.fec.gov/developers#!/committee/get_committees
79
125
  #
80
126
  # @example
81
- # OpenFecApi::Client.new(:api_key => API_KEY).committees(:page => 1, :per_page => 100)
127
+ # OpenFecApi::Client.new(:api_key => API_KEY).committees({:page => 1, :per_page => 100})
82
128
  def committees(options = {})
83
129
  get_response("/committees", options)
84
130
  end
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ # Committee Endpoint
144
+ #
145
+ # https://api.open.fec.gov/developers#!/committee/get_committees
146
+ #
147
+ # @param [String] committee_id
148
+ #
149
+ # @example
150
+ # OpenFecApi::Client.new(:api_key => API_KEY).committee("C00571372", {:page => 1, :per_page => 100})
151
+ def committee(committee_id, options = {})
152
+ get_response("/committee/#{committee_id}", options)
153
+ end
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
85
164
  end
86
165
  end
@@ -0,0 +1,4 @@
1
+ module OpenFecApi
2
+ class CandidateResponse < Response
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module OpenFecApi
2
+ class CommitteeResponse < Response
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenFecApi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,48 @@
1
+ {
2
+ "pagination": {
3
+ "pages": 1,
4
+ "page": 1,
5
+ "per_page": 20,
6
+ "count": 1
7
+ },
8
+ "api_version": "1.0",
9
+ "results": [
10
+ {
11
+ "incumbent_challenge_full": "Open seat",
12
+ "election_districts": [
13
+ "00",
14
+ "00"
15
+ ],
16
+ "address_zip": "101855256",
17
+ "name": "CLINTON, HILLARY RODHAM",
18
+ "address_state": "NY",
19
+ "candidate_id": "P00003392",
20
+ "district_number": 0,
21
+ "district": "00",
22
+ "office_full": "President",
23
+ "office": "P",
24
+ "load_date": "2015-11-02",
25
+ "address_street_2": null,
26
+ "active_through": 2016,
27
+ "address_city": "NEW YORK",
28
+ "party_full": "Democratic Party",
29
+ "candidate_inactive": false,
30
+ "address_street_1": "P.O. BOX 5256",
31
+ "election_years": [
32
+ 2008,
33
+ 2016
34
+ ],
35
+ "party": "DEM",
36
+ "cycles": [
37
+ 2008,
38
+ 2010,
39
+ 2012,
40
+ 2014,
41
+ 2016
42
+ ],
43
+ "state": "US",
44
+ "incumbent_challenge": "O",
45
+ "candidate_status": "C"
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,23 @@
1
+ [{"incumbent_challenge_full"=>"Open seat",
2
+ "election_districts"=>["00", "00"],
3
+ "address_zip"=>"101855256",
4
+ "name"=>"CLINTON, HILLARY RODHAM",
5
+ "address_state"=>"NY",
6
+ "candidate_id"=>"P00003392",
7
+ "district_number"=>0,
8
+ "district"=>"00",
9
+ "office_full"=>"President",
10
+ "office"=>"P",
11
+ "load_date"=>"2015-11-02",
12
+ "address_street_2"=>nil,
13
+ "active_through"=>2016,
14
+ "address_city"=>"NEW YORK",
15
+ "party_full"=>"Democratic Party",
16
+ "candidate_inactive"=>false,
17
+ "address_street_1"=>"P.O. BOX 5256",
18
+ "election_years"=>[2008, 2016],
19
+ "party"=>"DEM",
20
+ "cycles"=>[2008, 2010, 2012, 2014, 2016],
21
+ "state"=>"US",
22
+ "incumbent_challenge"=>"O",
23
+ "candidate_status"=>"C"}]
@@ -0,0 +1,79 @@
1
+ {
2
+ "pagination": {
3
+ "pages": 1,
4
+ "page": 1,
5
+ "per_page": 20,
6
+ "count": 2
7
+ },
8
+ "api_version": "1.0",
9
+ "results": [
10
+ {
11
+ "incumbent_challenge_full": "Open seat",
12
+ "election_districts": [
13
+ "00",
14
+ "00"
15
+ ],
16
+ "office_full": "President",
17
+ "party_full": "Democratic Party",
18
+ "name": "CLINTON, HILLARY RODHAM",
19
+ "office": "P",
20
+ "election_years": [
21
+ 2008,
22
+ 2016
23
+ ],
24
+ "party": "DEM",
25
+ "active_through": 2016,
26
+ "cycles": [
27
+ 2008,
28
+ 2010,
29
+ 2012,
30
+ 2014,
31
+ 2016
32
+ ],
33
+ "district_number": 0,
34
+ "district": "00",
35
+ "state": "US",
36
+ "incumbent_challenge": "O",
37
+ "candidate_status": "C",
38
+ "load_date": "2015-11-02",
39
+ "candidate_id": "P00003392"
40
+ },
41
+ {
42
+ "incumbent_challenge_full": "Challenger",
43
+ "election_districts": [
44
+ "00",
45
+ "00",
46
+ "00"
47
+ ],
48
+ "office_full": "Senate",
49
+ "party_full": "Democratic Party",
50
+ "name": "CLINTON, HILLARY RODHAM",
51
+ "office": "S",
52
+ "election_years": [
53
+ 2000,
54
+ 2006,
55
+ 2012
56
+ ],
57
+ "party": "DEM",
58
+ "active_through": 2012,
59
+ "cycles": [
60
+ 2000,
61
+ 2002,
62
+ 2004,
63
+ 2006,
64
+ 2008,
65
+ 2010,
66
+ 2012,
67
+ 2014,
68
+ 2016
69
+ ],
70
+ "district_number": 0,
71
+ "district": "00",
72
+ "state": "NY",
73
+ "incumbent_challenge": "C",
74
+ "candidate_status": "P",
75
+ "load_date": "2013-04-26",
76
+ "candidate_id": "S0NY00188"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "pagination": {
3
+ "pages": 1,
4
+ "page": 1,
5
+ "per_page": 20,
6
+ "count": 1
7
+ },
8
+ "api_version": "1.0",
9
+ "results": [
10
+ {
11
+ "state_full": "California ",
12
+ "expire_date": null,
13
+ "name": "10 ^ 9+",
14
+ "custodian_city": null,
15
+ "custodian_state": null,
16
+ "form_type": "F1Z",
17
+ "organization_type": null,
18
+ "treasurer_name_title": null,
19
+ "zip": "94085",
20
+ "treasurer_name_suffix": null,
21
+ "custodian_name_suffix": null,
22
+ "designation_full": "Unauthorized",
23
+ "treasurer_name_prefix": null,
24
+ "first_file_date": "2014-05-12",
25
+ "custodian_name_2": null,
26
+ "custodian_zip": null,
27
+ "treasurer_name_1": null,
28
+ "city": "SUNNYVALE",
29
+ "custodian_street_2": null,
30
+ "party_type_full": null,
31
+ "treasurer_name": "RANDI M WILLIS",
32
+ "custodian_street_1": null,
33
+ "last_file_date": "2014-06-10",
34
+ "organization_type_full": null,
35
+ "email": "RANDI.M.WILLIS@GMAIL.COM",
36
+ "treasurer_state": null,
37
+ "state": "CA",
38
+ "treasurer_city": null,
39
+ "street_2": null,
40
+ "custodian_name_title": null,
41
+ "lobbyist_registrant_pac": null,
42
+ "candidate_ids": [],
43
+ "committee_id": "C00563023",
44
+ "treasurer_street_2": null,
45
+ "treasurer_name_2": null,
46
+ "custodian_name_full": null,
47
+ "custodian_name_1": null,
48
+ "website": null,
49
+ "filing_frequency": "T",
50
+ "committee_type_full": "Super PAC (Independent Expenditure-Only)",
51
+ "treasurer_phone": null,
52
+ "custodian_name_prefix": null,
53
+ "committee_type": "O",
54
+ "fax": null,
55
+ "designation": "U",
56
+ "party_type": null,
57
+ "party_full": null,
58
+ "treasurer_zip": null,
59
+ "treasurer_street_1": null,
60
+ "leadership_pac": null,
61
+ "party": null,
62
+ "cycles": [
63
+ 2014
64
+ ],
65
+ "qualifying_date": null,
66
+ "custodian_phone": null,
67
+ "custodian_name_middle": null,
68
+ "street_1": "165 W DUANE AVE",
69
+ "treasurer_name_middle": null
70
+ }
71
+ ]
72
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "pagination": {
3
+ "pages": 1,
4
+ "page": 1,
5
+ "per_page": 20,
6
+ "count": 1
7
+ },
8
+ "api_version": "1.0",
9
+ "results": [
10
+ {
11
+ "street_2": null,
12
+ "cycle": 2014,
13
+ "committee_type": "O",
14
+ "committee_type_full": "Super PAC (Independent Expenditure-Only)",
15
+ "state_full": "California ",
16
+ "expire_date": null,
17
+ "designation": "U",
18
+ "name": "10 ^ 9+",
19
+ "city": "SUNNYVALE",
20
+ "party_full": null,
21
+ "treasurer_name": "RANDI M WILLIS",
22
+ "committee_id": "C00563023",
23
+ "organization_type_full": null,
24
+ "organization_type": null,
25
+ "cycles": [
26
+ 2014
27
+ ],
28
+ "party": null,
29
+ "state": "CA",
30
+ "zip": "94085",
31
+ "street_1": "165 W DUANE AVE",
32
+ "designation_full": "Unauthorized"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "pagination": {
3
+ "pages": 1,
4
+ "page": 1,
5
+ "per_page": 20,
6
+ "count": 2
7
+ },
8
+ "api_version": "1.0",
9
+ "results": [
10
+ {
11
+ "first_file_date": "2015-01-06",
12
+ "candidate_ids": [],
13
+ "committee_type": "Q",
14
+ "committee_type_full": "PAC - Qualified",
15
+ "expire_date": "2015-08-27T00:16:54+00:00",
16
+ "designation": "U",
17
+ "last_file_date": "2015-09-10",
18
+ "party_full": null,
19
+ "treasurer_name": "ROBINSON, JAMES P.",
20
+ "name": "RIGHT TO RISE PAC, INC.",
21
+ "organization_type_full": null,
22
+ "organization_type": null,
23
+ "cycles": [
24
+ 2016
25
+ ],
26
+ "party": null,
27
+ "state": "FL",
28
+ "committee_id": "C00571380",
29
+ "designation_full": "Unauthorized"
30
+ },
31
+ {
32
+ "first_file_date": "2015-01-06",
33
+ "candidate_ids": [],
34
+ "committee_type": "O",
35
+ "committee_type_full": "Super PAC (Independent Expenditure-Only)",
36
+ "expire_date": null,
37
+ "designation": "B",
38
+ "last_file_date": "2015-06-12",
39
+ "party_full": null,
40
+ "treasurer_name": "SPIES, CHARLES R.",
41
+ "name": "RIGHT TO RISE USA",
42
+ "organization_type_full": null,
43
+ "organization_type": null,
44
+ "cycles": [
45
+ 2016
46
+ ],
47
+ "party": null,
48
+ "state": "CA",
49
+ "committee_id": "C00571372",
50
+ "designation_full": "Lobbyist/Registrant PAC"
51
+ }
52
+ ]
53
+ }
data/spec/client_spec.rb CHANGED
@@ -55,6 +55,50 @@ module OpenFecApi
55
55
  end
56
56
  end
57
57
 
58
+ #
59
+ # Candidate Endpoint
60
+ #
61
+
62
+ describe '#candidate' do
63
+ context "when configured" do
64
+ let(:candidate_id){"P00003392"}
65
+ before do
66
+ @client = OpenFecApi::Client.new(ENV["OPEN_FEC_API_KEY"])
67
+ end
68
+
69
+ def request_and_print(candidate_id, options)
70
+ response = @client.candidate(candidate_id, options)
71
+ pp response.summary
72
+ return response
73
+ end #todo: maybe return mock response instead
74
+
75
+ it "returns data about the specified candidate" do
76
+ options = {:page => 1, :per_page => 100}
77
+ response = request_and_print(candidate_id, options)
78
+ candidate_name = response.results.map{|c| c["name"]}.uniq
79
+ expect(candidate_name).to eql(["CLINTON, HILLARY RODHAM"])
80
+ end
81
+ end
82
+ end
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
58
102
  #
59
103
  # Committees Endpoint
60
104
  #
@@ -81,5 +125,34 @@ module OpenFecApi
81
125
  end
82
126
  end
83
127
  end
128
+
129
+
130
+
131
+ #
132
+ # Committee Endpoint
133
+ #
134
+
135
+ describe '#committee' do
136
+ context "when configured" do
137
+ let(:committee_id){"C00571372"}
138
+ before do
139
+ @client = OpenFecApi::Client.new(ENV["OPEN_FEC_API_KEY"])
140
+ end
141
+
142
+ def request_and_print(committee_id, options)
143
+ response = @client.committee(committee_id, options)
144
+ pp response.summary
145
+ return response
146
+ end #todo: maybe return mock response instead
147
+
148
+ it "returns data about the specified committee" do
149
+ options = {:page => 1, :per_page => 100}
150
+ response = request_and_print(committee_id, options)
151
+ committee_name = response.results.map{|c| c["name"]}.uniq
152
+ expect(committee_name).to eql(["RIGHT TO RISE USA"])
153
+ end
154
+ end
155
+ end
156
+
84
157
  end
85
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_fec_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MJ Rossetti (@s2t2)
@@ -108,7 +108,6 @@ files:
108
108
  - ".gitignore"
109
109
  - ".rspec"
110
110
  - CREDITS.md
111
- - ENDPOINTS.md
112
111
  - Gemfile
113
112
  - LICENSE.txt
114
113
  - README.md
@@ -119,12 +118,20 @@ files:
119
118
  - lib/open_fec_api/client.rb
120
119
  - lib/open_fec_api/endpoint.rb
121
120
  - lib/open_fec_api/response.rb
121
+ - lib/open_fec_api/responses/candidate_response.rb
122
122
  - lib/open_fec_api/responses/candidates_response.rb
123
+ - lib/open_fec_api/responses/committee_response.rb
123
124
  - lib/open_fec_api/responses/committees_response.rb
124
125
  - lib/open_fec_api/version.rb
125
- - mock_responses/mock_candidates_response.rb
126
- - mock_responses/mock_committees_response.rb
127
- - mock_responses/over_rate_limit_response.rb
126
+ - mock/responses/candidate.json
127
+ - mock/responses/candidate.rb
128
+ - mock/responses/candidates.json
129
+ - mock/responses/candidates.rb
130
+ - mock/responses/committee.json
131
+ - mock/responses/committee_history.json
132
+ - mock/responses/committees.json
133
+ - mock/responses/committees.rb
134
+ - mock/responses/over_rate_limit.rb
128
135
  - open_fec_api.gemspec
129
136
  - spec/client_spec.rb
130
137
  - spec/spec_helper.rb
data/ENDPOINTS.md DELETED
@@ -1,36 +0,0 @@
1
- ## Endpoints
2
-
3
- Endpoint | Operation | Wrapper Method
4
- --- | --- | ---
5
- Candidates | `GET /candidate/{candidate_id}` | `Candidate#find`
6
- Candidates | `GET /candidate/{candidate_id}/history` | N/A
7
- Candidates | `GET /candidate/{candidate_id}/history/{cycle}` | N/A
8
- Candidates | `GET /candidates` | `Candidate#all`
9
- Candidates | `GET /candidates/search` | N/A
10
- Candidates | `GET /candidate/{candidate_id}/committees` | N/A
11
- Candidates | `GET /candidate/{candidate_id}/committees/history` | N/A
12
- Candidates | `GET /candidate/{candidate_id}/committees/history/{cycle}` | N/A
13
- Committees | `GET /committee/{committee_id}/candidates` | N/A
14
- Committees | `GET /committee/{committee_id}/candidates/history` | N/A
15
- Committees | `GET /committee/{committee_id}/candidates/history/{cycle}` | N/A
16
- Committees | `GET /committee/{committee_id}` | N/A
17
- Committees | `GET /committee/{committee_id}/history` | N/A
18
- Committees | `GET /committee/{committee_id}/history/{cycle}` | N/A
19
- Committees | `GET /committees` | N/A
20
- Filings | `GET /committee/{committee_id}/filings` | N/A
21
- Filings | `GET /filings` | N/A
22
- Financial | `GET /committee/{committee_id}/reports` | N/A
23
- Financial | `GET /committee/{committee_id}/totals` | N/A
24
- Financial | `GET /reports/{committee_type}` | N/A
25
- Schedules | `GET /committee/{committee_id}/schedules/schedule_a/by_contributor` | N/A
26
- Schedules | `GET /committee/{committee_id}/schedules/schedule_a/by_size` | N/A
27
- Schedules | `GET /committee/{committee_id}/schedules/schedule_a/by_state` | N/A
28
- Schedules | `GET /committee/{committee_id}/schedules/schedule_a/by_zip` | N/A
29
- Schedules | `GET /schedules/schedule_a` | N/A
30
- Schedules | `GET /schedules/schedule_a/by_contributor` | N/A
31
- Schedules | `GET /schedules/schedule_a/by_size` | N/A
32
- Schedules | `GET /schedules/schedule_a/by_state` | N/A
33
- Schedules | `GET /schedules/schedule_a/by_zip` | N/A
34
- Schedules | `GET /schedules/schedule_b` | N/A
35
- Search | `GET /names/candidates` | `Candidate#where`
36
- Search | `GET /names/committees` | N/A