zippopotamus 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +9 -0
- data/.github/workflows/ci.yml +21 -0
- data/Gemfile +5 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +22 -2
- data/Rakefile +9 -0
- data/lib/zippopotamus/place.rb +44 -0
- data/lib/zippopotamus/version.rb +1 -1
- data/lib/zippopotamus.rb +7 -1
- data/test/place_test.rb +52 -0
- data/test/test_helper.rb +10 -0
- data/test/zippopotamus_test.rb +47 -0
- data/zippopotamus.gemspec +17 -6
- metadata +60 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c36c6dc9aaaffbd7a9196979d2c359b7849bf88b2bcab247771be3a96fe2a91c
|
4
|
+
data.tar.gz: b33e8f3dcd49ba9c6ef2aebcb4ce6aada87e3320bc51e8a239265f8beebeca7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae9cd9f2448eaa612aaf62aa448a6533b330ad9d93ecf4d7ac714b8e6b89a476c0eb825e0b443e516e4618d56d22cdf4c3983750f8ea5003e72bea60acb984d
|
7
|
+
data.tar.gz: cf3da85cf3341aebe2e06be169658e4aaa610fc850891b5f6ba5fed4b1182087f01fde03e2c30dd7cd58abdf4d5282b6bcb360b77acaaf8a35a86f113a776082
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: [rmm5t]
|
4
|
+
# patreon: # Replace with a single Patreon username
|
5
|
+
# open_collective: # Replace with a single Open Collective username
|
6
|
+
# ko_fi: # Replace with a single Ko-fi username
|
7
|
+
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
custom: "https://www.paypal.me/rmm5t/5"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby: ["3.0", "3.1", "3.2", "3.3"]
|
10
|
+
|
11
|
+
steps:
|
12
|
+
# https://github.com/marketplace/actions/checkout
|
13
|
+
- uses: actions/checkout@v4
|
14
|
+
# https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
bundler-cache: true # runs `bundle install` and caches gems automatically
|
20
|
+
- name: Run tests
|
21
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
# Zippopotamus
|
1
|
+
# Zippopotamus
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/zippopotamus.svg)](https://rubygems.org/gems/zippopotamus)
|
4
|
+
[![Build Status](https://github.com/rmm5t/zippopotamus/workflows/CI/badge.svg)](https://github.com/rmm5t/zippopotamus/actions?query=workflow%3ACI)
|
5
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/zippopotamus.svg)](https://rubygems.org/gems/zippopotamus)
|
6
|
+
|
7
|
+
Ruby wrapper around the **[Zippopotam.us](http://zippopotam.us/)** API. **Zip Code Galore!** Postal Codes and Zip Codes made easy.
|
4
8
|
|
5
9
|
* Give it a postal code to get back the city, state, longitude, and latitude.
|
6
10
|
* Give it a city and state to get back a list of possible postal codes.
|
7
11
|
|
12
|
+
## DISCLAIMER: Not Ready Yet, But Some Day
|
13
|
+
|
14
|
+
I just started on this gem. It's not real yet. All
|
15
|
+
[Readme Driven Development](http://tom.preston-werner.com/2010/08/23/readme-driven-development.html)
|
16
|
+
so far.
|
17
|
+
|
8
18
|
## Installation
|
9
19
|
|
10
20
|
Add this line to your application's Gemfile:
|
@@ -41,6 +51,12 @@ place.post_code # => "90201"
|
|
41
51
|
place.longitude # => "-118.4065"
|
42
52
|
place.latitude # => "34.0901"
|
43
53
|
|
54
|
+
# Aliases also exist for code readability
|
55
|
+
place.name # => "Beverly Hills"
|
56
|
+
place.city # => "Beverly Hills"
|
57
|
+
place.postal_code # => "90201"
|
58
|
+
place.zip # => "90201"
|
59
|
+
|
44
60
|
# Also aliased as `by_zip`
|
45
61
|
places = Zippopotamus.by_zip("90210")
|
46
62
|
|
@@ -83,3 +99,7 @@ places[1].latitude # => "42.4128"
|
|
83
99
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
85
101
|
5. Create a new Pull Request
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
[MIT License](https://rmm5t.mit-license.org/)
|
data/Rakefile
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Zippopotamus
|
4
|
+
class Place
|
5
|
+
def initialize(values = {})
|
6
|
+
@values = values
|
7
|
+
add_readers(values.keys)
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
@values[key.to_s.downcase.gsub("_", " ")]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
JSON.pretty_generate(@values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"#<#{self.class}:0x#{self.object_id.to_s(16)}> JSON: " + to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
# def self.construct_from(api_body)
|
23
|
+
# end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
METHOD_ALIASES = {
|
28
|
+
place_name: [:name, :city],
|
29
|
+
post_code: [:postal_code, :zip],
|
30
|
+
}
|
31
|
+
|
32
|
+
def add_readers(keys)
|
33
|
+
singleton_class.instance_eval do
|
34
|
+
keys.each do |key|
|
35
|
+
define_method(key.to_s.downcase.gsub(" ", "_")) { @values[key] }
|
36
|
+
end
|
37
|
+
|
38
|
+
METHOD_ALIASES.each do |method, aliases|
|
39
|
+
aliases.each { |a| alias_method a, method } if method_defined?(method)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/zippopotamus/version.rb
CHANGED
data/lib/zippopotamus.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require "zippopotamus/version"
|
2
|
+
require "zippopotamus/place"
|
2
3
|
|
3
4
|
module Zippopotamus
|
4
|
-
|
5
|
+
def self.by_postal_code(postal_code, country = "us")
|
6
|
+
end
|
7
|
+
singleton_class.send(:alias_method, :by_zip, :by_postal_code)
|
8
|
+
|
9
|
+
def self.by_name(city, state, country = "us")
|
10
|
+
end
|
5
11
|
end
|
data/test/place_test.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PlaceTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@place = Zippopotamus::Place.new(
|
6
|
+
"longitude" => "-75.6398",
|
7
|
+
"latitude" => "40.0978",
|
8
|
+
"post code" => "19425",
|
9
|
+
"place name" => "Chester Springs",
|
10
|
+
"state" => "Pennsylvania",
|
11
|
+
"state abbreviation" => "PA",
|
12
|
+
"country" => "United States",
|
13
|
+
"country abbreviation" => "US",
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_mimic_a_read_only_hash
|
18
|
+
assert_equal "19425", @place["post code"]
|
19
|
+
assert_equal "Pennsylvania", @place["state"]
|
20
|
+
assert_nil @place["bogus"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_convert_keys_with_spaces_to_underscores
|
24
|
+
assert_equal "19425", @place["post_code"]
|
25
|
+
assert_equal "PA", @place["state_abbreviation"]
|
26
|
+
assert_nil @place["something_else"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_support_indifferent_access
|
30
|
+
assert_equal "19425", @place[:post_code]
|
31
|
+
assert_equal "PA", @place[:state_abbreviation]
|
32
|
+
assert_equal "US", @place[:country_abbreviation]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_support_method_syntax
|
36
|
+
assert_equal "19425", @place.post_code
|
37
|
+
assert_equal "PA", @place.state_abbreviation
|
38
|
+
assert_equal "Chester Springs", @place.place_name
|
39
|
+
assert_equal "-75.6398", @place.longitude
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_support_method_aliases
|
43
|
+
assert_equal "19425", @place.postal_code
|
44
|
+
assert_equal "19425", @place.zip
|
45
|
+
assert_equal "Chester Springs", @place.name
|
46
|
+
assert_equal "Chester Springs", @place.city
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_convert_a_full_zippopotamus_api_response_into_an_array_of_places
|
50
|
+
skip("Zippopotamus::Place.construct_from(api_response)")
|
51
|
+
end
|
52
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "webmock/minitest"
|
3
|
+
require "minitest/reporters"
|
4
|
+
if ENV["CI"] == "true"
|
5
|
+
Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new
|
6
|
+
else
|
7
|
+
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
|
8
|
+
end
|
9
|
+
|
10
|
+
require "zippopotamus"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ZippopotamusTest < Minitest::Test
|
4
|
+
def test_should_exist
|
5
|
+
assert Object.const_defined?(:Zippopotamus)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_respond_to_by_postal_code
|
9
|
+
assert Zippopotamus.respond_to?(:by_postal_code)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_by_postal_code_should_default_to_us
|
13
|
+
skip("Zippopotamus.by_postal_code('80027')")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_respond_to_by_zip
|
17
|
+
assert Zippopotamus.respond_to?(:by_zip)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_by_zip_should_alias_by_postal_code
|
21
|
+
skip("Zippopotamus.by_zip('80027')")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_by_postal_code_should_support_other_countries
|
25
|
+
skip("Zippopotamus.by_postal_code('4400', 'AU')")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_by_postal_code_should_raise_an_error_when_not_found
|
29
|
+
skip("Zippopotamus.by_zip('80027', 'CA')")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_respond_to_by_name
|
33
|
+
assert Zippopotamus.respond_to?(:by_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_by_name_should_default_to_us
|
37
|
+
skip("Zippopotamus.by_name('Leesburg', 'VA')")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_by_name_should_support_other_countries
|
41
|
+
skip("Zippopotamus.by_name('Sumburgh', 'SCT', 'GB')")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_by_name_should_raise_an_error_when_not_found
|
45
|
+
skip("Zippopotamus.by_name('Fake City', 'VA', 'US')")
|
46
|
+
end
|
47
|
+
end
|
data/zippopotamus.gemspec
CHANGED
@@ -4,13 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'zippopotamus/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
+
username = "rmm5t"
|
7
8
|
spec.name = "zippopotamus"
|
8
9
|
spec.version = Zippopotamus::VERSION
|
9
10
|
spec.authors = ["Ryan McGeary"]
|
10
11
|
spec.email = ["ryan@mcgeary.org"]
|
11
|
-
spec.summary = "Ruby wrapper
|
12
|
-
spec.description = "Lookup the city, state, longitude, and latitude for a given country and postal code, or lookup a list of possible postal codes for a given country, state, and city."
|
13
|
-
spec.homepage = "https://github.com
|
12
|
+
spec.summary = "Ruby wrapper for the Zippopotam.us API"
|
13
|
+
spec.description = "#{spec.summary}. Lookup the city, state, longitude, and latitude for a given country and postal code, or lookup a list of possible postal codes for a given country, state, and city."
|
14
|
+
spec.homepage = "https://github.com/#{username}/#{spec.name}"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,9 +19,19 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.
|
22
|
+
spec.metadata = {
|
23
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
24
|
+
"changelog_uri" => "#{spec.homepage}/releases",
|
25
|
+
"source_code_uri" => spec.homepage,
|
26
|
+
"funding_uri" => "https://github.com/sponsors/#{username}",
|
27
|
+
}
|
22
28
|
|
23
|
-
spec.
|
24
|
-
|
29
|
+
spec.add_runtime_dependency "rest-client", "~> 1.7"
|
30
|
+
|
31
|
+
spec.add_development_dependency "rake"
|
25
32
|
spec.add_development_dependency "minitest", "~> 5.5"
|
33
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.3", "> 1.3.1"
|
34
|
+
spec.add_development_dependency "webmock"
|
35
|
+
|
36
|
+
spec.required_ruby_version = ">= 1.9.3"
|
26
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zippopotamus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan McGeary
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,78 +16,109 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '5.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
56
|
+
name: minitest-reporters
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.3'
|
62
|
+
- - ">"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.1
|
62
65
|
type: :development
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - "~>"
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
version: '1.3'
|
72
|
+
- - ">"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.3.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: webmock
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: Ruby wrapper for the Zippopotam.us API. Lookup the city, state, longitude,
|
90
|
+
and latitude for a given country and postal code, or lookup a list of possible postal
|
91
|
+
codes for a given country, state, and city.
|
72
92
|
email:
|
73
93
|
- ryan@mcgeary.org
|
74
94
|
executables: []
|
75
95
|
extensions: []
|
76
96
|
extra_rdoc_files: []
|
77
97
|
files:
|
98
|
+
- ".github/FUNDING.yml"
|
99
|
+
- ".github/workflows/ci.yml"
|
78
100
|
- ".gitignore"
|
79
101
|
- Gemfile
|
102
|
+
- Guardfile
|
80
103
|
- LICENSE.txt
|
81
104
|
- README.md
|
82
105
|
- Rakefile
|
83
106
|
- lib/zippopotamus.rb
|
107
|
+
- lib/zippopotamus/place.rb
|
84
108
|
- lib/zippopotamus/version.rb
|
109
|
+
- test/place_test.rb
|
110
|
+
- test/test_helper.rb
|
111
|
+
- test/zippopotamus_test.rb
|
85
112
|
- zippopotamus.gemspec
|
86
113
|
homepage: https://github.com/rmm5t/zippopotamus
|
87
114
|
licenses:
|
88
115
|
- MIT
|
89
|
-
metadata:
|
90
|
-
|
116
|
+
metadata:
|
117
|
+
bug_tracker_uri: https://github.com/rmm5t/zippopotamus/issues
|
118
|
+
changelog_uri: https://github.com/rmm5t/zippopotamus/releases
|
119
|
+
source_code_uri: https://github.com/rmm5t/zippopotamus
|
120
|
+
funding_uri: https://github.com/sponsors/rmm5t
|
121
|
+
post_install_message:
|
91
122
|
rdoc_options: []
|
92
123
|
require_paths:
|
93
124
|
- lib
|
@@ -95,16 +126,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
126
|
requirements:
|
96
127
|
- - ">="
|
97
128
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
129
|
+
version: 1.9.3
|
99
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
131
|
requirements:
|
101
132
|
- - ">="
|
102
133
|
- !ruby/object:Gem::Version
|
103
134
|
version: '0'
|
104
135
|
requirements: []
|
105
|
-
|
106
|
-
|
107
|
-
signing_key:
|
136
|
+
rubygems_version: 3.5.23
|
137
|
+
signing_key:
|
108
138
|
specification_version: 4
|
109
|
-
summary: Ruby wrapper
|
110
|
-
test_files:
|
139
|
+
summary: Ruby wrapper for the Zippopotam.us API
|
140
|
+
test_files:
|
141
|
+
- test/place_test.rb
|
142
|
+
- test/test_helper.rb
|
143
|
+
- test/zippopotamus_test.rb
|