api_postcode_nl 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/api_postcode_nl.gemspec +3 -2
- data/lib/api_postcode_nl/api.rb +18 -4
- data/lib/api_postcode_nl/invalid_postcode_exception.rb +5 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/api_postcode_nl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "api_postcode_nl"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["rhomeister"]
|
12
|
-
s.date = "2013-01-
|
12
|
+
s.date = "2013-01-14"
|
13
13
|
s.description = "Retrieve a Dutch address based on housenumber and postcode"
|
14
14
|
s.email = "r.stranders@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"api_postcode_nl.gemspec",
|
28
28
|
"lib/api_postcode_nl.rb",
|
29
29
|
"lib/api_postcode_nl/api.rb",
|
30
|
+
"lib/api_postcode_nl/invalid_postcode_exception.rb",
|
30
31
|
"test/helper.rb",
|
31
32
|
"test/test_api_postcode_nl.rb"
|
32
33
|
]
|
data/lib/api_postcode_nl/api.rb
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'net/https'
|
4
4
|
require 'json'
|
5
|
+
require 'api_postcode_nl/invalid_postcode_exception'
|
5
6
|
|
6
7
|
module ApiPostcodeNl
|
7
8
|
class API
|
8
9
|
BASE_URL = "https://api.postcode.nl/rest/addresses"
|
9
|
-
|
10
|
+
|
10
11
|
class << self
|
11
12
|
def get_url(postcode, house_number, house_number_addition = nil)
|
12
|
-
|
13
|
+
postcode, house_number, house_number_addition = [postcode, house_number, house_number_addition].map{|c| c.to_s.delete(" ")}
|
14
|
+
"#{BASE_URL}/#{postcode}/#{house_number}/#{house_number_addition}"
|
13
15
|
end
|
14
16
|
|
15
17
|
def send(postcode, house_number, house_number_addition = nil)
|
@@ -19,9 +21,21 @@ module ApiPostcodeNl
|
|
19
21
|
|
20
22
|
request = Net::HTTP::Get.new(uri.path)
|
21
23
|
request.basic_auth key, secret
|
22
|
-
http.start {|http|
|
24
|
+
result = http.start {|http|
|
23
25
|
http.request(request)
|
24
|
-
}
|
26
|
+
}
|
27
|
+
handle_errors(result)
|
28
|
+
|
29
|
+
result.body
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_errors(result)
|
33
|
+
if result.is_a?(Net::HTTPNotFound)
|
34
|
+
raise ApiPostcodeNl::InvalidPostcodeException, JSON.parse(result.body)["exception"]
|
35
|
+
end
|
36
|
+
#puts result.code.class
|
37
|
+
#puts result.message
|
38
|
+
#puts result.body
|
25
39
|
end
|
26
40
|
|
27
41
|
def parse(response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_postcode_nl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- api_postcode_nl.gemspec
|
62
62
|
- lib/api_postcode_nl.rb
|
63
63
|
- lib/api_postcode_nl/api.rb
|
64
|
+
- lib/api_postcode_nl/invalid_postcode_exception.rb
|
64
65
|
- test/helper.rb
|
65
66
|
- test/test_api_postcode_nl.rb
|
66
67
|
homepage: http://github.com/rhomeister/api_postcode_nl
|
@@ -78,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
79
|
version: '0'
|
79
80
|
segments:
|
80
81
|
- 0
|
81
|
-
hash: -
|
82
|
+
hash: -2919040409656760397
|
82
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
84
|
none: false
|
84
85
|
requirements:
|