addressfinder 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/addressfinder.gemspec +17 -0
- data/lib/addressfinder.rb +26 -0
- data/lib/addressfinder/cleanse.rb +73 -0
- data/lib/addressfinder/configuration.rb +20 -0
- data/lib/addressfinder/errors.rb +13 -0
- data/lib/addressfinder/version.rb +3 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c39a2c437c55eca8db36e66ae69a229a3ca953ea
|
4
|
+
data.tar.gz: 895b3bd4ec4ceeea78a8e974ba84767aff30f76e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b38cef13fc5014066701d73e85a8e0a96853e996ede39ef215dabe4a4a9bad09cf5a58f2e445aaf369cdc86730ab9e34731deb34160650a4dc0f694f03d7d0d
|
7
|
+
data.tar.gz: 95a9e4d8b7cd31628218bc88138f8d30ea2faf7ee997d7de636a2d369efd25e197e6eee46bfa02df5062aafae670adbf16dc18e0c25556c37382aa55037bc68d
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Abletech
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# AddressFinder Ruby Gem
|
2
|
+
|
3
|
+
A client library for accessing the AddressFinder APIs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'addressfinder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install addressfinder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Configuration
|
22
|
+
|
23
|
+
You should call the configure block on startup of your app. In a Ruby on Rails application this
|
24
|
+
is normally performed in an initializer file. For example `./config/initializers/addressfinder.rb`
|
25
|
+
|
26
|
+
AddressFinder.configure do |af|
|
27
|
+
# Mandatory configuration
|
28
|
+
af.api_key = 'XXXXXXXXXX'
|
29
|
+
af.api_secret = 'YYYYYYYYYY'
|
30
|
+
af.default_country = 'nz'
|
31
|
+
|
32
|
+
# Optional configuration
|
33
|
+
af.timeout = 10 # seconds
|
34
|
+
af.proxy_host = 'corp.proxy.com'
|
35
|
+
af.proxy_port = 8080
|
36
|
+
af.proxy_user = 'username'
|
37
|
+
af.proxy_password = 'password'
|
38
|
+
end
|
39
|
+
|
40
|
+
### Address Cleansing
|
41
|
+
|
42
|
+
See the documentation on the available parameters and expected response here:
|
43
|
+
|
44
|
+
https://addressfinder.nz/docs/address_cleanse_api/
|
45
|
+
|
46
|
+
Usage example:
|
47
|
+
|
48
|
+
result = AddressFinder.cleanse(q: '186 Willis St, Wellington')
|
49
|
+
|
50
|
+
if result
|
51
|
+
$stdout.puts "Found: #{result.postal}"
|
52
|
+
else
|
53
|
+
$stdout.puts "Sorry, can't find that address"
|
54
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/addressfinder/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "addressfinder"
|
6
|
+
gem.version = AddressFinder::VERSION
|
7
|
+
gem.authors = ["Nigel Ramsay"]
|
8
|
+
gem.email = ["nigel@abletech.nz"]
|
9
|
+
gem.description = %q{Ruby client library for AddressFinder}
|
10
|
+
gem.summary = %q{Provides easy access to AddressFinder APIs}
|
11
|
+
gem.homepage = "https://github.com/AbleTech/addressfinder-ruby"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'addressfinder/version'
|
2
|
+
require 'addressfinder/configuration'
|
3
|
+
require 'addressfinder/cleanse'
|
4
|
+
require 'addressfinder/errors'
|
5
|
+
|
6
|
+
module AddressFinder
|
7
|
+
class << self
|
8
|
+
def configure(config_hash=nil)
|
9
|
+
if config_hash
|
10
|
+
config_hash.each do |k,v|
|
11
|
+
configuration.send("#{k}=", v) rescue nil if configuration.respond_to?("#{k}=")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
yield(configuration) if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= AddressFinder::Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def cleanse(*args)
|
23
|
+
AddressFinder::Cleanse.new(*args).perform
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module AddressFinder
|
2
|
+
class Cleanse
|
3
|
+
def initialize(q:, country: nil, delivered: nil, post_box: nil, rural: nil, region_code: nil)
|
4
|
+
@params = {}
|
5
|
+
@params['q'] = q
|
6
|
+
@params['delivered'] = delivered if delivered
|
7
|
+
@params['post_box'] = post_box if post_box
|
8
|
+
@params['rural'] = rural if rural
|
9
|
+
@params['region_code'] = region_code if region_code
|
10
|
+
@params['format'] = 'json'
|
11
|
+
@params['key'] = config.api_key
|
12
|
+
@params['secret'] = config.api_secret
|
13
|
+
@country = country || config.default_country
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
build_request
|
18
|
+
execute_request
|
19
|
+
build_result
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :full_url, :params, :response_body, :response_status, :result, :country
|
25
|
+
|
26
|
+
def build_request
|
27
|
+
@full_url = "https://#{config.hostname}:#{config.port}/api/#{country}/address/cleanse?#{encoded_params}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_request
|
31
|
+
uri = URI.parse(full_url)
|
32
|
+
http = Net::HTTP.new(uri.host, uri.port, config.proxy_host, config.proxy_port, config.proxy_user, config.proxy_password)
|
33
|
+
http.open_timeout = config.timeout
|
34
|
+
http.read_timeout = config.timeout
|
35
|
+
http.use_ssl = (uri.scheme == "https")
|
36
|
+
|
37
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
38
|
+
|
39
|
+
response = http.request(request)
|
40
|
+
|
41
|
+
@response_body = response.body
|
42
|
+
@response_status = response.code
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_result
|
46
|
+
if response_status != '200'
|
47
|
+
raise AddressFinder::RequestRejectedError.new(@response_status, @response_body)
|
48
|
+
end
|
49
|
+
|
50
|
+
if response_hash['matched']
|
51
|
+
return Result.new(response_hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def encoded_params
|
58
|
+
query = params.map{|k,v| "#{k}=#{v}"}.join('&')
|
59
|
+
URI::encode(query)
|
60
|
+
end
|
61
|
+
|
62
|
+
def response_hash
|
63
|
+
@_response_hash ||= JSON.parse(response_body)
|
64
|
+
end
|
65
|
+
|
66
|
+
def config
|
67
|
+
@_config ||= AddressFinder.configuration
|
68
|
+
end
|
69
|
+
|
70
|
+
class Result < OpenStruct
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AddressFinder
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_key
|
4
|
+
attr_accessor :api_secret
|
5
|
+
attr_accessor :hostname
|
6
|
+
attr_accessor :port
|
7
|
+
attr_accessor :proxy_host
|
8
|
+
attr_accessor :proxy_port
|
9
|
+
attr_accessor :proxy_user
|
10
|
+
attr_accessor :proxy_password
|
11
|
+
attr_accessor :timeout
|
12
|
+
attr_accessor :default_country
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.hostname = 'api.addressfinder.io'
|
16
|
+
self.port = 443
|
17
|
+
self.timeout = 10
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: addressfinder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nigel Ramsay
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby client library for AddressFinder
|
14
|
+
email:
|
15
|
+
- nigel@abletech.nz
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- addressfinder.gemspec
|
26
|
+
- lib/addressfinder.rb
|
27
|
+
- lib/addressfinder/cleanse.rb
|
28
|
+
- lib/addressfinder/configuration.rb
|
29
|
+
- lib/addressfinder/errors.rb
|
30
|
+
- lib/addressfinder/version.rb
|
31
|
+
homepage: https://github.com/AbleTech/addressfinder-ruby
|
32
|
+
licenses: []
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.4.6
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Provides easy access to AddressFinder APIs
|
54
|
+
test_files: []
|