usps-proxy 0.0.1

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: 78f73a0f353f4c4e347b9faad52ee5278c1f2831
4
+ data.tar.gz: 95c73e8af6d4e161b1c5dfe84f8b366481aba4ca
5
+ SHA512:
6
+ metadata.gz: 2196068af5b5c2c1a4e069331ccfe75b95a38c5cab738df01a710bd4747e797e8fccb0199ed5be4d3074c69562b7c99d2e03caa24447f2b640af0be1b9bd963e
7
+ data.tar.gz: 16068e817a742ed02390484ed6f62a5907a4b578152d63782baf004a45ef06b5e7499517c598accfc032495f6e13c6656deedefbaca7eaf0b8a90629c8cb9d04
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ USPS_USER="your api key"
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ .env
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,15 @@
1
+ ## Welcome!
2
+
3
+ We're so glad you're thinking about contributing to an 18F open source project! If you're unsure or afraid of anything, just ask or submit the issue or pull request anyways. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contribution, and don't want a wall of rules to get in the way of that.
4
+
5
+ Before contributing, we encourage you to read our CONTRIBUTING policy (you are here), our LICENSE, and our README, all of which should be in this repository. If you have any questions, or want to read more about our underlying policies, you can consult the 18F Open Source Policy GitHub repository at https://github.com/18f/open-source-policy, or just shoot us an email/official government letterhead note to [18f@gsa.gov](mailto:18f@gsa.gov).
6
+
7
+ ## Public domain
8
+
9
+ This project is in the public domain within the United States, and
10
+ copyright and related rights in the work worldwide are waived through
11
+ the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
12
+
13
+ All contributions to this project will be released under the CC0
14
+ dedication. By submitting a pull request, you are agreeing to comply
15
+ with this waiver of copyright interest.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ usps-proxy (0.0.1)
5
+ dotenv
6
+ sinatra
7
+ thin
8
+ usps (~> 0.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ builder (3.2.2)
14
+ coderay (1.1.0)
15
+ daemons (1.1.9)
16
+ dotenv (1.0.2)
17
+ ethon (0.7.1)
18
+ ffi (>= 1.3.0)
19
+ eventmachine (1.0.3)
20
+ ffi (1.9.6)
21
+ method_source (0.8.2)
22
+ mini_portile (0.6.1)
23
+ nokogiri (1.6.5)
24
+ mini_portile (~> 0.6.0)
25
+ pry (0.10.1)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.8.1)
28
+ slop (~> 3.4)
29
+ rack (1.5.2)
30
+ rack-protection (1.5.3)
31
+ rack
32
+ rake (10.4.2)
33
+ sinatra (1.4.5)
34
+ rack (~> 1.4)
35
+ rack-protection (~> 1.4)
36
+ tilt (~> 1.3, >= 1.3.4)
37
+ slop (3.6.0)
38
+ thin (1.6.3)
39
+ daemons (~> 1.0, >= 1.0.9)
40
+ eventmachine (~> 1.0)
41
+ rack (~> 1.0)
42
+ tilt (1.4.1)
43
+ typhoeus (0.6.9)
44
+ ethon (>= 0.7.1)
45
+ usps (0.1.3)
46
+ builder (>= 2.1.2)
47
+ nokogiri (>= 1.4.1)
48
+ typhoeus (>= 0.1.18)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ pry
55
+ rake (~> 10.0)
56
+ usps-proxy!
data/LICENSE.md ADDED
@@ -0,0 +1,31 @@
1
+ As a work of the United States Government, this project is in the
2
+ public domain within the United States.
3
+
4
+ Additionally, we waive copyright and related rights in the work
5
+ worldwide through the CC0 1.0 Universal public domain dedication.
6
+
7
+ ## CC0 1.0 Universal Summary
8
+
9
+ This is a human-readable summary of the [Legal Code (read the full text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode).
10
+
11
+ ### No Copyright
12
+
13
+ The person who associated a work with this deed has dedicated the work to
14
+ the public domain by waiving all of his or her rights to the work worldwide
15
+ under copyright law, including all related and neighboring rights, to the
16
+ extent allowed by law.
17
+
18
+ You can copy, modify, distribute and perform the work, even for commercial
19
+ purposes, all without asking permission.
20
+
21
+ ### Other Information
22
+
23
+ In no way are the patent or trademark rights of any person affected by CC0,
24
+ nor are the rights that other persons may have in the work or in how the
25
+ work is used, such as publicity or privacy rights.
26
+
27
+ Unless expressly stated otherwise, the person who associated a work with
28
+ this deed makes no warranties about the work, and disclaims liability for
29
+ all uses of the work, to the fullest extent permitted by applicable law.
30
+ When using or citing the work, you should not imply endorsement by the
31
+ author or the affirmer.
data/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # usps-proxy
2
+
3
+ A Sinatra server that makes the USPS API a tad easier to consume on the client-side.
4
+
5
+ This gem sits alongside the namespace created by the [`USPS` gem](https://github.com/gaffneyc/usps).
6
+
7
+ ## Why?
8
+
9
+ - The USPS API is XML-based. This gem makes it JSON-accessible.
10
+ - Keep API keys completely secret
11
+ - Monitor and throttle client-side requests to USPS's servers (tbd)
12
+
13
+ ## What is supported?
14
+
15
+ This is still a work-in-progress, but there is basic support for:
16
+
17
+ - city/state lookup
18
+ - address standardization/verification
19
+
20
+ ## Usage
21
+
22
+ ### As part of a Rails app
23
+
24
+ In `Gemfile`:
25
+
26
+ ```ruby
27
+ gem 'usps-proxy', github: '18F/usps-proxy', branch: 'master'
28
+ ```
29
+
30
+ By default, `USPS::Proxy` will look for the `USPS_USER` environment variable. However, you can override this in `config/initializers/[production|development|test].rb`:
31
+
32
+ ```ruby
33
+ USPS.username = 'your usps username'
34
+ ```
35
+
36
+ (note that this is a method on the [`USPS` gem](https://github.com/gaffneyc/usps) and not this gem)
37
+
38
+ USPS offers several APIs. You likely won't need to use all of them. Because of that, `USPS::Proxy` allows you to mix and match them:
39
+
40
+ In `config/routes.rb`:
41
+
42
+ ```ruby
43
+ scope '/usps' do
44
+ mount USPS::Proxy::CityState, at: '/city_state'
45
+ mount USPS::Proxy::AddressStandardization, at: '/address_standardixation'
46
+ end
47
+ ```
48
+
49
+ Each API is its own mini `Sinatra` application with a single route, `'/'`.
50
+
51
+ ### Standalone
52
+
53
+ Clone this repo and `cd` into it.
54
+
55
+ Edit `config.ru` as needed. Also be sure your `USPS_USER` environment variable is set (or user the `USPS.username` *somewhere* before the app runs).
56
+
57
+ ```ruby
58
+ require './lib/usps-proxy'
59
+
60
+ run Rack::URLMap.new(
61
+ '/city_state' => USPS::Proxy::CityState,
62
+ '/address_standardization' => USPS::Proxy::AddressStandardization
63
+ )
64
+ ```
65
+
66
+ ```
67
+ $ bundle
68
+ $ bundle exec thin start
69
+ ```
70
+
71
+ ### APIs
72
+
73
+ #### City/State Lookup
74
+
75
+ GET `/city_state`
76
+
77
+ Request params (in the query string):
78
+
79
+ - `zip5` *required*
80
+
81
+ Example path: `/city_state?zip5=20006`
82
+
83
+ Example response:
84
+
85
+ ```javascript
86
+ {
87
+ "results": {
88
+ "20008": {
89
+ "zip": 20008,
90
+ "city": "WASHINGTON",
91
+ "state": "DC"
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ #### Address Standardization/Verification
98
+
99
+ GET `/address_standardization`
100
+
101
+ Request params (in the query string):
102
+
103
+ - `firm`
104
+ - `address1` *required*
105
+ - `address2`
106
+ - `city` *required*
107
+ - `state` *required*
108
+ - `zip5` *required*
109
+ - `zip4`
110
+
111
+ Example path: `/address_standardization?address1=1800%20F%20street%20NW&city=washington&state=DC&zip5=20006`
112
+
113
+ Example response:
114
+
115
+ ```javascript
116
+ {
117
+ "results": [
118
+ {
119
+ "name": null,
120
+ "company": "",
121
+ "address1": "1901 F ST NW",
122
+ "address2": "",
123
+ "city": "WASHINGTON",
124
+ "state": "DC",
125
+ "zip5": "20006",
126
+ "zip4": "",
127
+ "return_text": ""
128
+ }
129
+ ]
130
+ }
131
+ ```
132
+
133
+ ```javascript
134
+ {
135
+ "results": [
136
+ {
137
+ "name": null,
138
+ "company": "",
139
+ "address1": "1801 F ST NW",
140
+ "address2": "",
141
+ "city": "WASHINGTON",
142
+ "state": "DC",
143
+ "zip5": "20006",
144
+ "zip4": "4406",
145
+ "return_text": "Default address: The address you entered was found but more information is needed (such as an apartment, suite, or box number) to match to a specific address."
146
+ }
147
+ ]
148
+ }
149
+ ```
150
+
151
+ ## Public domain
152
+
153
+ This project is in the public domain within the United States, and
154
+ copyright and related rights in the work worldwide are waived through
155
+ the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
156
+
157
+ All contributions to this project will be released under the CC0
158
+ dedication. By submitting a pull request, you are agreeing to comply
159
+ with this waiver of copyright interest.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ require './lib/usps-proxy'
2
+
3
+ run Rack::URLMap.new(
4
+ '/city_state' => USPS::Proxy::CityState,
5
+ '/address_standardization' => USPS::Proxy::AddressStandardization
6
+ )
data/lib/usps-proxy.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'usps-proxy/version'
2
+ require 'usps-proxy/protocol'
3
+ require 'usps-proxy/city_state'
4
+ require 'usps-proxy/address_standardization'
5
+
6
+ require 'bundler/setup'
7
+ require 'sinatra/base'
8
+
9
+ require 'usps'
10
+ require 'dotenv'
11
+ require 'pry'
12
+ require 'json'
13
+ Dotenv.load
14
+
15
+ module USPS
16
+ module Proxy
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'pry'
4
+
5
+ module USPS
6
+ module Proxy
7
+ class AddressStandardization < Sinatra::Base
8
+ get '/' do
9
+ content_type :json
10
+
11
+ address = USPS::Address.new(params)
12
+ request = USPS::Request::AddressStandardization.new(address)
13
+
14
+ begin
15
+ response = request.send!
16
+ {
17
+ results: response.to_h.values
18
+ }.to_json
19
+ rescue USPS::Error => error
20
+ {
21
+ error: error.message,
22
+ code: error.number
23
+ }.to_json
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'pry'
4
+ require 'json'
5
+
6
+ module USPS
7
+ module Proxy
8
+
9
+ class CityState < Sinatra::Base
10
+ get '/' do
11
+ content_type :json
12
+
13
+ request = USPS::Request::CityAndStateLookup.new(params[:zip5])
14
+
15
+ begin
16
+ response = request.send!
17
+
18
+ {
19
+ results: response.to_h
20
+ }.to_json
21
+ rescue USPS::Error => error
22
+ {
23
+ error: error.message,
24
+ code: error.number
25
+ }.to_json
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ module USPS
2
+ module Proxy
3
+ module Protocol
4
+
5
+ CITY_STATE_PARAMS = [
6
+ {
7
+ name: :zip5,
8
+ required: true
9
+ }
10
+ ]
11
+
12
+ ADDRESS_STANDARDIZATION_PARAMS = [
13
+ {
14
+ name: :firm,
15
+ required: false
16
+ },
17
+ {
18
+ name: :address1,
19
+ required: true
20
+ },
21
+ {
22
+ name: :address2,
23
+ required: false
24
+ },
25
+ {
26
+ name: :city,
27
+ required: true
28
+ },
29
+ {
30
+ name: :state,
31
+ required: true
32
+ },
33
+ {
34
+ name: :zip5,
35
+ required: true
36
+ },
37
+ {
38
+ name: :zip4,
39
+ required: false
40
+ }
41
+ ]
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module UspsProxy
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'usps-proxy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "usps-proxy"
8
+ spec.version = UspsProxy::VERSION
9
+ spec.authors = ["Alan deLevie"]
10
+ spec.email = ["alan.delevie@gsa.gov"]
11
+ spec.summary = %q{Some space between the USPS API and your users}
12
+ spec.description = %q{Makes the USPS API a bit easier to consumer on the client-side.}
13
+ spec.homepage = ""
14
+ spec.license = "Public Domain. See LICENSE.md"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "pry"
23
+
24
+ spec.add_dependency "dotenv"
25
+ spec.add_dependency "sinatra"
26
+ spec.add_dependency "usps", "~>0.1"
27
+ spec.add_dependency "thin"
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usps-proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alan deLevie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: usps
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thin
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Makes the USPS API a bit easier to consumer on the client-side.
98
+ email:
99
+ - alan.delevie@gsa.gov
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".env.example"
105
+ - ".gitignore"
106
+ - ".ruby-version"
107
+ - CONTRIBUTING.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.md
111
+ - README.md
112
+ - Rakefile
113
+ - config.ru
114
+ - lib/usps-proxy.rb
115
+ - lib/usps-proxy/address_standardization.rb
116
+ - lib/usps-proxy/city_state.rb
117
+ - lib/usps-proxy/protocol.rb
118
+ - lib/usps-proxy/version.rb
119
+ - usps-proxy.gemspec
120
+ homepage: ''
121
+ licenses:
122
+ - Public Domain. See LICENSE.md
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.2.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Some space between the USPS API and your users
144
+ test_files: []