postcodeapi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +1 -0
- data/lib/postcodeapi/api.rb +18 -0
- data/lib/postcodeapi/version.rb +3 -0
- data/lib/postcodeapi.rb +10 -0
- data/postcodeapi.gemspec +26 -0
- data/spec/postcodeapi/api_spec.rb +49 -0
- data/spec/spec_helper.rb +8 -0
- metadata +146 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-c -fd
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ariejan de Vroom
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Postcodeapi [![Build Status](https://travis-ci.org/ariejan/postcodeapi.png?branch=master)](https://travis-ci.org/ariejan/postcodeapi)
|
2
|
+
|
3
|
+
This is a small Ruby wrapper around the postcodeapi.nu API, which allows you
|
4
|
+
to resolve Dutch postcodes to street and city names.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'postcodeapi'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install postcodeapi
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Firstly, sign up for a free API key at http://postcodeapi.nu, then juse this gem:
|
23
|
+
|
24
|
+
api = Postcode::API.new("your-api-key")
|
25
|
+
result = api.postcode("5041EB")
|
26
|
+
|
27
|
+
result.resource.street
|
28
|
+
=> "Wilhelminastraat"
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Please make sure you add specs for your features. Pull requests without proper
|
33
|
+
specs will not be merged.
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## Contributors
|
42
|
+
|
43
|
+
Original author:
|
44
|
+
|
45
|
+
* Ariejan de Vroom, https://ariejan.net
|
46
|
+
|
47
|
+
## LICENSE
|
48
|
+
|
49
|
+
Copyright (c) 2013 Ariejan de Vroom
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
52
|
+
a copy of this software and associated documentation files (the
|
53
|
+
"Software"), to deal in the Software without restriction, including
|
54
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
55
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
56
|
+
permit persons to whom the Software is furnished to do so, subject to
|
57
|
+
the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be
|
60
|
+
included in all copies or substantial portions of the Software.
|
61
|
+
|
62
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
63
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
65
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
66
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
67
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
68
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Postcode
|
2
|
+
# You're required to sign up for an api key at http://postcodeapi.nu
|
3
|
+
class API
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
base_uri "http://api.postcodeapi.nu"
|
7
|
+
|
8
|
+
def initialize(api_key)
|
9
|
+
@api_key = api_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def postcode(postcode, options = {})
|
13
|
+
options.merge!(:headers => { "Api-Key" => @api_key})
|
14
|
+
response = self.class.get("/#{postcode}", options)
|
15
|
+
Hashie::Mash.new(response.parsed_response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/postcodeapi.rb
ADDED
data/postcodeapi.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'postcodeapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "postcodeapi"
|
8
|
+
gem.version = Postcode::VERSION
|
9
|
+
gem.authors = ["Ariejan de Vroom"]
|
10
|
+
gem.email = ["ariejan@ariejan.net"]
|
11
|
+
gem.description = %q{Wrapper around the postcodeapi.nu API for resolving Dutch postal codes}
|
12
|
+
gem.summary = %q{Wrapper around the postcodeapi.nu API.}
|
13
|
+
gem.homepage = "https://github.com/ariejan/postcodeapi"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'httparty', '~> 0.10.2'
|
21
|
+
gem.add_dependency 'hashie', '~> 1.2.0'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake', '~> 10.0.3'
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
25
|
+
gem.add_development_dependency 'webmock', '~> 1.9.0'
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Postcode::API do
|
4
|
+
|
5
|
+
context "without a valid API key" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
body = '{"success":false,"error":{"code":401,"message":"A valid \'Api-Key\' needs to be provided in the \'Headers\' in order to use this API."}}'
|
9
|
+
stub_request(:get, "http://api.postcodeapi.nu/5041EB").
|
10
|
+
with(:headers => {'Api-Key'=>'invalid'}).
|
11
|
+
to_return(:status => 401, :body => body, :headers => {"Content-Type" => "application/json"})
|
12
|
+
end
|
13
|
+
|
14
|
+
subject(:api) { Postcode::API.new("invalid") }
|
15
|
+
|
16
|
+
it 'returns an error response' do
|
17
|
+
result = api.postcode('5041EB')
|
18
|
+
|
19
|
+
result.success.should be_false
|
20
|
+
result.error.code.should eq(401)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with a valid API key" do
|
25
|
+
|
26
|
+
before do
|
27
|
+
body = '{"success":true,"resource":{"street":"Wilhelminapark","postcode":"5041EB","town":"Tilburg","latitude":51.9401,"longitude":5.61531}}'
|
28
|
+
stub_request(:get, "http://api.postcodeapi.nu/5041EB").
|
29
|
+
with(:headers => {'Api-Key'=>'valid'}).
|
30
|
+
to_return(:status => 401, :body => body, :headers => {"Content-Type" => "application/json"})
|
31
|
+
end
|
32
|
+
|
33
|
+
subject(:api) { Postcode::API.new("valid") }
|
34
|
+
|
35
|
+
it 'returns an error response' do
|
36
|
+
result = api.postcode('5041EB')
|
37
|
+
|
38
|
+
result.success.should be_true
|
39
|
+
result.resource.street.should eq("Wilhelminapark")
|
40
|
+
result.resource.postcode.should eq("5041EB")
|
41
|
+
result.resource.town.should eq("Tilburg")
|
42
|
+
result.resource.latitude.should eq(51.9401)
|
43
|
+
result.resource.longitude.should eq(5.61531)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postcodeapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ariejan de Vroom
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hashie
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 10.0.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.0.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.12.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.12.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.9.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.9.0
|
94
|
+
description: Wrapper around the postcodeapi.nu API for resolving Dutch postal codes
|
95
|
+
email:
|
96
|
+
- ariejan@ariejan.net
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- lib/postcodeapi.rb
|
109
|
+
- lib/postcodeapi/api.rb
|
110
|
+
- lib/postcodeapi/version.rb
|
111
|
+
- postcodeapi.gemspec
|
112
|
+
- spec/postcodeapi/api_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: https://github.com/ariejan/postcodeapi
|
115
|
+
licenses: []
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: -20125056826090370
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -20125056826090370
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.25
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Wrapper around the postcodeapi.nu API.
|
144
|
+
test_files:
|
145
|
+
- spec/postcodeapi/api_spec.rb
|
146
|
+
- spec/spec_helper.rb
|