peerstreet-client-pandawhisperer 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
+ SHA1:
3
+ metadata.gz: a0c01a5e0890af26733467d71cb57ea9e3d77733
4
+ data.tar.gz: 752c24e89424a238c5a7dd1114675bac28eef9fd
5
+ SHA512:
6
+ metadata.gz: 793e46bb9fb6e563bf5022331c5ffe74cf45ac845dbfc482a1dcba81fafba938f287f375c376710451edde9fb2579ddee1162470d468c667ef892862944a7ef5
7
+ data.tar.gz: 6519cf7bd91a0c5d3cd2a02569a75de8fa0bbeae104c6d1020202b03a8c98d4835b81afcea1cdf308ea61923a20a950bff48e73d283466816e1b8f1e61115844
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /pkg
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Read dependencies from gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ peerstreet-client-pandawhisperer (0.1.0)
5
+ httparty (~> 0.14)
6
+ thor (~> 0.19)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.1)
12
+ public_suffix (~> 2.0, >= 2.0.2)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ hashdiff (0.3.4)
17
+ httparty (0.14.0)
18
+ multi_xml (>= 0.5.2)
19
+ multi_xml (0.6.0)
20
+ public_suffix (2.0.5)
21
+ rake (12.0.0)
22
+ rspec (3.5.0)
23
+ rspec-core (~> 3.5.0)
24
+ rspec-expectations (~> 3.5.0)
25
+ rspec-mocks (~> 3.5.0)
26
+ rspec-core (3.5.4)
27
+ rspec-support (~> 3.5.0)
28
+ rspec-expectations (3.5.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.5.0)
31
+ rspec-mocks (3.5.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-support (3.5.0)
35
+ safe_yaml (1.0.4)
36
+ thor (0.19.4)
37
+ webmock (3.0.1)
38
+ addressable (>= 2.3.6)
39
+ crack (>= 0.3.2)
40
+ hashdiff
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.14)
47
+ peerstreet-client-pandawhisperer!
48
+ rake (~> 12.0)
49
+ rspec (~> 3.5)
50
+ webmock (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.14.6
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # PeerStreet Coding Challenge
2
+
3
+ ## Client
4
+
5
+ ### Prerequisites
6
+
7
+ - Ruby 2.3+
8
+
9
+ ### Installation
10
+
11
+ ```
12
+ cd client
13
+ bundle install
14
+ ```
15
+
16
+ ### Usage
17
+
18
+ Run `bin/zip2msa <zip> [base url]`.
19
+
20
+ First argument is the ZIP code (mandatory).
21
+
22
+ Second argument is the API URL (optional, defaults to `http://peerstreet-cw.herokuapp.com`)
23
+
24
+ For example:
25
+ ```
26
+ bin/zip2msa 12345
27
+ ```
28
+
29
+ Should print:
30
+
31
+ ```
32
+
33
+ ZIP: 12345
34
+ CBSA: 10580
35
+ Name: Albany-Schenectady-Troy, NY
36
+ Pop. 2014 (est.): 880091
37
+ Pop. 2015 (est.): 881830
38
+
39
+ ```
40
+
41
+ ### Running tests
42
+
43
+ Simply run rspec:
44
+
45
+ ```
46
+ rspec
47
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'peerstreet/cli'
4
+
5
+ PeerStreet::CLI.start(ARGV)
data/client.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peerstreet/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "peerstreet-client-pandawhisperer"
8
+ spec.version = PeerStreet::Client::VERSION
9
+ spec.authors = ["Christoph Wagner"]
10
+ spec.email = ["github@pandawhisperer.net"]
11
+
12
+ spec.summary = %q{A CLI for the PeerStreet coding challenge}
13
+ spec.description = %q{
14
+ A simple REST API client for the PeerStreet coding challenge.
15
+ }
16
+ spec.homepage = "https://github.com/PeerStreet/coding-challenge-pandawhisperer/tree/master/client"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "bin"
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "httparty", "~> 0.14"
26
+ spec.add_dependency "thor", "~> 0.19"
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "rake", "~> 12.0"
29
+ spec.add_development_dependency "rspec", "~> 3.5"
30
+ spec.add_development_dependency "webmock", "~> 3.0"
31
+ end
data/lib/client.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'httparty'
2
+
3
+ class Client
4
+ include HTTParty
5
+
6
+ def initialize(base_url)
7
+ self.class.base_uri base_url
8
+ end
9
+
10
+ def msa(zip)
11
+ self.class.get('/msa', query: { zip: zip })
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ require 'peerstreet/client'
2
+ require 'thor'
3
+
4
+ module PeerStreet
5
+ DEFAULT_API_URL = 'http://peerstreet-cw.herokuapp.com'
6
+
7
+ class CLI < Thor
8
+ desc "zip2msa ZIP", "Finds the MSA for a given ZIP"
9
+ option :url
10
+ def zip2msa(zip)
11
+ url = options[:url] || DEFAULT_API_URL
12
+
13
+ begin
14
+ msa = PeerStreet::Client.new(url).msa(zip)
15
+ if msa.response.code == '404'
16
+ puts 'Not found'
17
+ else
18
+ output msa
19
+ end
20
+ rescue => ex
21
+ STDERR.puts ex.message
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def output(msa)
28
+ puts """
29
+ ZIP: #{msa['zip']}
30
+ CBSA: #{msa['cbsa']}
31
+ Name: #{msa['name']}
32
+ Pop. 2014 (est.): #{msa['popestimate2014']}
33
+ Pop. 2015 (est.): #{msa['popestimate2015']}
34
+ """
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module PeerStreet
2
+ class Client
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'peerstreet/client/version'
2
+ require 'httparty'
3
+
4
+ module PeerStreet
5
+ class Client
6
+ include HTTParty
7
+
8
+ def initialize(base_url)
9
+ self.class.base_uri base_url
10
+ end
11
+
12
+ def msa(zip)
13
+ self.class.get('/msa', query: { zip: zip })
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peerstreet-client-pandawhisperer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Wagner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.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.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: "\n A simple REST API client for the PeerStreet coding challenge.\n
98
+ \ "
99
+ email:
100
+ - github@pandawhisperer.net
101
+ executables:
102
+ - peerstreet-client
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - bin/peerstreet-client
113
+ - client.gemspec
114
+ - lib/client.rb
115
+ - lib/peerstreet/cli.rb
116
+ - lib/peerstreet/client.rb
117
+ - lib/peerstreet/client/version.rb
118
+ homepage: https://github.com/PeerStreet/coding-challenge-pandawhisperer/tree/master/client
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: A CLI for the PeerStreet coding challenge
141
+ test_files: []