find_reps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2dc1fac08b030da8a601212e27127c1c7fb2f3d05424dd3d61ee01cebd06ba4e
4
+ data.tar.gz: 64ce3219729e0b84c55a2eaebd7fe9a4944393a71354b12750f60a44276b05cb
5
+ SHA512:
6
+ metadata.gz: 16cc702c71968bf1f4f55177879ba1b97d16c7f7e237a8e2e71918a7ec0103031c4adb2492030ead2117d067f21c9400adef2ef74fa10730e44034e6c8b71acc
7
+ data.tar.gz: 66a02af5a4fb2d515370bec4bf1cc9890acb4a5e9a3a3325261fd7cb3741ce73904088a669264def7f642c8d49b5cd7cfbb7c55b1100e819bc59aaa0cb4401ef
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in find_reps.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ find_reps (0.1.0)
5
+ faraday (~> 0.15.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ faraday (0.15.4)
11
+ multipart-post (>= 1.2, < 3)
12
+ multipart-post (2.0.0)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.17)
20
+ find_reps!
21
+ rake (~> 10.0)
22
+
23
+ BUNDLED WITH
24
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # FindReps
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/find_reps`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'find_reps'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install find_reps
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thewatts/find_reps.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "find_reps"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/find_reps.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "find_reps/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "find_reps"
8
+ spec.version = FindReps::VERSION
9
+ spec.authors = ["Nathaniel Watts"]
10
+ spec.email = ["reg@nathanielwatts.com"]
11
+
12
+ spec.summary = %q{A sample gem used to fetch representative data from an API.}
13
+ spec.description = %q{A sample gem used to fetch representative data from an API.}
14
+ spec.homepage = "https://nathanielwatts.com"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_dependency "faraday", "~> 0.15.4"
37
+ spec.add_development_dependency "bundler", "~> 1.17"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
@@ -0,0 +1,3 @@
1
+ module FindReps
2
+ VERSION = "0.1.0"
3
+ end
data/lib/find_reps.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative "find_reps/version"
2
+ require "ostruct"
3
+ require "faraday"
4
+
5
+ module FindReps
6
+ extend self
7
+
8
+ class Error < StandardError; end
9
+ class Representative < OpenStruct; end
10
+
11
+ def endpoint=(value)
12
+ @endpoint = value
13
+ end
14
+
15
+ def endpoint
16
+ @endpoint
17
+ end
18
+
19
+ def by_zipcode(zipcode)
20
+ if zipcode.nil? || zipcode.empty?
21
+ raise Error, "must provide a zipcode"
22
+ end
23
+
24
+ if endpoint.nil?
25
+ raise Error, "must assign an endpoint"
26
+ end
27
+
28
+ url = "#{endpoint}/api/representatives.json?zipcode=#{zipcode}"
29
+ response = Faraday.get(url)
30
+
31
+ if response.status == 200
32
+ JSON.parse(response.body).map { |rep_data| Representative.new(rep_data) }
33
+ else
34
+ raise Error, "status: #{response.status}, body: #{response.body}"
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: find_reps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Watts
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-11 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: 0.15.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A sample gem used to fetch representative data from an API.
56
+ email:
57
+ - reg@nathanielwatts.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - find_reps.gemspec
70
+ - lib/find_reps.rb
71
+ - lib/find_reps/version.rb
72
+ homepage: https://nathanielwatts.com
73
+ licenses: []
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ homepage_uri: https://nathanielwatts.com
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A sample gem used to fetch representative data from an API.
96
+ test_files: []