dcentralized 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dcentralized.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nick den Engelsman
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,51 @@
1
+ # Dcentralized
2
+
3
+ API wrapper for Pro6PP zipcode database(d-centralize.nl).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dcentralized'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dcentralized
18
+
19
+ ## Setup
20
+
21
+ Add file `config/initializers/dcentralized.rb`.
22
+
23
+ require 'dcentralized'
24
+ Dcentralized.configure do |config|
25
+ config.api_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
26
+ end
27
+
28
+ ## Usage
29
+
30
+ **Example**
31
+
32
+ Dcentralized.auto_complete("2564AZ")
33
+ # => {
34
+ "nl_sixpp":["2564AZ"],
35
+ "street":["Laan van Meerdervoort"],
36
+ "city":["'s-Gravenhage"],
37
+ "municipality":["'s-Gravenhage"],
38
+ "province":["Zuid-Holland"],
39
+ "streetnumbers":["1096-1126"],
40
+ "lat":["52.06751"],
41
+ "lng":["4.24733"],
42
+ "areacode":["070"]
43
+ }
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dcentralized/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dcentralized"
8
+ gem.version = Dcentralized::VERSION
9
+ gem.authors = ["Nick den Engelsman"]
10
+ gem.email = ["nickdenengelsman@codedrops.nl"]
11
+ gem.description = %q{API wrapper for d-centralize.nl}
12
+ gem.summary = %q{Retreive data from the Pro6PP zipcode database}
13
+ gem.homepage = ""
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_runtime_dependency "rest-client", "~> 1.6.7"
21
+ gem.add_runtime_dependency "xml-simple", "~> 1.1.2"
22
+
23
+ gem.add_development_dependency "rspec", "~> 2.13.0"
24
+ gem.add_development_dependency "capybara", "~> 2.1.0"
25
+ gem.add_development_dependency "vcr", "~> 2.4.0"
26
+ gem.add_development_dependency "webmock", "~> 1.8.0"
27
+ gem.add_development_dependency "simplecov", "~> 0.7.1"
28
+ end
@@ -0,0 +1,43 @@
1
+ require "xmlsimple"
2
+ require "json"
3
+ require "rest-client"
4
+ require "dcentralized/version"
5
+
6
+ module Dcentralized
7
+ class << self
8
+ attr_accessor :api_url, :auth_key
9
+ def configure(&blk); class_eval(&blk); end
10
+ end
11
+
12
+ def self.auto_complete(zipcode)
13
+ # Format the zipcode
14
+ zipcode = format_zipcode(zipcode)
15
+ # Setup request
16
+ params = {auth_key: @auth_key}
17
+ zipcode.length == 6 ? params.merge!(nl_sixpp: zipcode) : params.merge!(nl_fourpp: zipcode)
18
+ params.merge!(format: 'xml', pretty: 'True')
19
+ # Perform request and return output
20
+ response = RestClient.get "#{@api_url}/autocomplete", {params: params}
21
+ XmlSimple.xml_in(response)["results"][0]["result"][0].to_json
22
+ end
23
+
24
+ def self.format_zipcode(zipcode = nil)
25
+ if zipcode.nil? || zipcode == ""
26
+ raise Exception.new("No zipcode provided")
27
+ elsif (zipcode =~ /^[1-9]{4}$|[1-9]{4}[\ ]{1}[a-zA-Z]{2}$|[1-9]{4}[a-zA-Z]{2}$/).nil?
28
+ raise Exception.new("Wrong zipcode format (1234AB format expected)")
29
+ else
30
+ zipcode.gsub(" ", "").upcase
31
+ end
32
+ end
33
+
34
+ def self.version_string
35
+ "Dcentralized version #{Dcentralized::VERSION}"
36
+ end
37
+ end
38
+
39
+ # Set default configuration
40
+ Dcentralized.configure do
41
+ @api_url = "http://api.pro6pp.nl/v1"
42
+ @auth_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
43
+ end
@@ -0,0 +1,3 @@
1
+ module Dcentralized
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dcentralized do
4
+ it 'should remove spaces from zipcode' do
5
+ Dcentralized.format_zipcode("2564 AZ").should eq "2564AZ"
6
+ end
7
+
8
+ it 'should upcase the zipcode' do
9
+ Dcentralized.format_zipcode("2564az").should eq "2564AZ"
10
+ end
11
+
12
+ it 'should raise an exception' do
13
+ expect { Dcentralized.format_zipcode(nil) }.to raise_error
14
+ expect { Dcentralized.format_zipcode("") }.to raise_error
15
+ expect { Dcentralized.format_zipcode("111") }.to raise_error
16
+ expect { Dcentralized.format_zipcode("1111A") }.to raise_error
17
+ expect { Dcentralized.format_zipcode("11111A") }.to raise_error
18
+ expect { Dcentralized.format_zipcode("AAAA") }.to raise_error
19
+ expect { Dcentralized.format_zipcode("11AA") }.to raise_error
20
+ end
21
+
22
+ it 'should return high detailed result' do
23
+ VCR.use_cassette('auto_complete_high') do
24
+ xml_response_mock = '{"nl_sixpp":["2564AZ"],"street":["Laan van Meerdervoort"],"city":["\'s-Gravenhage"],"municipality":["\'s-Gravenhage"],"province":["Zuid-Holland"],"streetnumbers":["1096-1126"],"lat":["52.06751"],"lng":["4.24733"],"areacode":["070"]}'
25
+ Dcentralized.auto_complete("2564AZ").should eq xml_response_mock
26
+ Dcentralized.auto_complete("2564AZ").should include('"street":[')
27
+ end
28
+ end
29
+
30
+ it 'should return low detailed result' do
31
+ VCR.use_cassette('auto_complete_low') do
32
+ xml_response_mock = '{"nl_fourpp":["2564"],"city":["\'s-Gravenhage"],"municipality":["\'s-Gravenhage"],"province":["Zuid-Holland"],"areacode":["070"],"lat":["52.068"],"lng":["4.25724"]}'
33
+ Dcentralized.auto_complete("2564").should eq xml_response_mock
34
+ Dcentralized.auto_complete("2564").should_not include('"street":[')
35
+ end
36
+ end
37
+
38
+ it 'should return correct version string' do
39
+ Dcentralized.version_string.should eq "Dcentralized version #{Dcentralized::VERSION}"
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'webmock'
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+ require 'dcentralized'
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ end
12
+
13
+ VCR.configure do |config|
14
+ config.cassette_library_dir = 'spec/vcr'
15
+ config.hook_into :webmock
16
+ end
@@ -0,0 +1,83 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.pro6pp.nl/v1/autocomplete?auth_key=123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ&format=xml&nl_sixpp=2564AZ&pretty=True
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/xml; charset=utf-8
25
+ Vary:
26
+ - Accept-Encoding
27
+ Date:
28
+ - Wed, 17 Apr 2013 19:21:03 GMT
29
+ Server:
30
+ - Google Frontend
31
+ Transfer-Encoding:
32
+ - chunked
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <status>ok</status>\n
36
+ \ <results>\n <result>\n <nl_sixpp>2564AZ</nl_sixpp>\n <street>Laan
37
+ van Meerdervoort</street>\n <city>'s-Gravenhage</city>\n <municipality>'s-Gravenhage</municipality>\n
38
+ \ <province>Zuid-Holland</province>\n <streetnumbers>1096-1126</streetnumbers>\n
39
+ \ <lat>52.06751</lat>\n <lng>4.24733</lng>\n <areacode>070</areacode>\n
40
+ \ </result>\n </results>\n</response>\n"
41
+ http_version:
42
+ recorded_at: Wed, 17 Apr 2013 19:21:03 GMT
43
+ - request:
44
+ method: get
45
+ uri: http://api.pro6pp.nl/v1/autocomplete?auth_key=123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ&format=xml&nl_sixpp=2564AZ&pretty=True
46
+ body:
47
+ encoding: US-ASCII
48
+ string: ''
49
+ headers:
50
+ Accept:
51
+ - ! '*/*; q=0.5, application/xml'
52
+ Accept-Encoding:
53
+ - gzip, deflate
54
+ User-Agent:
55
+ - Ruby
56
+ response:
57
+ status:
58
+ code: 200
59
+ message: OK
60
+ headers:
61
+ Cache-Control:
62
+ - no-cache
63
+ Content-Type:
64
+ - application/xml; charset=utf-8
65
+ Vary:
66
+ - Accept-Encoding
67
+ Date:
68
+ - Wed, 17 Apr 2013 19:21:04 GMT
69
+ Server:
70
+ - Google Frontend
71
+ Transfer-Encoding:
72
+ - chunked
73
+ body:
74
+ encoding: US-ASCII
75
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <status>ok</status>\n
76
+ \ <results>\n <result>\n <nl_sixpp>2564AZ</nl_sixpp>\n <street>Laan
77
+ van Meerdervoort</street>\n <city>'s-Gravenhage</city>\n <municipality>'s-Gravenhage</municipality>\n
78
+ \ <province>Zuid-Holland</province>\n <streetnumbers>1096-1126</streetnumbers>\n
79
+ \ <lat>52.06751</lat>\n <lng>4.24733</lng>\n <areacode>070</areacode>\n
80
+ \ </result>\n </results>\n</response>\n"
81
+ http_version:
82
+ recorded_at: Wed, 17 Apr 2013 19:21:04 GMT
83
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.pro6pp.nl/v1/autocomplete?auth_key=123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ&format=xml&nl_fourpp=2564&pretty=True
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/xml; charset=utf-8
25
+ Vary:
26
+ - Accept-Encoding
27
+ Date:
28
+ - Wed, 17 Apr 2013 19:21:04 GMT
29
+ Server:
30
+ - Google Frontend
31
+ Transfer-Encoding:
32
+ - chunked
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <status>ok</status>\n
36
+ \ <results>\n <result>\n <nl_fourpp>2564</nl_fourpp>\n <city>'s-Gravenhage</city>\n
37
+ \ <municipality>'s-Gravenhage</municipality>\n <province>Zuid-Holland</province>\n
38
+ \ <areacode>070</areacode>\n <lat>52.068</lat>\n <lng>4.25724</lng>\n
39
+ \ </result>\n </results>\n</response>\n"
40
+ http_version:
41
+ recorded_at: Wed, 17 Apr 2013 19:21:04 GMT
42
+ - request:
43
+ method: get
44
+ uri: http://api.pro6pp.nl/v1/autocomplete?auth_key=123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ&format=xml&nl_fourpp=2564&pretty=True
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ''
48
+ headers:
49
+ Accept:
50
+ - ! '*/*; q=0.5, application/xml'
51
+ Accept-Encoding:
52
+ - gzip, deflate
53
+ User-Agent:
54
+ - Ruby
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Cache-Control:
61
+ - no-cache
62
+ Content-Type:
63
+ - application/xml; charset=utf-8
64
+ Vary:
65
+ - Accept-Encoding
66
+ Date:
67
+ - Wed, 17 Apr 2013 19:21:04 GMT
68
+ Server:
69
+ - Google Frontend
70
+ Transfer-Encoding:
71
+ - chunked
72
+ body:
73
+ encoding: US-ASCII
74
+ string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <status>ok</status>\n
75
+ \ <results>\n <result>\n <nl_fourpp>2564</nl_fourpp>\n <city>'s-Gravenhage</city>\n
76
+ \ <municipality>'s-Gravenhage</municipality>\n <province>Zuid-Holland</province>\n
77
+ \ <areacode>070</areacode>\n <lat>52.068</lat>\n <lng>4.25724</lng>\n
78
+ \ </result>\n </results>\n</response>\n"
79
+ http_version:
80
+ recorded_at: Wed, 17 Apr 2013 19:21:04 GMT
81
+ recorded_with: VCR 2.4.0
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcentralized
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick den Engelsman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
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: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: xml-simple
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.2
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.1.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.13.0
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: 2.13.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: capybara
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.1.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.1.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: vcr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.4.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: 2.4.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.7.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.7.1
126
+ description: API wrapper for d-centralize.nl
127
+ email:
128
+ - nickdenengelsman@codedrops.nl
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - dcentralized.gemspec
139
+ - lib/dcentralized.rb
140
+ - lib/dcentralized/version.rb
141
+ - spec/lib/dcentralized_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/vcr/auto_complete_high.yml
144
+ - spec/vcr/auto_complete_low.yml
145
+ homepage: ''
146
+ licenses: []
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 1.8.25
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Retreive data from the Pro6PP zipcode database
169
+ test_files:
170
+ - spec/lib/dcentralized_spec.rb
171
+ - spec/spec_helper.rb
172
+ - spec/vcr/auto_complete_high.yml
173
+ - spec/vcr/auto_complete_low.yml