dcentralized 0.0.2 → 0.0.3
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/README.md +18 -16
- data/lib/dcentralized.rb +8 -5
- data/lib/dcentralized/version.rb +1 -1
- data/spec/lib/dcentralized_spec.rb +4 -4
- metadata +8 -2
data/README.md
CHANGED
@@ -25,22 +25,24 @@ Add file `config/initializers/dcentralized.rb`.
|
|
25
25
|
config.api_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
|
26
26
|
end
|
27
27
|
|
28
|
-
##
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Dcentralized.auto_complete("2564AZ")
|
33
|
-
# =>
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
28
|
+
## Example usage
|
29
|
+
|
30
|
+
High detailed zipcode result:
|
31
|
+
|
32
|
+
response = Dcentralized.auto_complete("2564AZ")
|
33
|
+
# => #<OpenStruct 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">
|
34
|
+
|
35
|
+
Low detailed zipcode result:
|
36
|
+
|
37
|
+
response = Dcentralized.auto_complete("2564")
|
38
|
+
# => #<OpenStruct nl_fourpp="2564", city="'s-Gravenhage", municipality="'s-Gravenhage", province="Zuid-Holland", areacode="070", lat="52.068", lng="4.25724">
|
39
|
+
|
40
|
+
You can then use:
|
41
|
+
|
42
|
+
response.street
|
43
|
+
# => "Laan van Meerdervoort"
|
44
|
+
response.province
|
45
|
+
# => "Zuid-Holland"
|
44
46
|
|
45
47
|
## Contributing
|
46
48
|
|
data/lib/dcentralized.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "rest-client"
|
2
2
|
require "xmlsimple"
|
3
3
|
require "hash_symbolizer"
|
4
|
+
require "ostruct"
|
4
5
|
require "dcentralized/version"
|
5
6
|
|
6
7
|
module Dcentralized
|
7
8
|
class << self
|
8
|
-
attr_accessor :api_url, :
|
9
|
+
attr_accessor :api_url, :api_key
|
9
10
|
def configure(&blk); class_eval(&blk); end
|
10
11
|
end
|
11
12
|
|
@@ -13,12 +14,14 @@ module Dcentralized
|
|
13
14
|
# Format the zipcode
|
14
15
|
zipcode = format_zipcode(zipcode)
|
15
16
|
# Setup request
|
16
|
-
params
|
17
|
+
params = {auth_key: @api_key}
|
17
18
|
zipcode.length == 6 ? params.merge!(nl_sixpp: zipcode) : params.merge!(nl_fourpp: zipcode)
|
18
19
|
params.merge!(format: 'xml', pretty: 'True')
|
19
|
-
# Perform request
|
20
|
+
# Perform request
|
20
21
|
response = RestClient.get "#{@api_url}/autocomplete", {params: params}
|
21
|
-
|
22
|
+
hash = XmlSimple.xml_in(response)["results"][0]["result"][0].symbolize_keys(true)
|
23
|
+
# Return openstruct output
|
24
|
+
OpenStruct.new stringify(hash)
|
22
25
|
end
|
23
26
|
|
24
27
|
def self.format_zipcode(zipcode = nil)
|
@@ -47,5 +50,5 @@ end
|
|
47
50
|
# Set default configuration
|
48
51
|
Dcentralized.configure do
|
49
52
|
@api_url = "http://api.pro6pp.nl/v1"
|
50
|
-
@
|
53
|
+
@api_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
|
51
54
|
end
|
data/lib/dcentralized/version.rb
CHANGED
@@ -32,8 +32,8 @@ describe Dcentralized do
|
|
32
32
|
:lng => "4.24733",
|
33
33
|
:areacode => "070"
|
34
34
|
}
|
35
|
-
Dcentralized.auto_complete("2564AZ").should eq xml_response_mock
|
36
|
-
Dcentralized.auto_complete("2564AZ").should
|
35
|
+
Dcentralized.auto_complete("2564AZ").should eq OpenStruct.new(xml_response_mock)
|
36
|
+
Dcentralized.auto_complete("2564AZ").street.should eq "Laan van Meerdervoort"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -48,8 +48,8 @@ describe Dcentralized do
|
|
48
48
|
:lat => "52.068",
|
49
49
|
:lng => "4.25724"
|
50
50
|
}
|
51
|
-
Dcentralized.auto_complete("2564").should eq xml_response_mock
|
52
|
-
Dcentralized.auto_complete("2564").
|
51
|
+
Dcentralized.auto_complete("2564").should eq OpenStruct.new(xml_response_mock)
|
52
|
+
Dcentralized.auto_complete("2564").street.should eq nil
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcentralized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-04-
|
12
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -170,12 +170,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- - ! '>='
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
hash: -1491342071412150727
|
173
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
177
|
none: false
|
175
178
|
requirements:
|
176
179
|
- - ! '>='
|
177
180
|
- !ruby/object:Gem::Version
|
178
181
|
version: '0'
|
182
|
+
segments:
|
183
|
+
- 0
|
184
|
+
hash: -1491342071412150727
|
179
185
|
requirements: []
|
180
186
|
rubyforge_project:
|
181
187
|
rubygems_version: 1.8.25
|