smartystreets_api 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTk5YTNiMGExYzA2NDNkYjU0MzlmMjJjNjdhZmE2YzYyYWM3MDQ1Yg==
5
+ data.tar.gz: !binary |-
6
+ NmQ4N2EwN2Y2OWRkMmFmZjA1NjYxYmZlYWI0NmEzNDJjMDMxNGMzOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OThkOTNiZGI5OTRmNWM5MGNjOGVjNTE3YzNlZDJkNmFkNzE3NjQzZGZkYTcz
10
+ YzE1YzI5OTJjNzNkYzEwNjE5NWUyNTllODZmZDE1YTM2OTMxYWI1ZWZhY2Y4
11
+ YjM3NDhjZTIzMGVhMmViOTllZjAyM2IyY2QyYmY2MDk5NzNjN2Q=
12
+ data.tar.gz: !binary |-
13
+ ZTBiMGE1ODAxZWVkYjI0ZGYwN2ZhYzJhYTFkMjkwYTljZDI4YWIxMWZkMmYy
14
+ NGNlMjI2OWVmMDFjZmM3NTJhZGE1Y2IxOTRiNDgyMzE5OTExZGZkN2I5NDAz
15
+ ZjRmZDg1YmZiNWIxMTAyOWUxOTY2ZDgwMGNhMzkwYWUyZWUyNmM=
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/credentials.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at lorrain.florian@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smartystreets_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 florrain
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # SmartyStreetsApi [![Build Status](https://travis-ci.org/florrain/smartystreets_api.svg?branch=master)](https://travis-ci.org/florrain/smartystreets_api)
2
+
3
+ Ruby client for smartystreets.com APIs. So far only the single US street address API has been implemented.
4
+
5
+ PRs are welcome!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'smartystreets_api'
13
+ ```
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install smartystreets_api
18
+
19
+ ## Usage
20
+ Configure the GEM first:
21
+ ```ruby
22
+ # config/initializers/smartystreets_api.rb
23
+ SmartyStreetsApi.configure do |config|
24
+ config.auth_id = "AUTH-ID"
25
+ config.auth_token = "AUTH-TOKEN"
26
+ end
27
+ ```
28
+
29
+ Then try to validate an address:
30
+ ```ruby
31
+ address_args = {
32
+ street: "114 Sansome Street",
33
+ secondary: "Floor 5",
34
+ city: "San Francisco",
35
+ state: "CA",
36
+ zipcode: "94104"
37
+ }
38
+
39
+ response = SmartyStreetsApi::UsStreetAddress.get_single(address_args)
40
+
41
+ #response
42
+ [
43
+ {
44
+ lines: {
45
+ delivery_line_1: "114 Sansome St Fl 5",
46
+ last_line: "San Francisco CA 94104-3812"
47
+ },
48
+ indexes: {
49
+ input_index: 0,
50
+ candidate_index: 0,
51
+ delivery_point_barcode: "941043812053"
52
+ },
53
+ components: {
54
+ primary_number: "114",
55
+ street_name: "Sansome",
56
+ street_suffix: "St",
57
+ secondary_number: "5",
58
+ secondary_designator: "Fl",
59
+ city_name: "San Francisco",
60
+ state_abbreviation: "CA",
61
+ zipcode: "94104",
62
+ plus4_code: "3812",
63
+ delivery_point: "05",
64
+ delivery_point_check_digit: "3"
65
+ },
66
+ metadata: {
67
+ record_type: "H",
68
+ zip_type: "Standard",
69
+ county_fips: "06075",
70
+ county_name: "San Francisco",
71
+ carrier_route: "C015",
72
+ congressional_district: "12",
73
+ rdi: "Commercial",
74
+ elot_sequence: "0163",
75
+ elot_sort: "A",
76
+ latitude: 37.79133,
77
+ longitude: -122.40068,
78
+ precision: "Zip9",
79
+ time_zone: "Pacific",
80
+ utc_offset: -8,
81
+ dst: true
82
+ },
83
+ analysis: {
84
+ dpv_match_code: "Y",
85
+ dpv_footnotes: "AABB",
86
+ dpv_cmra: "N",
87
+ dpv_vacant: "N",
88
+ active: "N",
89
+ footnotes: "N#"
90
+ }
91
+ }]
92
+ ```
93
+
94
+ A decorator can reformat the address based on the components. Please make sure the format fits your need!!
95
+
96
+ ```ruby
97
+ response = SmartyStreetsApi::UsStreetAddress.get_single(office)
98
+
99
+ decorated_address = SmartyStreetsApi::Decorators::UsFormat.new.call(response.first)
100
+
101
+ # decorated_address
102
+ {
103
+ street: "114 Sansome St",
104
+ secondary: "Fl 5",
105
+ city: "San Francisco",
106
+ state: "CA",
107
+ zipcode: "94104",
108
+ plus4_code: "3812"
109
+ }
110
+ ```
111
+
112
+ ## Development
113
+
114
+ After checking out the repo, run `bundle` to install dependencies. Then copy/paste `spec/credentials.sample.yml` to `spec/credentials.yml` and set your own credentials.
115
+ VCR is intended to hide them so no worries, as long as you don't commit hard-coded credentials in the code they won't be pushed in cassettes + you won't have to pay for the already passed tests.
116
+
117
+ Run `rake spec` to run the tests.
118
+
119
+ 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).
120
+
121
+ ## Contributing
122
+
123
+ Bug reports and pull requests are welcome on GitHub at https://github.com/florrain/smartystreets_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
124
+
125
+
126
+ ## License
127
+
128
+ 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,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,58 @@
1
+ class SmartyStreetsApi::Decorators::UsFormat
2
+ def call(address_object)
3
+ return if !address_object || !address_object[:components]
4
+
5
+ self.class.private_instance_methods(false).inject({}) do |decorated_address, attribute|
6
+ components = self.send(attribute.to_sym)
7
+
8
+ array_values = components.map do |component_name|
9
+ if address_object[:components] && address_object[:components][component_name]
10
+ address_object[:components][component_name]
11
+ else
12
+ nil
13
+ end
14
+ end.compact
15
+
16
+ decorated_address[attribute] = array_values.empty? ? nil : array_values.join(" ")
17
+
18
+ decorated_address
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def street
25
+ [
26
+ :primary_number,
27
+ :street_predirection,
28
+ :street_name,
29
+ :street_postdirection,
30
+ :street_suffix
31
+ ]
32
+ end
33
+
34
+ def secondary
35
+ [
36
+ :secondary_designator,
37
+ :secondary_number,
38
+ :extra_secondary_designator,
39
+ :extra_secondary_number
40
+ ]
41
+ end
42
+
43
+ def city
44
+ [:city_name]
45
+ end
46
+
47
+ def state
48
+ [:state_abbreviation]
49
+ end
50
+
51
+ def zipcode
52
+ [:zipcode]
53
+ end
54
+
55
+ def plus4_code
56
+ [:plus4_code]
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ module SmartyStreetsApi
2
+ module MonkeyPatches
3
+ module Hash
4
+
5
+ def symbolize_keys!
6
+ keys.each do |key|
7
+ self[key.to_sym] = delete(key)
8
+ end
9
+ self
10
+ end unless method_defined?(:symbolize_keys!)
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ Hash.send(:include, SmartyStreetsApi::MonkeyPatches::Hash)
@@ -0,0 +1,77 @@
1
+ class SmartyStreetsApi::UsStreetAddress
2
+ AUTH_ARGS = %w(auth-id auth-token)
3
+ INPUTS = %w(street street2 secondary city state zipcode lastline addressee urbanization candidates)
4
+ OUTPUT_ADDRESS_LINES = %w(addressee delivery_line_1 delivery_line_2 last_line)
5
+ OUTPUT_ADDRESS_INDEXES = %w(input_id input_index candidate_index delivery_point_barcode)
6
+
7
+ def self.get_single(options)
8
+ uri = URI("#{host}/street-address")
9
+
10
+ args = options.select { |name, value| INPUTS.include?(name.to_s) && (value && !value.empty?) }.merge!(auth_args)
11
+
12
+ uri.query = URI.encode_www_form(args)
13
+
14
+ response = Net::HTTP.get_response(uri)
15
+
16
+ parse(response)
17
+ end
18
+
19
+ private
20
+
21
+ def self.parse(response)
22
+ parsed_response = JSON.parse(response.body)
23
+
24
+ raise_error!(parsed_response) if severe_error?(response.code)
25
+
26
+ parse_response(parsed_response)
27
+ end
28
+
29
+ def self.parse_response(response)
30
+ response.map do |address|
31
+ {
32
+ lines: address_lines(address).symbolize_keys!,
33
+ indexes: address_indexes(address).symbolize_keys!,
34
+ components: address["components"].symbolize_keys!,
35
+ metadata: address["metadata"].symbolize_keys!,
36
+ analysis: address["analysis"].symbolize_keys!
37
+ }
38
+ end
39
+ end
40
+
41
+ def self.address_lines(address)
42
+ address.select { |field| OUTPUT_ADDRESS_LINES.include?(field) }.symbolize_keys!
43
+ end
44
+
45
+ def self.address_indexes(address)
46
+ address.select { |field| OUTPUT_ADDRESS_INDEXES.include?(field) }.symbolize_keys!
47
+ end
48
+
49
+ def self.severe_error?(response_status_code)
50
+ response_status_code.to_i != 200
51
+ end
52
+
53
+ def self.raise_error!(response_status_code)
54
+ case response_status_code
55
+ when 401
56
+ raise "SmartyStreets - Unauthorized"
57
+ when 402
58
+ raise "SmartyStreets - Payment Required"
59
+ when 413
60
+ raise "SmartyStreets - Request Entity Too Large"
61
+ when 400
62
+ raise "SmartyStreets - Bad Request (Malformed Payload)"
63
+ when 429
64
+ raise "SmartyStreets - Too Many Requests"
65
+ else
66
+ raise "SmartyStreets - Unknown error"
67
+ end
68
+ end
69
+
70
+ def self.host
71
+ SmartyStreetsApi.configuration.base_url
72
+ end
73
+
74
+ def self.auth_args
75
+ SmartyStreetsApi.configuration.auth_args
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module SmartyStreetsApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "smartystreets_api/version"
2
+
3
+ module SmartyStreetsApi
4
+ class << self
5
+ attr_accessor :config
6
+ end
7
+
8
+ def self.configuration
9
+ unless @config
10
+ configure
11
+ end
12
+
13
+ @config
14
+ end
15
+
16
+ def self.configure
17
+ self.config ||= Configuration.new
18
+ yield(config)
19
+ end
20
+
21
+ class Configuration
22
+ attr_accessor :auth_id, :auth_token, :base_url
23
+
24
+ def initialize
25
+ @auth_id = "AUTH-ID"
26
+ @auth_token = "AUTH-TOKEN"
27
+ @base_url = "https://api.smartystreets.com"
28
+ end
29
+
30
+ def auth_args
31
+ { "auth-id" => @auth_id, "auth-token" => @auth_token }
32
+ end
33
+ end
34
+
35
+ module Decorators
36
+ end
37
+ end
38
+
39
+ require "smartystreets_api/monkey_patches"
40
+ require "smartystreets_api/decorators/us_format"
41
+ require "smartystreets_api/us_street_address"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smartystreets_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smartystreets_api"
8
+ spec.version = SmartyStreetsApi::VERSION
9
+ spec.authors = ["florrain"]
10
+ spec.email = ["lorrain.florian@gmail.com"]
11
+
12
+ spec.summary = "Ruby API client for SmartyStreets"
13
+ spec.description = "A simple and dependency free API GEM for https://smartystreets.com/, the address verification API."
14
+ spec.homepage = "https://github.com/florrain/smartystreets_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "vcr", "~> 3.0.3"
24
+ spec.add_development_dependency "webmock", "~> 1.21.0"
25
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartystreets_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - florrain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.21.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.21.0
83
+ description: A simple and dependency free API GEM for https://smartystreets.com/,
84
+ the address verification API.
85
+ email:
86
+ - lorrain.florian@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/smartystreets_api.rb
100
+ - lib/smartystreets_api/decorators/us_format.rb
101
+ - lib/smartystreets_api/monkey_patches.rb
102
+ - lib/smartystreets_api/us_street_address.rb
103
+ - lib/smartystreets_api/version.rb
104
+ - smartystreets_api.gemspec
105
+ homepage: https://github.com/florrain/smartystreets_api
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.8
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby API client for SmartyStreets
129
+ test_files: []