address_verifier 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/address_verifier.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/address_verifier.rb +59 -0
- data/lib/address_verifier/version.rb +3 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f28fd5efe072ff551bec3d566d9f93694feca60
|
4
|
+
data.tar.gz: e725a69dfcf5bb667ea5c71a260aabccce009a69
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 004076b0ebc425c9a3678a00fe649bbc75e53fccd94048ee85dc294a63433f2e3c4217d4dbb0a3e5c3ea4b46a6c7bfc915d0dbb8373140b5c340c7d92a9f76f7
|
7
|
+
data.tar.gz: aef56d8b557a5e86d4eda00324302aacba4bce99e7e5c2358b0f5cb92700bb4f83746acbfdb8b52e491a79c5ece67371483242fab39450f544a7442caa155742
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# AddressVerifier
|
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/address_verifier`. 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 'address_verifier'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install address_verifier
|
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. Then, run `rake spec` to run the tests. 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/[USERNAME]/address_verifier.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'address_verifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'address_verifier'
|
8
|
+
spec.version = AddressVerifier::VERSION
|
9
|
+
spec.authors = ['Matthew Jesuele']
|
10
|
+
spec.email = ['matt@yoshirt.com']
|
11
|
+
|
12
|
+
spec.summary = 'AddressVerifier'
|
13
|
+
spec.description = 'Uses USPS Web Tools and Google Maps APIs to validate and get suggestions for addresses'
|
14
|
+
spec.homepage = 'http://yoshirt.com'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'httparty', '~> 0'
|
22
|
+
spec.add_runtime_dependency 'queryparams', '~> 0'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "address_verifier"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'queryparams'
|
3
|
+
|
4
|
+
class AddressVerifier
|
5
|
+
attr_accessor :usps_user_id
|
6
|
+
attr_accessor :google_api_key
|
7
|
+
|
8
|
+
def initialize(usps_user_id = nil, google_api_key = nil)
|
9
|
+
@usps_user_id = usps_user_id
|
10
|
+
@google_api_key = google_api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_suggestions(address)
|
14
|
+
HTTParty.get(suggestions_url(address))['results'].map do |r|
|
15
|
+
r['formatted_address']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def usps_verification(address)
|
20
|
+
HTTParty.get(usps_verification_url(usps_verification_xml(address)))
|
21
|
+
end
|
22
|
+
|
23
|
+
def verified?(address)
|
24
|
+
res = usps_verification(address)['AddressValidateResponse']['Address']
|
25
|
+
res['ReturnText'].nil? && res['Error'].nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def suggestions_url(address)
|
31
|
+
params = QueryParams.encode(
|
32
|
+
address: address,
|
33
|
+
key: @google_api_key
|
34
|
+
)
|
35
|
+
"https://maps.googleapis.com/maps/api/geocode/json?#{params}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def usps_verification_xml(address)
|
39
|
+
"
|
40
|
+
<AddressValidateRequest USERID='#{@usps_user_id}'>
|
41
|
+
<IncludeOptionalElements>true</IncludeOptionalElements>
|
42
|
+
<ReturnCarrierRoute>true</ReturnCarrierRoute>
|
43
|
+
<Address ID=\"0\">
|
44
|
+
<FirmName />
|
45
|
+
<Address1>#{address[:address1]}</Address1>
|
46
|
+
<Address2>#{address[:address2]}</Address2>
|
47
|
+
<City>#{address[:city]}</City>
|
48
|
+
<State>#{address[:state]}</State>
|
49
|
+
<Zip5>#{address[:zip5]}</Zip5>
|
50
|
+
<Zip4>#{address[:zip4]}</Zip4>
|
51
|
+
</Address>
|
52
|
+
</AddressValidateRequest>
|
53
|
+
"
|
54
|
+
end
|
55
|
+
|
56
|
+
def usps_verification_url(xml)
|
57
|
+
"http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=#{xml}"
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: address_verifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Jesuele
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-01 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: queryparams
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.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.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Uses USPS Web Tools and Google Maps APIs to validate and get suggestions
|
84
|
+
for addresses
|
85
|
+
email:
|
86
|
+
- matt@yoshirt.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- address_verifier.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/address_verifier.rb
|
101
|
+
- lib/address_verifier/version.rb
|
102
|
+
homepage: http://yoshirt.com
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: AddressVerifier
|
125
|
+
test_files: []
|