postcodes_io 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad9cc32017365faafe6c67cf7d18da5aa5010e1b
4
+ data.tar.gz: b04650165b7ec3830d90f1fc5eec3ce617273868
5
+ SHA512:
6
+ metadata.gz: ec45114d531178260c93decbc083b0b4b7d6a02ae45aee0730c6658d18b3b79d0a1b776387099dd6685e6826e9573d51d019f3d1eedc56aaad4277e424408485
7
+ data.tar.gz: 890e6ca0d609aaf1204a6269c6b3426b71e8c2a67d3c06651b40b663cb186238ecacf48f1a1180786f08a1a1cddf168e229b4e076a5dc29fcb947bad7d7c5c8c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in postcodes_io.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,78 @@
1
+ # PostcodesIo
2
+
3
+ A simple wrapper around [postcodes.io](http://postcodes.io/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'postcodes_io'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install postcodes_io
20
+
21
+ ## Usage
22
+
23
+ Require the gem
24
+
25
+ ```ruby
26
+ require 'PostcodesIO'
27
+ ```
28
+
29
+ Create new instance of the Postcode::IO
30
+
31
+ ```ruby
32
+ pio = Postcodes::IO.new
33
+ ```
34
+
35
+ Lookup a postcode
36
+ ```ruby
37
+ postcode = pio.lookup('NN12 8TN')
38
+ ```
39
+
40
+ Inspect the results!
41
+ ```ruby
42
+ postcode.longitude # -1.02144562675883
43
+ postcode.latitude # 52.0776806788868
44
+ ```
45
+
46
+ ##All available fields
47
+
48
+ |name|description|
49
+ |----|-----------|
50
+ |postcode| pretty formatted postcode|
51
+ |quality| 1-9 value of the quality of the grid reference |
52
+ |eastings| OS grid reference |
53
+ |northings | OS grid reference |
54
+ |country | The code for the appropriate country|
55
+ |nhs_ha | The health area code for the postcode |
56
+ |admin_county | The county the postcode has been assigned |
57
+ |admin_district| The current district/unitary authority to which the postcode has been assigned |
58
+ |admin_ward| The current administrative/electoral area to which the postcode has been assigned |
59
+ |longitude| The WGS84 longitude |
60
+ |latitude| The WGS84 latitude |
61
+ |parliamentary_constituency| he Westminster Parliamentary Constituency|
62
+ |european_electoral_region| The European Electoral Region code|
63
+ |primary_care_trust| The code for the Primary Care area |
64
+ |region| [former GORs](http://www.ons.gov.uk/ons/guide-method/geography/beginner-s-guide/administrative/england/government-office-regions/index.html)|
65
+ |parish| The smallest type of administrative area|
66
+ |lsoa| [The 2011 Census lower layer SOA code](http://www.ons.gov.uk/ons/guide-method/geography/beginner-s-guide/census/super-output-areas--soas-/index.html)|
67
+ |msoa| [The 2011 Census middle layer SOA (MSOA) code](The 2011 Census lower layer SOA code for England and Wales](http://www.ons.gov.uk/ons/guide-method/geography/beginner-s-guide/census/super-output-areas--soas-/index.html)|
68
+ |ccg| Clinical Commissioning Group |
69
+ |nuts| [see here](http://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics)|
70
+
71
+ For more details see [the documentation on postcodes.io](http://postcodes.io/docs)
72
+ ## Contributing
73
+
74
+ 1. Fork it ( https://github.com/[my-github-username]/postcodes_io/fork )
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ exec "irb -r postcodes_io -I ./lib"
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'excon'
2
+ require 'json'
3
+ require 'postcodes_io/postcode'
4
+
5
+ module Postcodes
6
+ module Lookup
7
+ def lookup(postcode)
8
+ postcode.gsub!(/\s+/, '') # remove any whitespace. m1 1ab => m11ab
9
+ response = Excon.get("https://api.postcodes.io/postcodes/#{postcode}")
10
+ unless response.status == 404
11
+ parsed_response = JSON.parse(response.body)
12
+ return Postcodes::Postcode.new(parsed_response['result'])
13
+ end
14
+ return nil
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Postcodes
2
+ class Postcode
3
+
4
+ attr_reader :info
5
+
6
+ def initialize(info)
7
+ @info = info
8
+ end
9
+
10
+ # allow accessing info values with dot notation
11
+ def method_missing(name, *args, &block)
12
+ return @info[name] if @info.key? name
13
+ @info.each { |k,v| return v if k.to_s.to_sym == name }
14
+ super.method_missing name
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Postcodes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "postcodes_io/version"
2
+ require "postcodes_io/lookup"
3
+ require "postcodes_io/postcode"
4
+
5
+ module Postcodes
6
+ class IO
7
+ include Lookup
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'postcodes_io/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "postcodes_io"
8
+ spec.version = Postcodes::VERSION
9
+ spec.authors = ["James Ruston"]
10
+ spec.email = ["jruston90@gmail.com"]
11
+ spec.summary = %q{Lookup postcodes}
12
+ spec.description = %q{Get rich data from postcode lookups. Wraps postcodes.io}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+
26
+ spec.add_runtime_dependency "excon", "~> 0.39"
27
+ end
@@ -0,0 +1,27 @@
1
+ {
2
+ "status": 200,
3
+ "result": {
4
+ "postcode": "CM12 9TR",
5
+ "quality": 1,
6
+ "eastings": 567111,
7
+ "northings": 191249,
8
+ "country": "England",
9
+ "nhs_ha": "East of England",
10
+ "admin_county": "Essex",
11
+ "admin_district": "Basildon",
12
+ "admin_ward": "Burstead",
13
+ "longitude": 0.411227930206834,
14
+ "latitude": 51.5953004291798,
15
+ "parliamentary_constituency": "Basildon and Billericay",
16
+ "european_electoral_region": "Eastern",
17
+ "primary_care_trust": "South West Essex",
18
+ "region": "East of England",
19
+ "parish": "Little Burstead",
20
+ "lsoa": "Basildon 009A",
21
+ "msoa": "Basildon 009",
22
+ "nuts": "Burstead",
23
+ "incode": "9TR",
24
+ "outcode": "CM12",
25
+ "ccg": "NHS Basildon and Brentwood CCG"
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Postcodes::IO do
4
+
5
+ let(:base_url) {'https://api.postcodes.io'}
6
+ let(:stub_response) { File.read('spec/fixtures/lookup_response.json') }
7
+
8
+ before :each do
9
+ stub_request(:get, "#{base_url}/postcodes/CM129TR")
10
+ .to_return(status: 200, body: stub_response)
11
+ end
12
+
13
+ describe '#lookup' do
14
+ let(:input) { 'CM12 9TR' }
15
+ let(:output) { subject.lookup(input) }
16
+
17
+ it 'requests a postcode' do
18
+ output
19
+ WebMock.should have_requested(:get, "#{base_url}/postcodes/CM129TR")
20
+ end
21
+
22
+ it 'returns the long and lat' do
23
+ output.longitude.should == 0.411227930206834
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ require 'webmock/rspec'
2
+ require 'postcodes_io'
3
+
4
+ RSpec.configure do |config|
5
+ # The settings below are suggested to provide a good initial experience
6
+ # with RSpec, but feel free to customize to your heart's content.
7
+ =begin
8
+ # These two settings work together to allow you to limit a spec run
9
+ # to individual examples or groups you care about by tagging them with
10
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
11
+ # get run.
12
+ config.filter_run :focus
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ # Many RSpec users commonly either run the entire suite or an individual
16
+ # file, and it's useful to allow more verbose output when running an
17
+ # individual spec file.
18
+ if config.files_to_run.one?
19
+ # Use the documentation formatter for detailed output,
20
+ # unless a formatter has already been configured
21
+ # (e.g. via a command-line flag).
22
+ config.default_formatter = 'doc'
23
+ end
24
+
25
+ # Print the 10 slowest examples and example groups at the
26
+ # end of the spec run, to help surface which specs are running
27
+ # particularly slow.
28
+ config.profile_examples = 10
29
+
30
+ # Run specs in random order to surface order dependencies. If you find an
31
+ # order dependency and want to debug it, you can fix the order by providing
32
+ # the seed, which is printed after each run.
33
+ # --seed 1234
34
+ config.order = :random
35
+
36
+ # Seed global randomization in this process using the `--seed` CLI option.
37
+ # Setting this allows you to use `--seed` to deterministically reproduce
38
+ # test failures related to randomization by passing the same `--seed` value
39
+ # as the one that triggered the failure.
40
+ Kernel.srand config.seed
41
+
42
+ # rspec-expectations config goes here. You can use an alternate
43
+ # assertion/expectation library such as wrong or the stdlib/minitest
44
+ # assertions if you prefer.
45
+ config.expect_with :rspec do |expectations|
46
+ # Enable only the newer, non-monkey-patching expect syntax.
47
+ # For more details, see:
48
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
49
+ expectations.syntax = :expect
50
+ end
51
+
52
+ # rspec-mocks config goes here. You can use an alternate test double
53
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
54
+ config.mock_with :rspec do |mocks|
55
+ # Enable only the newer, non-monkey-patching expect syntax.
56
+ # For more details, see:
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ mocks.syntax = :expect
59
+
60
+ # Prevents you from mocking or stubbing a method that does not exist on
61
+ # a real object. This is generally recommended.
62
+ mocks.verify_partial_doubles = true
63
+ end
64
+ =end
65
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postcodes_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Ruston
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: excon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.39'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.39'
83
+ description: Get rich data from postcode lookups. Wraps postcodes.io
84
+ email:
85
+ - jruston90@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/postcodes_io.rb
97
+ - lib/postcodes_io/lookup.rb
98
+ - lib/postcodes_io/postcode.rb
99
+ - lib/postcodes_io/version.rb
100
+ - postcodes_io.gemspec
101
+ - spec/fixtures/lookup_response.json
102
+ - spec/postcode_io_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Lookup postcodes
128
+ test_files:
129
+ - spec/fixtures/lookup_response.json
130
+ - spec/postcode_io_spec.rb
131
+ - spec/spec_helper.rb