ww-postcodeapi 0.0.1 → 0.0.2

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
@@ -1,6 +1,6 @@
1
1
  # Postcodeapi
2
2
 
3
- [![Build Status](https://travis-ci.org/martijnschouwe/postcodeapi.png)](https://travis-ci.org/martijnschouwe/postcodeapi) [![Code Climate](https://codeclimate.com/github/martijnschouwe/postcodeapi.png)](https://codeclimate.com/github/martijnschouwe/postcodeapi) [![Gem Version](https://badge.fury.io/rb/postcodeapi.png)](http://badge.fury.io/rb/postcodeapi)
3
+ [![Build Status](https://travis-ci.org/martijnschouwe/postcodeapi.png)](https://travis-ci.org/martijnschouwe/postcodeapi) [![Code Climate](https://codeclimate.com/github/martijnschouwe/postcodeapi.png)](https://codeclimate.com/github/martijnschouwe/postcodeapi) [![Gem Version](https://badge.fury.io/rb/postcodeapi.png)](http://badge.fury.io/rb/ww-postcodeapi)
4
4
 
5
5
  API wrapper for postcodeapi.nu zipcode api.
6
6
 
@@ -20,6 +20,16 @@ module Postcodeapi
20
20
  OpenStruct.new res[:resource]
21
21
  end
22
22
 
23
+ def self.get_address(zipcode,number)
24
+ # Format the zipcode
25
+ zipcode = format_zipcode(zipcode)
26
+ # Perform request
27
+ response = RestClient.get "#{@api_url}/#{zipcode}/#{number}", {:content_type => :json, :accept => :json, :'Api-Key' => @api_key}
28
+ # Return openstruct output
29
+ res = JSON.parse(response.to_str,{symbolize_names: true})
30
+ OpenStruct.new res[:resource]
31
+ end
32
+
23
33
  def self.format_zipcode(zipcode = nil)
24
34
  if zipcode.nil? || zipcode == ""
25
35
  raise Exception.new("No zipcode provided")
@@ -1,3 +1,3 @@
1
1
  module Postcodeapi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,7 +19,7 @@ describe Postcodeapi do
19
19
  expect { Postcodeapi.format_zipcode("11AA") }.to raise_error
20
20
  end
21
21
 
22
- it 'should return an address result' do
22
+ it 'should return a street result' do
23
23
  VCR.use_cassette('get_street', :allow_playback_repeats => true) do
24
24
  json_response_mock = '{
25
25
  "success": true,
@@ -39,6 +39,29 @@ describe Postcodeapi do
39
39
  end
40
40
  end
41
41
 
42
+ it 'should return an address result' do
43
+ VCR.use_cassette('get_address', :allow_playback_repeats => true) do
44
+ json_response_mock = '{
45
+ "success": true,
46
+ "resource": {
47
+ "street": "Wilhelminapark",
48
+ "house_number":4,
49
+ "postcode": "5041EB",
50
+ "town": "Tilburg",
51
+ "latitude": 51.9401,
52
+ "longitude": 5.61531,
53
+ "x": 133505,
54
+ "y": 397537
55
+ }
56
+ }'
57
+ res = JSON.parse(json_response_mock.to_str,{symbolize_names: true})
58
+ Postcodeapi.get_address("5041EB",4).should eq OpenStruct.new(res[:resource])
59
+ Postcodeapi.get_address("5041EB",4).street.should eq "Wilhelminapark"
60
+ Postcodeapi.get_address("5041EB",4).house_number.should eq 4
61
+
62
+ end
63
+ end
64
+
42
65
 
43
66
  it 'should return correct version string' do
44
67
  Postcodeapi.version_string.should eq "Postcodeapi version #{Postcodeapi::VERSION}"
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ -
4
+ recorded_at: "Mon, 09 Dec 2013 15:02:48 GMT"
5
+ request:
6
+ body:
7
+ encoding: UTF-8
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/json"
12
+ Accept-Encoding:
13
+ - "gzip, deflate"
14
+ Api-Key:
15
+ - 1234567890abcdefghizjklmnopqrstuvwxyz
16
+ User-Agent:
17
+ - Ruby
18
+ method: get
19
+ uri: "http://api.postcodeapi.nu/5041EB/4"
20
+ response:
21
+ body:
22
+ encoding: UTF-8
23
+ string: "{ \"success\": true, \"resource\": { \"street\": \"Wilhelminapark\",\"house_number\":4, \"postcode\": \"5041EB\", \"town\": \"Tilburg\", \"latitude\": 51.9401, \"longitude\": 5.61531, \"x\": 133505, \"y\": 397537 } }"
24
+ headers:
25
+ Alternate-Protocol:
26
+ - "80:quic,80:quic"
27
+ Cache-Control:
28
+ - no-cache
29
+ Content-Type:
30
+ - "application/json; charset=utf-8"
31
+ Date:
32
+ - "Mon, 09 Dec 2013 15:02:48 GMT"
33
+ Server:
34
+ - "Google Frontend"
35
+ Transfer-Encoding:
36
+ - chunked
37
+ Vary:
38
+ - Accept-Encoding
39
+ http_version: ~
40
+ status:
41
+ code: 200
42
+ message: OK
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ww-postcodeapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-12-08 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -141,6 +141,7 @@ files:
141
141
  - postcodeapi.gemspec
142
142
  - spec/lib/postcode_api_spec.rb
143
143
  - spec/spec_helper.rb
144
+ - spec/vcr/get_address.yml
144
145
  - spec/vcr/get_street.yml
145
146
  homepage: https://github.com/martijnschouwe/postcodeapi
146
147
  licenses: []
@@ -169,4 +170,5 @@ summary: Get address details from the postcodeapi.nu api
169
170
  test_files:
170
171
  - spec/lib/postcode_api_spec.rb
171
172
  - spec/spec_helper.rb
173
+ - spec/vcr/get_address.yml
172
174
  - spec/vcr/get_street.yml