federal_rep_lookup 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6d44515d00e2f0ebd53975d45bed632a0f31b2be31faa31b02eee409bc419de0
4
+ data.tar.gz: c6cc68e9e5944092187d4e9e7aadd927347c8da06e32ecf5d1df5a8bbcb9a490
5
+ SHA512:
6
+ metadata.gz: dc10a8910c86162522de74b63f0eff6795fbffe9764d2115480da341d2a7f5e0c13906d753aa79ece5894ce2080c1405a10784442bdc2ebfe7721e45804bee6c
7
+ data.tar.gz: 35639894cf9df16f618a14583911a43e65084638f23fc859b7000a4e312600eda6373d942721fd0363b1cd170587c72fd877fa101d488657f28868de1cc805f6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Jonathan Hooper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FederalRepLookup
2
+
3
+ This is a tool for looking up Federal Congresspeople based on zipcode they represent.
4
+
5
+ ## Installation
6
+
7
+ This can be installed by adding the gem to you Gemfil
8
+
9
+ ```bash
10
+ gem 'federal_rep_lookup'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ TODO: Write usage instructions here
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
+
21
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/federal_rep_lookup.
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ module FederalRepLookup
2
+ CongressPerson = Struct.new(:name, :party, :state, :district, :phone, :office, :link, keyword_init: true)
3
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FederalRepLookup
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,28 @@
1
+ module FederalRepLookup
2
+ class WhoIsMyRepClient
3
+ BASE_URL = "https://whoismyrepresentative.com/getall_mems.php"
4
+
5
+ def lookup(zipcode:)
6
+ encoded_params = URI.encode_www_form(
7
+ zip: zipcode,
8
+ output: :json,
9
+ )
10
+ url = [BASE_URL, '?', encoded_params].join
11
+ response = Faraday.get(url)
12
+
13
+ results = JSON.parse(response.body)['results']
14
+ results.map do |result|
15
+ CongressPerson.new(**result)
16
+ end
17
+ rescue JSON::ParserError
18
+ if response.body.match?(/message=['"]No Data Found['"]/)
19
+ # When no congress people are found for a zipcode the service returns
20
+ # an XML document. That cannot be parsed as JSON so we rescue the parse
21
+ # error and return an empty array if the not found message appears.
22
+ []
23
+ else
24
+ raise
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'json'
5
+ require 'faraday'
6
+
7
+ require_relative "federal_rep_lookup/version"
8
+ require_relative "federal_rep_lookup/congress_person"
9
+ require_relative "federal_rep_lookup/who_is_my_rep_client"
10
+
11
+ module FederalRepLookup
12
+ class Error < StandardError; end
13
+
14
+ def self.lookup(zipcode:)
15
+ WhoIsMyRepClient.new.lookup(zipcode:)
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module FederalRepLookup
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: federal_rep_lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Hooper
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-05-16 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: This is a ruby gem for looking up your member of congress. It uses whoismyrepresentative.com
27
+ to lookup reps by zipcode.
28
+ email:
29
+ - jon9820@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/federal_rep_lookup.rb
39
+ - lib/federal_rep_lookup/congress_person.rb
40
+ - lib/federal_rep_lookup/version.rb
41
+ - lib/federal_rep_lookup/who_is_my_rep_client.rb
42
+ - sig/federal_rep_lookup.rbs
43
+ homepage: https://github.com/Tesibus/federal_rep_lookup
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/Tesibus/federal_rep_lookup
48
+ source_code_uri: https://github.com/Tesibus/federal_rep_lookup
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.1.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.6.2
64
+ specification_version: 4
65
+ summary: A ruby gem for looking up your members of congress
66
+ test_files: []