postcodeapi 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/CHANGELOG.txt +12 -0
- data/CODE_OF_CONDUCT.md +22 -0
- data/README.md +59 -5
- data/lib/postcodeapi/api.rb +42 -10
- data/lib/postcodeapi/version.rb +1 -1
- data/postcodeapi.gemspec +4 -4
- data/spec/postcodeapi/api_spec.rb +59 -35
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d9305b21a4a58981374007ece910c95a7745438
|
4
|
+
data.tar.gz: 0a0f19fc7c6169503fcc94bfe3c4a7f9143ce488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5305cf890fd8c6b5c51c054ccb0a7e896748847a6fa37686278e7b36ab60735ca9081cd02041c23138626de9ef976996d70abbc2d2d42ff5577835142dd4d1f
|
7
|
+
data.tar.gz: 976d41b69eff97e5956b670ab64a43c6e3167af9f9d4a45111d9ae36a70e3ad7d91eb1e1d1b02fa62e899a18c6e9b2554bdad892a907f0c5f5ea0f2aab4633c0
|
data/.travis.yml
CHANGED
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# 2.0.0 - 2016-01-27
|
2
|
+
|
3
|
+
* Migrate to PostcodeAPI v2, see http://www.postcodeapi.nu for details.
|
4
|
+
|
5
|
+
# 1.1.0 - 2015-05-18
|
6
|
+
|
7
|
+
* Normalize input before calling API
|
8
|
+
|
9
|
+
# 1.0.0 - 2014-01-29
|
10
|
+
|
11
|
+
* Allow hashie version flexibility
|
12
|
+
|
1
13
|
# 0.0.2 - 2013-03-14
|
2
14
|
|
3
15
|
* Use plain old net/http instead of pulling in httparty [martijn]
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include:
|
8
|
+
|
9
|
+
* The use of sexualized language or imagery
|
10
|
+
* Personal attacks
|
11
|
+
* Trolling or insulting/derogatory comments
|
12
|
+
* Public or private harassment
|
13
|
+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
14
|
+
* Other unethical or unprofessional conduct.
|
15
|
+
|
16
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
17
|
+
|
18
|
+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
19
|
+
|
20
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
21
|
+
|
22
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
data/README.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
This is a small Ruby wrapper around the postcodeapi.nu API, which allows you
|
4
4
|
to resolve Dutch postcodes to street and city names.
|
5
5
|
|
6
|
+
**postcodeapi-2.x is only compatible with PostcodeAPI v2. PostcodeAPI v1 is
|
7
|
+
deprecated and will be taken offline on 2016-03-01.**
|
8
|
+
|
6
9
|
## Installation
|
7
10
|
|
8
11
|
Add this line to your application's Gemfile:
|
@@ -19,13 +22,58 @@ Or install it yourself as:
|
|
19
22
|
|
20
23
|
## Usage
|
21
24
|
|
22
|
-
Firstly, sign up for a free API key at http://postcodeapi.nu, then
|
25
|
+
Firstly, sign up for a free API key at http://postcodeapi.nu, then use this gem like this:
|
26
|
+
|
27
|
+
require 'pp'
|
28
|
+
require 'postcodeapi'
|
23
29
|
|
24
30
|
api = Postcode::API.new("your-api-key")
|
25
|
-
result = api.postcode("5041EB")
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
irb> pp api.addresses("5694AJ", 1)
|
33
|
+
{"addresses"=>
|
34
|
+
[{"city"=>{"id"=>"3520", "label"=>"Son en Breugel"},
|
35
|
+
"letter"=>nil,
|
36
|
+
"id"=>"0848200000005576",
|
37
|
+
"purpose"=>"woonfunctie",
|
38
|
+
"postcode"=>"5694AJ",
|
39
|
+
"municipality"=>{"id"=>"0848", "label"=>"Son en Breugel"},
|
40
|
+
"nen5825"=>{"street"=>"SINT CATHARINASTRAAT", "postcode"=>"5694 AJ"},
|
41
|
+
"street"=>"Sint Catharinastraat",
|
42
|
+
"number"=>1,
|
43
|
+
"province"=>{"id"=>"30", "label"=>"Noord-Brabant"},
|
44
|
+
"addition"=>nil,
|
45
|
+
"geo"=>
|
46
|
+
{"center"=>
|
47
|
+
{"wgs84"=>
|
48
|
+
{"crs"=>
|
49
|
+
{"properties"=>{"name"=>"urn:ogc:def:crs:OGC:1.3:CRS84"},
|
50
|
+
"type"=>"name"},
|
51
|
+
"type"=>"Point",
|
52
|
+
"coordinates"=>[5.50767699298, 51.5131728171]},
|
53
|
+
"rd"=>
|
54
|
+
{"crs"=>
|
55
|
+
{"properties"=>{"name"=>"urn:ogc:def:crs:EPSG::28992"},
|
56
|
+
"type"=>"name"},
|
57
|
+
"type"=>"Point",
|
58
|
+
"coordinates"=>[163363, 391581]}}},
|
59
|
+
"type"=>"Verblijfsobject",
|
60
|
+
"_links"=>
|
61
|
+
{"self"=>
|
62
|
+
{"href"=>
|
63
|
+
"https://postcode-api.apiwise.nl/v2/addresses/0848200000005576/"}}}]}
|
64
|
+
|
65
|
+
There is also `#simple_addresses` to retrieve a minimal set of data:
|
66
|
+
|
67
|
+
irb> pp api.simple_addresses("5694AJ", 1)
|
68
|
+
{"addresses"=>
|
69
|
+
[{"latitude"=>51.5131728171,
|
70
|
+
"longitude"=>5.50767699298,
|
71
|
+
"municipality"=>"Son en Breugel",
|
72
|
+
"postcode"=>"5694AJ",
|
73
|
+
"province"=>"Noord-Brabant",
|
74
|
+
"street"=>"Sint Catharinastraat"}]}
|
75
|
+
|
76
|
+
Please note that the house number is optional.
|
29
77
|
|
30
78
|
## Contributing
|
31
79
|
|
@@ -44,9 +92,15 @@ Original author:
|
|
44
92
|
|
45
93
|
* Ariejan de Vroom, https://ariejan.net
|
46
94
|
|
95
|
+
Github contributors
|
96
|
+
|
97
|
+
* pedrocatalao
|
98
|
+
* martijn
|
99
|
+
* WvanLelyveld
|
100
|
+
|
47
101
|
## LICENSE
|
48
102
|
|
49
|
-
Copyright (c) 2013 Ariejan de Vroom
|
103
|
+
Copyright (c) 2013-2016 Ariejan de Vroom
|
50
104
|
|
51
105
|
Permission is hereby granted, free of charge, to any person obtaining
|
52
106
|
a copy of this software and associated documentation files (the
|
data/lib/postcodeapi/api.rb
CHANGED
@@ -1,28 +1,60 @@
|
|
1
1
|
module Postcode
|
2
|
-
# You're required to sign up for an api key at http://postcodeapi.nu
|
2
|
+
# You're required to sign up for an api key at http://www.postcodeapi.nu/
|
3
3
|
class API
|
4
|
-
BASE_URI =
|
4
|
+
BASE_URI = 'https://postcode-api.apiwise.nl'
|
5
5
|
|
6
6
|
def initialize(api_key)
|
7
7
|
@api_key = api_key
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
# Returns an address list for a given postcode with all raw data that the api disposes
|
11
|
+
def addresses(postcode, house_number = nil, options = {})
|
11
12
|
postcode = sanitize(postcode)
|
12
|
-
uri = URI.parse([BASE_URI,
|
13
|
+
uri = URI.parse([BASE_URI, 'v2', 'addresses'].compact.join('/'))
|
14
|
+
uri.query = URI.encode_www_form( {'postcode' => postcode, 'number' => house_number} )
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true
|
18
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
21
|
+
request.add_field('X-Api-Key', @api_key)
|
22
|
+
response = http.request(request)
|
23
|
+
|
24
|
+
content = Hashie::Mash.new(JSON.parse(response.body))
|
25
|
+
|
26
|
+
return content if content.error
|
27
|
+
content._embedded
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns simplified addresses for a given postcode with only essential filtered data
|
31
|
+
def simple_addresses(postcode, house_number = nil, options = {})
|
32
|
+
content = addresses(postcode, house_number, options)
|
20
33
|
|
21
|
-
|
34
|
+
return content if content.error
|
35
|
+
simplify(content)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def simplify(content)
|
41
|
+
addresses = []
|
42
|
+
content.addresses.each do |entry|
|
43
|
+
addresses << Hashie::Mash.new(
|
44
|
+
{ latitude: entry.geo.center.wgs84.coordinates.last,
|
45
|
+
longitude: entry.geo.center.wgs84.coordinates.first,
|
46
|
+
municipality: entry.municipality.label,
|
47
|
+
postcode: entry.postcode,
|
48
|
+
province: entry.province.label,
|
49
|
+
street: entry.street
|
50
|
+
} )
|
51
|
+
end
|
52
|
+
Hashie::Mash.new({addresses: addresses})
|
22
53
|
end
|
23
54
|
|
24
55
|
def sanitize(postcode)
|
25
56
|
postcode.gsub(/\s+/, '').upcase
|
26
57
|
end
|
58
|
+
|
27
59
|
end
|
28
60
|
end
|
data/lib/postcodeapi/version.rb
CHANGED
data/postcodeapi.gemspec
CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'hashie', '>=
|
20
|
+
gem.add_dependency 'hashie', '>= 3.4.3'
|
21
21
|
|
22
|
-
gem.add_development_dependency 'rake', '~> 10.0
|
23
|
-
gem.add_development_dependency 'rspec', '~>
|
24
|
-
gem.add_development_dependency 'webmock', '~> 1.
|
22
|
+
gem.add_development_dependency 'rake', '~> 10.5.0'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 3.4.0'
|
24
|
+
gem.add_development_dependency 'webmock', '~> 1.22.6'
|
25
25
|
end
|
@@ -3,71 +3,95 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe Postcode::API do
|
4
4
|
context "without a valid API key" do
|
5
5
|
before do
|
6
|
-
body = '{"
|
7
|
-
stub_request(:get, "
|
8
|
-
with(:headers => {'Api-Key'=>'invalid'}).
|
6
|
+
body = '{"error":"API key is invalid."}'
|
7
|
+
stub_request(:get, "https://postcode-api.apiwise.nl/v2/addresses?number&postcode=5041EB").
|
8
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby', 'X-Api-Key'=>'invalid'}).
|
9
9
|
to_return(:status => 401, :body => body, :headers => {"Content-Type" => "application/json"})
|
10
10
|
end
|
11
11
|
|
12
12
|
subject(:api) { Postcode::API.new("invalid") }
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
context "for raw data request" do
|
15
|
+
it 'returns an error response' do
|
16
|
+
result = api.addresses('5041EB')
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
expect(result.error).to eq("API key is invalid.")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "for simplified data request" do
|
23
|
+
it 'also returns an error response' do
|
24
|
+
result = api.simple_addresses('5041EB')
|
25
|
+
|
26
|
+
expect(result.error).to eq("API key is invalid.")
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
22
31
|
context "with a valid API key" do
|
23
32
|
context "with postcode only" do
|
24
33
|
before do
|
25
|
-
body = '{"
|
26
|
-
stub_request(:get, "
|
27
|
-
with(:headers => {'Api-Key'=>'valid'}).
|
28
|
-
to_return(:status =>
|
34
|
+
body = '{"_embedded":{"addresses":[{"city":{"id":"1043","label":"Tilburg"},"letter":"a","id":"0855200000066230","purpose":"kantoorfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":17,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07699118186,51.5666652242]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133491.678,397570.947]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000066230/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000060997","purpose":"kantoorfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":17,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07703198051,51.5666742042]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133494.511,397571.934]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000060997/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000060998","purpose":"kantoorfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":18,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07706422938,51.5666172658]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133496.72,397565.59]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000060998/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":"b","id":"0855200000061000","purpose":"industriefunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":19,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07709246364,51.5665293687]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133498.636,397555.803]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061000/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":"a","id":"0855200000060999","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":19,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07708494827,51.5665443149]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133498.122,397557.468]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000060999/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061001","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":21,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07717893166,51.566414786]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133504.577,397543.03]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061001/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":"b","id":"0855200000061004","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":22,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07720777743,51.566283727]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133506.515,397528.441]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061004/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000110606","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":22,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07724882372,51.5662923031]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133509.365,397529.383]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000110606/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061005","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":23,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07728036245,51.5662336728]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133511.524,397522.851]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061005/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061006","purpose":"winkelfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":24,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07731653182,51.5661664347]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133514,397515.36]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061006/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061007","purpose":"kantoorfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":25,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07738142047,51.5660457722]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133518.442,397501.917]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061007/"}}},{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061008","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":27,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07745550693,51.5659044692]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133523.512,397486.175]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061008/"}}}]},"_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/?postcode=5041EB"}}}'
|
35
|
+
stub_request(:get, "https://postcode-api.apiwise.nl/v2/addresses?number&postcode=5041EB").
|
36
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby', 'X-Api-Key'=>'valid'}).
|
37
|
+
to_return(:status => 200, :body => body, :headers => {"Content-Type" => "application/json"})
|
29
38
|
end
|
30
39
|
|
31
40
|
subject(:api) { Postcode::API.new("valid") }
|
32
41
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
context "for raw data request" do
|
43
|
+
it 'returns an success response with correct format' do
|
44
|
+
result = api.addresses('5041EB')
|
45
|
+
|
46
|
+
expect(result.addresses).to_not be_empty
|
47
|
+
expect(result.addresses.first.street).to eq("Wilhelminapark")
|
48
|
+
expect(result.addresses.first.postcode).to eq("5041EB")
|
49
|
+
expect(result.addresses.first.municipality.label).to eq("Tilburg")
|
50
|
+
expect(result.addresses.first.geo.center.wgs84.coordinates.last).to eq(51.5666652242)
|
51
|
+
expect(result.addresses.first.geo.center.wgs84.coordinates.first).to eq(5.07699118186)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "for simplified data request" do
|
56
|
+
it 'returns an success response' do
|
57
|
+
result = api.simple_addresses('5041EB')
|
58
|
+
|
59
|
+
expect(result.addresses).not_to be_empty
|
60
|
+
expect(result.addresses.first.street).to eq("Wilhelminapark")
|
61
|
+
expect(result.addresses.first.postcode).to eq("5041EB")
|
62
|
+
expect(result.addresses.first.municipality).to eq("Tilburg")
|
63
|
+
expect(result.addresses.first.latitude).to eq(51.5666652242)
|
64
|
+
expect(result.addresses.first.longitude).to eq(5.07699118186)
|
65
|
+
end
|
42
66
|
end
|
43
67
|
|
44
68
|
it 'sanitizes input before lookup' do
|
45
|
-
result = api.
|
69
|
+
result = api.simple_addresses('5041 eb')
|
46
70
|
|
47
|
-
result.
|
48
|
-
result.
|
71
|
+
expect(result.addresses).to_not be_empty
|
72
|
+
expect(result.addresses.first.postcode).to eq("5041EB")
|
49
73
|
end
|
50
74
|
end
|
51
75
|
|
52
76
|
context "with postcode and house number" do
|
53
77
|
before do
|
54
|
-
body = '{"
|
55
|
-
stub_request(:get, "
|
56
|
-
with(:headers => {'Api-Key'=>'valid'}).
|
57
|
-
to_return(:status =>
|
78
|
+
body = '{"_embedded":{"addresses":[{"city":{"id":"1043","label":"Tilburg"},"letter":null,"id":"0855200000061001","purpose":"woonfunctie","postcode":"5041EB","municipality":{"id":"0855","label":"Tilburg"},"nen5825":{"street":"WILHELMINAPARK","postcode":"5041 EB"},"street":"Wilhelminapark","number":21,"province":{"id":"30","label":"Noord-Brabant"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[5.07717893166,51.566414786]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[133504.577,397543.03]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0855200000061001/"}}}]},"_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/?postcode=5041EB&number=21"}}}'
|
79
|
+
stub_request(:get, "https://postcode-api.apiwise.nl/v2/addresses?number=21&postcode=5041EB").
|
80
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby', 'X-Api-Key'=>'valid'}).
|
81
|
+
to_return(:status => 200, :body => body, :headers => {"Content-Type" => "application/json"})
|
58
82
|
end
|
59
83
|
|
60
84
|
subject(:api) { Postcode::API.new("valid") }
|
61
85
|
|
62
86
|
it 'returns an error response' do
|
63
|
-
result = api.
|
64
|
-
|
65
|
-
result.
|
66
|
-
result.
|
67
|
-
result.
|
68
|
-
result.
|
69
|
-
result.
|
70
|
-
result.
|
87
|
+
result = api.simple_addresses('5041EB', 21)
|
88
|
+
|
89
|
+
expect(result.addresses).to_not be_empty
|
90
|
+
expect(result.addresses.first.street).to eq("Wilhelminapark")
|
91
|
+
expect(result.addresses.first.postcode).to eq("5041EB")
|
92
|
+
expect(result.addresses.first.municipality).to eq("Tilburg")
|
93
|
+
expect(result.addresses.first.latitude).to eq(51.566414786)
|
94
|
+
expect(result.addresses.first.longitude).to eq(5.07717893166)
|
71
95
|
end
|
72
96
|
end
|
73
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postcodeapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariejan de Vroom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.4.3
|
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:
|
26
|
+
version: 3.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 10.0
|
33
|
+
version: 10.5.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: 10.0
|
40
|
+
version: 10.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.4.0
|
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: 3.4.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.22.6
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.22.6
|
69
69
|
description: Wrapper around the postcodeapi.nu API for resolving Dutch postal codes
|
70
70
|
email:
|
71
71
|
- ariejan@ariejan.net
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
79
|
- CHANGELOG.txt
|
80
|
+
- CODE_OF_CONDUCT.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.4.5
|
111
|
+
rubygems_version: 2.4.5.1
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: Wrapper around the postcodeapi.nu API.
|