get_your_rep 0.1.9 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1782c2a5230bdcc479cec091d9a35c066e8fd845
4
- data.tar.gz: 968959010cce628943b0451ff3b21d5389c3b628
3
+ metadata.gz: ba6cc36506ebdc000dd985795884989ae947ec4a
4
+ data.tar.gz: ae75fd36e09b93d71417ed39b24e674169356610
5
5
  SHA512:
6
- metadata.gz: 743d761b375e97435248cf3b1f9a798c6b5282fdb21bcfdde43999894083086730483ce353272f7c2afa0f462ff8e39b465b31218832d0f5f0874d3ba0404283
7
- data.tar.gz: 574ec214a72556ed7b3bc3bff029a74007a0c7398abec54f27d17f541bea72df6f1120b08cad16fe462fdc128de7a6528e497fddfdb06f78ea31f44942ec441d
6
+ metadata.gz: 1644ce639ff3fedb084bfd2e5ace28633d355da9a63ce7ca5134f10483746f4a45335b6f75c8956207309fa5f738775a101c7985ae320942856464feb5093722
7
+ data.tar.gz: fedee5d0c4d211768ba342f988553c4af70687cc49c27c20d1b09041a93a38865c7bea921ddc5b648610b1402f7e40aba978651ea4f68e5eb3a5bf7525e9ed83
data/.gitignore ADDED
@@ -0,0 +1,55 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ # RubyMine project settings
39
+ .idea
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ Gemfile.lock
49
+ .ruby-version
50
+ .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+ Contact GitHub API Training Shop Blog About
55
+ © 2016 GitHub, Inc. Terms Privacy Security Status Help
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'lib/get_your_rep/patriotic.rb'
10
+
11
+ Metrics/MethodLength:
12
+ Max: 15
13
+ Exclude:
14
+ - 'test/*'
15
+ - 'lib/get_your_rep/cli.rb'
16
+ - 'lib/get_your_rep/patriotic.rb'
17
+
18
+ Style/Documentation:
19
+ Exclude:
20
+ - 'spec/**/*'
21
+ - 'test/**/*'
22
+
23
+ Metrics/ModuleLength:
24
+ Max: 200
25
+
26
+ Metrics/ClassLength:
27
+ Max: 200
28
+
29
+ Metrics/AbcSize:
30
+ Enabled: false
31
+
32
+ Metrics/CyclomaticComplexity:
33
+ Enabled: false
34
+
35
+ Style/MultilineOperationIndentation:
36
+ Exclude:
37
+ - 'lib/get_your_rep/patriotic.rb'
38
+
39
+ Style/HashSyntax:
40
+ Enabled: true
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 m. simon borg
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Get yo' rep!
2
+
3
+ This is the companion [gem](https://rubygems.org/gems/get_your_rep) for the [Phone Your Rep API] (https://github.com/thecristen/phone-your-rep-api)
4
+
5
+ This gem sends requests to the Google Civic Information API for info on your representatives and parses the JSON response into a Ruby hash.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'get_your_rep'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install get_your_rep
22
+
23
+ ## You must use your own Google API key activated for use with the [Civic Information API](https://developers.google.com/civic-information/).
24
+
25
+ Add this line to your ~/.bashrc or ~/.bash_profile
26
+ `export GOOGLE_API_KEY="<YOUR_API_KEY>"`
27
+
28
+ ## Usage
29
+
30
+ ### Usage documentation is out of date with new release. Update coming soon. Install and setup are accurate!
31
+
32
+ Send queries like this `reps = GetYourRep.now(address, level:, role:)` to gather a Delegation of Representatives.
33
+
34
+ `address` is your address. You can use just a zip code, but use a full address for the best results. Don't worry about commas, spaces, character case, or `.`s (`"123 1/2 main St., anywhere CA 12345"` is A-OK)
35
+
36
+ Some queries will return `nil` when using only a zip code because not every zip code can be directly mapped to a voting district. I strongly recommend using a full address.
37
+
38
+ `:level` is the level of government. The two values that are currently supported are `"state"` and `"national"`. The default value is `"national"`
39
+
40
+ `:role` corresponds to the rep's legislative house. The values that are currently supported are `"representative"`, `"senator"`, `"executive"` and `"vice executive"`. The default value is `"representative"`
41
+
42
+ Add Delegations together with `reps << other_reps`.
43
+
44
+ Or, get Congress, State Legislature, Governor and Lieutenant Governor all at once with `GetYourRep.all(address)`.
45
+
46
+ When making db queries, for instance in a Rails app, you can use form useful collection like this:
47
+
48
+ ```
49
+ 2.3.3 :008 > reps
50
+ => [{...}, {...}, {...}, {...}, {...}]
51
+ 2.3.3 :009 > reps.first_names
52
+ => ["Peter", "Bernard", "Patrick J.", "Peter", "Phil"]
53
+ 2.3.3 :010 > reps.last_names
54
+ => ["Welch", "Sanders", "Leahy", "Shumlin", "Scott"]
55
+ ```
56
+
57
+ `reps.business_cards` gathers attributes of all reps in a Delegation into a simple array for easy iteration.
58
+
59
+ You can access an individual Representative and its attributes like this:
60
+ ```
61
+ 2.3.3 :003 > rep = reps.second
62
+ => {:name=>"Bernard Sanders", :office=>"United States Senate", :party=>"Independent", :phone=>"(202) 224-5141", :address_1=>"332 dirksen building", :address_2=>nil, :address_3=>"Washington, DC 20510", :email=>nil, :url=>"http://www.sanders.senate.gov/", :photo=>"http://bioguide.congress.gov/bioguide/photo/S/S000033.jpg", :googleplus=>"+BernieSanders", :facebook=>"senatorsanders", :twitter=>"sensanders", :youtube=>"senatorsanders"}
63
+ 2.3.3 :004 > rep.name
64
+ => "Bernard Sanders"
65
+ 2.3.3 :005 > rep.first_name
66
+ => "Bernard"
67
+ 2.3.3 :006 > rep.last_name
68
+ => "Sanders"
69
+ 2.3.3 :007 > rep.party
70
+ => "Independent"
71
+ ```
72
+
73
+ ## Development
74
+
75
+ 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. Add `export GOOGLE_API_KEY="<YOUR_API_KEY>"` to your `.bashrc` or `.bash_profile` and then `bundle exec rake_test`.
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/msimonborg/get_your_rep.
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/**/*test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'get_your_rep'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ require 'pry'
13
+ Pry.start
14
+
15
+ # require "irb"
16
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/config.reek ADDED
@@ -0,0 +1,18 @@
1
+ Attribute:
2
+ enabled: false
3
+
4
+ DuplicateMethodCall:
5
+ exclude:
6
+ - ['lib/get_your_rep/patriotic.rb']
7
+
8
+ TooManyStatements:
9
+ exclude:
10
+ - ['lib/get_your_rep/patriotic.rb']
11
+
12
+ TooManyMethods:
13
+ exclude:
14
+ - ['lib/get_your_rep/representative.rb'] # #business_card is the offender. TODO: write method or delete.
15
+
16
+ UncommunicativeVariableName:
17
+ exclude:
18
+ - ['lib/get_your_rep/responses/google_office.rb'] # doesn't like @line1 and @line1 but I don't care.
data/exe/reps ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'get_your_rep'
7
+
8
+ GetYourRep::CLI.call
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'date'
6
+ require 'get_your_rep/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'get_your_rep'
10
+ s.version = GetYourRep::VERSION
11
+ s.date = Date.today.to_s
12
+ s.required_ruby_version = '>= 2.0.0'
13
+ s.post_install_message = "If you are upgrading from get_your_rep ~> 0.1, version 1.0 may break your app. It is \
14
+ a good idea to upgrade, but please read the documentation first!"
15
+ s.add_dependency 'httparty', '~> 0'
16
+ s.add_dependency 'geocoder', '~> 1.4', '>= 1.4.1'
17
+ s.add_dependency 'colorize', '~> 0.8.1'
18
+ s.add_development_dependency 'pry', '~> 0'
19
+ s.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.1'
20
+ s.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.13'
21
+ s.add_development_dependency 'rake', '~> 12.0'
22
+ s.summary = "Get yo' rep!"
23
+ s.description = "Get your rep(s) from Google's Civic Information API and Open States. Formerly get-your-rep."
24
+ s.authors = ['msimonborg']
25
+ s.email = 'msimonborg@gmail.com'
26
+ s.homepage = 'https://github.com/msimonborg/get-your-rep'
27
+ s.license = 'MIT'
28
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ s.bindir = 'exe'
30
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ s.require_paths = ['lib']
32
+ end
data/lib/get_your_rep.rb CHANGED
@@ -1,26 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
  require 'geocoder'
5
+ require 'colorize'
6
+ require 'pry' # TODO: remove for publication
7
+
8
+ require 'get_your_rep/version'
9
+ require 'get_your_rep/errors'
10
+ require 'get_your_rep/get_your_rep_module'
11
+ require 'get_your_rep/patriotic'
12
+ require 'get_your_rep/cli'
3
13
  require 'get_your_rep/open_states'
4
14
  require 'get_your_rep/delegation'
5
15
  require 'get_your_rep/representative'
6
16
  require 'get_your_rep/google'
7
- require 'core_extensions/array/get_your_rep_mutations'
8
- require 'core_extensions/hash/get_your_rep_mutations'
9
-
10
- ##
11
- # Monkey patch the Array and Hash classes with .to_rep and .to_del methods.
12
- Array.include CoreExtensions::Array::GetYourRepMutations
13
- Hash.include CoreExtensions::Hash::GetYourRepMutations
14
-
15
- ##
16
- # Top level namespace.
17
- module GetYourRep
17
+ require 'get_your_rep/office_location'
18
+ require 'get_your_rep/responses/open_states_office'
19
+ require 'get_your_rep/responses/base'
20
+ require 'get_your_rep/responses/open_states_rep'
21
+ require 'get_your_rep/responses/google_office'
22
+ require 'get_your_rep/responses/google_rep'
18
23
 
19
- ##
20
- # Get all reps using Google for state executives and national reps,
21
- # and OpenStates for state reps.
22
- def self.all(address)
23
- @reps = Google.top_level_reps(address)
24
- @reps << OpenStates.now(address)
25
- end
26
- end
24
+ # Top level namespace
25
+ module GetYourRep; end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+ module GetYourRep
3
+ # Command Line Interface
4
+ module CLI # :nodoc:
5
+ class << self
6
+ include GetYourRep
7
+
8
+ attr_reader :line, :address, :delegation
9
+
10
+ def call
11
+ Patriotic.stars_and_bars
12
+ Patriotic.welcome
13
+ @line = 0
14
+ start
15
+ end
16
+
17
+ private
18
+
19
+ def start
20
+ puts '', "Type 'help' for help".blue
21
+ loop do
22
+ new_line
23
+ print "[#{line}] gyr(#{VERSION}) -> "
24
+ input = gets.strip.downcase
25
+
26
+ case input
27
+ when 'help'
28
+ help
29
+ when 'exit'
30
+ break
31
+ when 'set address'
32
+ set_address
33
+ when 'address'
34
+ find_or_set_address
35
+ when 'all reps'
36
+ all_reps
37
+ when 'google all reps'
38
+ google_all_reps
39
+ when 'google congress only'
40
+ google_congress_only
41
+ when 'open states'
42
+ open_states
43
+ else
44
+ command_not_found_error
45
+ end
46
+ end
47
+ end
48
+
49
+ def find_or_set_address
50
+ puts address || set_address
51
+ end
52
+
53
+ def new_line
54
+ @line += 1
55
+ end
56
+
57
+ def help
58
+ puts "'help'...................list of commands".bold.blue
59
+ puts "'address'................displays address or sets it if there is none".bold.blue
60
+ puts "'set address'............set a new address".bold.blue
61
+ puts "'all reps'...............get federal legislators from Google".bold.blue
62
+ puts " and state legislators from Open States".bold.blue
63
+ puts "'google all reps'........get all federal and state executives and".bold.blue
64
+ puts " legislators from Google".bold.blue
65
+ puts "'google congress only'...get only congress from Google".bold.blue
66
+ puts "'open states'............get only state legislators from Open States".bold.blue
67
+ end
68
+
69
+ def set_address
70
+ puts "\nThe most accurate results will always be achieved with a full address, \n\
71
+ but you can try a zip code if you insist.".yellow
72
+ puts 'Hint: '.bold.blue + 'GYR will geocode your zip to an address anyway.'.yellow
73
+ print "\nPlease enter your address -> "
74
+ self.address = gets.strip
75
+ end
76
+
77
+ def address=(value)
78
+ @address = address_is_a_zip?(value) ? convert_zip_to_address(value) : value
79
+ end
80
+
81
+ def all_reps
82
+ address || set_address
83
+ super(address)
84
+ display_reps
85
+ end
86
+
87
+ def google_all_reps
88
+ address || set_address
89
+ @delegation = Google.all_reps(address)
90
+ display_reps
91
+ end
92
+
93
+ def google_congress_only
94
+ address || set_address
95
+ @delegation = Google.all_reps(address, congress_only: true)
96
+ display_reps
97
+ end
98
+
99
+ def open_states
100
+ address || set_address
101
+ @delegation = OpenStates.all_reps(address)
102
+ display_reps
103
+ end
104
+
105
+ def display_reps
106
+ delegation.reps.each do |rep|
107
+ @banner ||= Patriotic.banner
108
+ rep.cli_display
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end