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 CHANGED
@@ -25,22 +25,24 @@ Add file `config/initializers/dcentralized.rb`.
25
25
  config.api_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
26
26
  end
27
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
- }
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, :auth_key
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 = {auth_key: @auth_key}
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 and return output
20
+ # Perform request
20
21
  response = RestClient.get "#{@api_url}/autocomplete", {params: params}
21
- stringify(XmlSimple.xml_in(response)["results"][0]["result"][0].symbolize_keys(true))
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
- @auth_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
53
+ @api_key = "123456789aBcDeFgHiJkLmNoPqRsTuVwXyZ"
51
54
  end
@@ -1,3 +1,3 @@
1
1
  module Dcentralized
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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 include(:street)
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").should_not include(:street)
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.2
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-19 00:00:00.000000000 Z
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