congress_gov 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +156 -0
  5. data/lib/congress_gov/client.rb +125 -0
  6. data/lib/congress_gov/configuration.rb +48 -0
  7. data/lib/congress_gov/error.rb +46 -0
  8. data/lib/congress_gov/resources/amendment.rb +107 -0
  9. data/lib/congress_gov/resources/base.rb +74 -0
  10. data/lib/congress_gov/resources/bill.rb +199 -0
  11. data/lib/congress_gov/resources/bound_congressional_record.rb +48 -0
  12. data/lib/congress_gov/resources/clerk_vote.rb +125 -0
  13. data/lib/congress_gov/resources/committee.rb +136 -0
  14. data/lib/congress_gov/resources/committee_meeting.rb +37 -0
  15. data/lib/congress_gov/resources/committee_print.rb +50 -0
  16. data/lib/congress_gov/resources/committee_report.rb +65 -0
  17. data/lib/congress_gov/resources/congress_info.rb +32 -0
  18. data/lib/congress_gov/resources/crs_report.rb +17 -0
  19. data/lib/congress_gov/resources/daily_congressional_record.rb +48 -0
  20. data/lib/congress_gov/resources/hearing.rb +37 -0
  21. data/lib/congress_gov/resources/house_communication.rb +51 -0
  22. data/lib/congress_gov/resources/house_requirement.rb +36 -0
  23. data/lib/congress_gov/resources/house_vote.rb +127 -0
  24. data/lib/congress_gov/resources/law.rb +53 -0
  25. data/lib/congress_gov/resources/member.rb +151 -0
  26. data/lib/congress_gov/resources/nomination.rb +74 -0
  27. data/lib/congress_gov/resources/senate_communication.rb +51 -0
  28. data/lib/congress_gov/resources/summary.rb +27 -0
  29. data/lib/congress_gov/resources/treaty.rb +75 -0
  30. data/lib/congress_gov/response.rb +109 -0
  31. data/lib/congress_gov/version.rb +6 -0
  32. data/lib/congress_gov.rb +180 -0
  33. metadata +237 -0
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CongressGov
4
+ module Resources
5
+ # Access treaty data from the Congress.gov API.
6
+ class Treaty < Base
7
+ # List treaties, optionally filtered by congress.
8
+ #
9
+ # @param congress [Integer, nil] filter to a specific Congress
10
+ # @param limit [Integer]
11
+ # @param offset [Integer]
12
+ # @return [CongressGov::Response]
13
+ def list(congress: nil, limit: 20, offset: 0)
14
+ path = congress ? "treaty/#{congress}" : 'treaty'
15
+ client.get(path, { limit: limit, offset: offset })
16
+ end
17
+
18
+ # Fetch a treaty's full detail record.
19
+ #
20
+ # @param congress [Integer] e.g. 119
21
+ # @param number [Integer] treaty number
22
+ # @return [CongressGov::Response]
23
+ def get(congress, number)
24
+ client.get("treaty/#{congress}/#{number}")
25
+ end
26
+
27
+ # Fetch a treaty with a specific suffix.
28
+ #
29
+ # @param congress [Integer]
30
+ # @param number [Integer]
31
+ # @param suffix [String] treaty suffix
32
+ # @return [CongressGov::Response]
33
+ def get_with_suffix(congress, number, suffix)
34
+ client.get("treaty/#{congress}/#{number}/#{suffix}")
35
+ end
36
+
37
+ # Actions taken on a treaty.
38
+ #
39
+ # @param congress [Integer]
40
+ # @param number [Integer]
41
+ # @param limit [Integer]
42
+ # @param offset [Integer]
43
+ # @return [CongressGov::Response]
44
+ def actions(congress, number, limit: 20, offset: 0)
45
+ client.get("treaty/#{congress}/#{number}/actions",
46
+ { limit: limit, offset: offset })
47
+ end
48
+
49
+ # Actions for a treaty with a specific suffix.
50
+ #
51
+ # @param congress [Integer]
52
+ # @param number [Integer]
53
+ # @param suffix [String]
54
+ # @param limit [Integer]
55
+ # @param offset [Integer]
56
+ # @return [CongressGov::Response]
57
+ def actions_with_suffix(congress, number, suffix, limit: 20, offset: 0)
58
+ client.get("treaty/#{congress}/#{number}/#{suffix}/actions",
59
+ { limit: limit, offset: offset })
60
+ end
61
+
62
+ # Committees associated with a treaty.
63
+ #
64
+ # @param congress [Integer]
65
+ # @param number [Integer]
66
+ # @param limit [Integer]
67
+ # @param offset [Integer]
68
+ # @return [CongressGov::Response]
69
+ def committees(congress, number, limit: 20, offset: 0)
70
+ client.get("treaty/#{congress}/#{number}/committees",
71
+ { limit: limit, offset: offset })
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CongressGov
4
+ # Wraps a raw Faraday response body.
5
+ # Handles the Congress.gov pagination envelope uniformly.
6
+ # Includes +Enumerable+ so callers can iterate results directly.
7
+ class Response
8
+ include Enumerable
9
+
10
+ # @return [Hash, Array, nil] the parsed JSON body.
11
+ attr_reader :raw
12
+ # @return [Integer] the HTTP status code.
13
+ attr_reader :status
14
+
15
+ # @param body [Hash, Array, nil] parsed response body.
16
+ # @param status [Integer] HTTP status code.
17
+ def initialize(body, status)
18
+ @raw = body || {}
19
+ @status = status
20
+ end
21
+
22
+ # The primary results collection. Congress.gov uses different top-level keys
23
+ # per endpoint ("members", "bills", "house-vote", etc.).
24
+ # Returns the first Array value found in the body, falling back to [].
25
+ #
26
+ # @return [Array]
27
+ def results
28
+ return raw if raw.is_a?(Array)
29
+ return [] unless raw.is_a?(Hash)
30
+
31
+ array_value = raw.values.find { |v| v.is_a?(Array) }
32
+ array_value || []
33
+ end
34
+
35
+ # Yields each result, enabling Enumerable methods on the response.
36
+ #
37
+ # @yield [Hash] each result item
38
+ # @return [Enumerator] if no block given
39
+ def each(&)
40
+ results.each(&)
41
+ end
42
+
43
+ # Total number of matching records across all pages.
44
+ #
45
+ # @return [Integer, nil]
46
+ def total_count
47
+ raw.dig('pagination', 'count') if raw.is_a?(Hash)
48
+ end
49
+
50
+ # URL of the next page, or nil if on the last page.
51
+ #
52
+ # @return [String, nil]
53
+ def next_url
54
+ raw.dig('pagination', 'next') if raw.is_a?(Hash)
55
+ end
56
+
57
+ # URL of the previous page, or nil if on the first page.
58
+ #
59
+ # @return [String, nil]
60
+ def prev_url
61
+ raw.dig('pagination', 'prev') if raw.is_a?(Hash)
62
+ end
63
+
64
+ # Whether another page of results exists.
65
+ #
66
+ # @return [Boolean]
67
+ def has_next_page?
68
+ !next_url.nil?
69
+ end
70
+
71
+ # The offset for the next page, parsed from next_url.
72
+ #
73
+ # @return [Integer, nil]
74
+ def next_offset
75
+ return nil unless next_url
76
+
77
+ uri = URI.parse(next_url)
78
+ params = URI.decode_www_form(uri.query.to_s).to_h
79
+ params['offset']&.to_i
80
+ end
81
+
82
+ # Delegates key lookup to the raw response body.
83
+ #
84
+ # @param key [String] top-level key in the parsed JSON.
85
+ # @return [Object, nil]
86
+ def [](key)
87
+ raw[key] if raw.is_a?(Hash)
88
+ end
89
+
90
+ # Returns the raw parsed response body as a Hash.
91
+ #
92
+ # @return [Hash, Array]
93
+ def to_h
94
+ raw
95
+ end
96
+
97
+ # Concise representation for debugging.
98
+ #
99
+ # @return [String]
100
+ def inspect
101
+ count = results.size
102
+ total = total_count
103
+ more = has_next_page? ? ' has_next_page' : ''
104
+ "#<#{self.class} status=#{status} results=#{count}#{"/#{total}" if total}#{more}>"
105
+ end
106
+
107
+ alias to_s inspect
108
+ end
109
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CongressGov
4
+ # Current version of the CongressGov gem.
5
+ VERSION = '0.1.0'
6
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'congress_gov/version'
4
+ require 'congress_gov/configuration'
5
+ require 'congress_gov/error'
6
+ require 'congress_gov/response'
7
+ require 'congress_gov/client'
8
+ require 'congress_gov/resources/base'
9
+ require 'congress_gov/resources/member'
10
+ require 'congress_gov/resources/bill'
11
+ require 'congress_gov/resources/house_vote'
12
+ require 'congress_gov/resources/clerk_vote'
13
+ require 'congress_gov/resources/committee'
14
+ require 'congress_gov/resources/amendment'
15
+ require 'congress_gov/resources/nomination'
16
+ require 'congress_gov/resources/treaty'
17
+ require 'congress_gov/resources/house_communication'
18
+ require 'congress_gov/resources/senate_communication'
19
+ require 'congress_gov/resources/house_requirement'
20
+ require 'congress_gov/resources/law'
21
+ require 'congress_gov/resources/congress_info'
22
+ require 'congress_gov/resources/summary'
23
+ require 'congress_gov/resources/committee_report'
24
+ require 'congress_gov/resources/committee_print'
25
+ require 'congress_gov/resources/committee_meeting'
26
+ require 'congress_gov/resources/hearing'
27
+ require 'congress_gov/resources/daily_congressional_record'
28
+ require 'congress_gov/resources/bound_congressional_record'
29
+ require 'congress_gov/resources/crs_report'
30
+
31
+ # Ruby client for the Congress.gov REST API v3.
32
+ # @see https://api.congress.gov/
33
+ module CongressGov
34
+ # Mutex for thread-safe initialization of configuration and client.
35
+ @mutex = Mutex.new
36
+
37
+ class << self
38
+ # Returns the current configuration instance.
39
+ # Thread-safe via Mutex.
40
+ #
41
+ # @return [CongressGov::Configuration]
42
+ def configuration
43
+ @mutex.synchronize { @configuration ||= Configuration.new }
44
+ end
45
+
46
+ # Yields the configuration instance for modification.
47
+ #
48
+ # @yieldparam config [CongressGov::Configuration]
49
+ # @return [void]
50
+ def configure
51
+ @mutex.synchronize { yield(@configuration ||= Configuration.new) }
52
+ end
53
+
54
+ # Resets configuration and client to defaults.
55
+ # Thread-safe via Mutex.
56
+ #
57
+ # @return [void]
58
+ def reset!
59
+ @mutex.synchronize do
60
+ @configuration = Configuration.new
61
+ @client = nil
62
+ end
63
+ end
64
+
65
+ # Returns the shared API client instance.
66
+ # Thread-safe via Mutex.
67
+ #
68
+ # @return [CongressGov::Client]
69
+ def client
70
+ @mutex.synchronize { @client ||= Client.new(@configuration || Configuration.new) }
71
+ end
72
+
73
+ # Resource shorthand accessors
74
+
75
+ # @return [CongressGov::Resources::Member]
76
+ def member
77
+ Resources::Member.new(client)
78
+ end
79
+
80
+ # @return [CongressGov::Resources::Bill]
81
+ def bill
82
+ Resources::Bill.new(client)
83
+ end
84
+
85
+ # @return [CongressGov::Resources::HouseVote]
86
+ def house_vote
87
+ Resources::HouseVote.new(client)
88
+ end
89
+
90
+ # @return [CongressGov::Resources::ClerkVote]
91
+ def clerk_vote
92
+ Resources::ClerkVote.new(client)
93
+ end
94
+
95
+ # @return [CongressGov::Resources::Committee]
96
+ def committee
97
+ Resources::Committee.new(client)
98
+ end
99
+
100
+ # @return [CongressGov::Resources::Amendment]
101
+ def amendment
102
+ Resources::Amendment.new(client)
103
+ end
104
+
105
+ # @return [CongressGov::Resources::Nomination]
106
+ def nomination
107
+ Resources::Nomination.new(client)
108
+ end
109
+
110
+ # @return [CongressGov::Resources::Treaty]
111
+ def treaty
112
+ Resources::Treaty.new(client)
113
+ end
114
+
115
+ # @return [CongressGov::Resources::HouseCommunication]
116
+ def house_communication
117
+ Resources::HouseCommunication.new(client)
118
+ end
119
+
120
+ # @return [CongressGov::Resources::SenateCommunication]
121
+ def senate_communication
122
+ Resources::SenateCommunication.new(client)
123
+ end
124
+
125
+ # @return [CongressGov::Resources::HouseRequirement]
126
+ def house_requirement
127
+ Resources::HouseRequirement.new(client)
128
+ end
129
+
130
+ # @return [CongressGov::Resources::Law]
131
+ def law
132
+ Resources::Law.new(client)
133
+ end
134
+
135
+ # @return [CongressGov::Resources::CongressInfo]
136
+ def congress_info
137
+ Resources::CongressInfo.new(client)
138
+ end
139
+
140
+ # @return [CongressGov::Resources::Summary]
141
+ def summary
142
+ Resources::Summary.new(client)
143
+ end
144
+
145
+ # @return [CongressGov::Resources::CommitteeReport]
146
+ def committee_report
147
+ Resources::CommitteeReport.new(client)
148
+ end
149
+
150
+ # @return [CongressGov::Resources::CommitteePrint]
151
+ def committee_print
152
+ Resources::CommitteePrint.new(client)
153
+ end
154
+
155
+ # @return [CongressGov::Resources::CommitteeMeeting]
156
+ def committee_meeting
157
+ Resources::CommitteeMeeting.new(client)
158
+ end
159
+
160
+ # @return [CongressGov::Resources::Hearing]
161
+ def hearing
162
+ Resources::Hearing.new(client)
163
+ end
164
+
165
+ # @return [CongressGov::Resources::DailyCongressionalRecord]
166
+ def daily_congressional_record
167
+ Resources::DailyCongressionalRecord.new(client)
168
+ end
169
+
170
+ # @return [CongressGov::Resources::BoundCongressionalRecord]
171
+ def bound_congressional_record
172
+ Resources::BoundCongressionalRecord.new(client)
173
+ end
174
+
175
+ # @return [CongressGov::Resources::CrsReport]
176
+ def crs_report
177
+ Resources::CrsReport.new(client)
178
+ end
179
+ end
180
+ end
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: congress_gov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ThePublicTab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-retry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday-http-cache
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '6.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '6.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.23'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.23'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.65'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.65'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.22'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.22'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dotenv
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ description: |
168
+ A Ruby client for the Congress.gov REST API v3. Access member data,
169
+ roll call votes, bill details, committee information, and more.
170
+ Includes a fallback parser for Clerk of the House XML vote records.
171
+ The first Ruby client targeting the current v3 API.
172
+ email:
173
+ - dev@thepublictab.com
174
+ executables: []
175
+ extensions: []
176
+ extra_rdoc_files: []
177
+ files:
178
+ - CHANGELOG.md
179
+ - LICENSE.txt
180
+ - README.md
181
+ - lib/congress_gov.rb
182
+ - lib/congress_gov/client.rb
183
+ - lib/congress_gov/configuration.rb
184
+ - lib/congress_gov/error.rb
185
+ - lib/congress_gov/resources/amendment.rb
186
+ - lib/congress_gov/resources/base.rb
187
+ - lib/congress_gov/resources/bill.rb
188
+ - lib/congress_gov/resources/bound_congressional_record.rb
189
+ - lib/congress_gov/resources/clerk_vote.rb
190
+ - lib/congress_gov/resources/committee.rb
191
+ - lib/congress_gov/resources/committee_meeting.rb
192
+ - lib/congress_gov/resources/committee_print.rb
193
+ - lib/congress_gov/resources/committee_report.rb
194
+ - lib/congress_gov/resources/congress_info.rb
195
+ - lib/congress_gov/resources/crs_report.rb
196
+ - lib/congress_gov/resources/daily_congressional_record.rb
197
+ - lib/congress_gov/resources/hearing.rb
198
+ - lib/congress_gov/resources/house_communication.rb
199
+ - lib/congress_gov/resources/house_requirement.rb
200
+ - lib/congress_gov/resources/house_vote.rb
201
+ - lib/congress_gov/resources/law.rb
202
+ - lib/congress_gov/resources/member.rb
203
+ - lib/congress_gov/resources/nomination.rb
204
+ - lib/congress_gov/resources/senate_communication.rb
205
+ - lib/congress_gov/resources/summary.rb
206
+ - lib/congress_gov/resources/treaty.rb
207
+ - lib/congress_gov/response.rb
208
+ - lib/congress_gov/version.rb
209
+ homepage: https://github.com/xjackk/congress-gov-rb
210
+ licenses:
211
+ - MIT
212
+ metadata:
213
+ homepage_uri: https://github.com/xjackk/congress-gov-rb
214
+ source_code_uri: https://github.com/xjackk/congress-gov-rb
215
+ changelog_uri: https://github.com/xjackk/congress-gov-rb/blob/main/CHANGELOG.md
216
+ bug_tracker_uri: https://github.com/xjackk/congress-gov-rb/issues
217
+ rubygems_mfa_required: 'true'
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 3.1.0
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubygems_version: 3.5.11
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: Ruby client for the Congress.gov API v3
237
+ test_files: []