eircode 1.0.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: 539c8f5ba64069a78cbe09f59e5c5666a564a4c1
4
+ data.tar.gz: 48a8bce650078a856fa3f37981bb1a7775c765f1
5
+ SHA512:
6
+ metadata.gz: 2784ca413876cb3dd2c1eb190d05679d0376b4504183480205c22a8909f81e84d2ce4694dc877ac5916f81f7c34e0edab662cd0edfcd1fc0de899f2e49b8c1d5
7
+ data.tar.gz: e748665125ae3156150906cd09c6de7d91cb849dabdfbc2b1a85af264949745cf9aa5f8541beea42ad72843bc0eb0d256a06e1058e209abf2de46ad4d386bbff
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 eircode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Colm McBarron
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,29 @@
1
+ # Eircode
2
+
3
+ Simple Gem to wrap the public Eircode API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eircode'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eircode
18
+
19
+ ## Usage
20
+
21
+ Use at your own risk!
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/eircode/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/eircode.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eircode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eircode"
8
+ spec.version = Eircode::VERSION
9
+ spec.authors = ["Colm McBarron"]
10
+ spec.email = ["colm.mcbarron@eachandother.com"]
11
+ spec.summary = %q{Gem to wrap/hack the Eircode API}
12
+ spec.description = %q{Gem to wrap/hack the Eircode API}
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.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "webmock"
24
+ spec.add_development_dependency "vcr"
25
+
26
+
27
+
28
+ spec.add_dependency "faraday"
29
+ spec.add_dependency "json"
30
+ end
data/lib/eircode.rb ADDED
@@ -0,0 +1,51 @@
1
+ require_relative "eircode/version"
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+
6
+ SEARCH_URL = "https://finder-api.eircode.ie/api/autocomplete/en?key=874d0fd8-d94a-418a-8089-5d901019f88c&addressline="
7
+
8
+ module Eircode
9
+
10
+ class Address
11
+ def self.search(query)
12
+ response = Faraday.get("#{SEARCH_URL}#{query}")
13
+ result_hash = JSON.parse(response.body)
14
+ results = Results.new(result_hash)
15
+ return results
16
+ end
17
+ end
18
+
19
+ class Results
20
+
21
+ attr_accessor :total_matches
22
+ attr_accessor :addresses
23
+
24
+ def initialize(result_hash)
25
+ @total_matches = result_hash["totalMatches"]
26
+ addresses = result_hash["addresses"]
27
+ if addresses.nil?
28
+ @addresses = nil
29
+ else
30
+ @addresses = []
31
+ addresses.each do |a|
32
+ address = Address.new(a)
33
+ @addresses << address;
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ class Address
40
+ attr_accessor :id
41
+ attr_accessor :address
42
+ attr_accessor :unique
43
+
44
+ def initialize(address_hash)
45
+ @id = address_hash['id']
46
+ @address = address_hash['address']
47
+ @unique = address_hash['unique']
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module Eircode
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ require './test/test_helper'
2
+
3
+ class EircodeAddressTest < Minitest::Test
4
+ def test_exists
5
+ assert Eircode::Address
6
+ end
7
+
8
+ def test_it_gives_back_too_many_addresses
9
+ VCR.use_cassette('too_many_addresses') do
10
+ results = Eircode::Address.search("priory")
11
+ assert_equal Eircode::Results, results.class
12
+ assert_equal 137, results.total_matches
13
+ assert_equal nil, results.addresses
14
+ end
15
+ end
16
+
17
+ def test_it_gives_back_no_addresses
18
+ VCR.use_cassette('no_addresses') do
19
+ results = Eircode::Address.search("sdsdsdsdsdsd")
20
+ assert_equal Eircode::Results, results.class
21
+ assert_equal 0, results.total_matches
22
+ assert_equal nil, results.addresses
23
+ end
24
+ end
25
+
26
+ def test_it_gives_back_some_addresses
27
+ VCR.use_cassette('some_addresses') do
28
+ results = Eircode::Address.search("the priory dublin")
29
+ assert_equal Eircode::Results, results.class
30
+ assert_equal 10, results.total_matches
31
+ assert_equal Array, results.addresses.class
32
+ first_address = results.addresses.first
33
+ assert_equal Eircode::Address, first_address.class
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://finder-api.eircode.ie/api/autocomplete/en?addressline=sdsdsdsdsdsd&key=874d0fd8-d94a-418a-8089-5d901019f88c
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Tue, 14 Jul 2015 13:39:29 GMT
27
+ Expires:
28
+ - '-1'
29
+ Pragma:
30
+ - no-cache
31
+ Content-Length:
32
+ - '47'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: "{\r\n \"totalMatches\": 0,\r\n \"addresses\": null\r\n}"
38
+ http_version:
39
+ recorded_at: Tue, 14 Jul 2015 13:40:00 GMT
40
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://finder-api.eircode.ie/api/autocomplete/en?addressline=the%20priory%20dublin&key=874d0fd8-d94a-418a-8089-5d901019f88c
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Tue, 14 Jul 2015 13:39:31 GMT
27
+ Expires:
28
+ - '-1'
29
+ Pragma:
30
+ - no-cache
31
+ Content-Length:
32
+ - '1589'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: "{\r\n \"totalMatches\": 10,\r\n \"addresses\": [\r\n {\r\n \"id\":
38
+ \"01b32136-5fbf-4081-a1bb-d5b1a223ecee\",\r\n \"address\": \"THE PRIORY,
39
+ KILTIPPER ROAD, DUBLIN 24\",\r\n \"unique\": true\r\n },\r\n {\r\n
40
+ \ \"id\": \"c7dc8456-cf3e-400b-bde2-416f503ac5b7\",\r\n \"address\":
41
+ \"THE PRIORY, GREENHILLS ROAD, DUBLIN 24\",\r\n \"unique\": true\r\n
42
+ \ },\r\n {\r\n \"id\": \"0177810a-0b4f-48a5-a871-c45509ea6eef\",\r\n
43
+ \ \"address\": \"THE PRIORY, MONKSTOWN ROAD, MONKSTOWN, BLACKROCK, CO.
44
+ DUBLIN\",\r\n \"unique\": true\r\n },\r\n {\r\n \"id\": \"ccd790dc-9063-417f-83b2-a36932c358a2\",\r\n
45
+ \ \"address\": \"THE PRIORY, 409 STILLORGAN ROAD, BLACKROCK, CO. DUBLIN\",\r\n
46
+ \ \"unique\": true\r\n },\r\n {\r\n \"id\": \"740bef43-35b7-4625-a85b-f17c9c8ad9a8\",\r\n
47
+ \ \"address\": \"THE PRIORY, DUBLIN 16\",\r\n \"unique\": false\r\n
48
+ \ },\r\n {\r\n \"id\": \"7e6056fd-6f05-48d8-a9d7-e64daef946d0\",\r\n
49
+ \ \"address\": \"THE PRIORY, JOHN STREET, DUBLIN 8\",\r\n \"unique\":
50
+ true\r\n },\r\n {\r\n \"id\": \"d7697fe7-41a6-4404-8014-d316366e12c6\",\r\n
51
+ \ \"address\": \"THE PRIORY, DONABATE, CO. DUBLIN\",\r\n \"unique\":
52
+ false\r\n },\r\n {\r\n \"id\": \"e55c2834-fc38-4295-9877-989947fadf64\",\r\n
53
+ \ \"address\": \"THE PRIORY, MAIN STREET, MALAHIDE, CO. DUBLIN\",\r\n
54
+ \ \"unique\": false\r\n },\r\n {\r\n \"id\": \"3aa59f89-b7fd-4faa-8d21-a6f94080da60\",\r\n
55
+ \ \"address\": \"THE PRIORY, DUBLIN 7\",\r\n \"unique\": false\r\n
56
+ \ },\r\n {\r\n \"id\": \"0ec9cbfd-8654-4c5c-85fb-51d29116fce8\",\r\n
57
+ \ \"address\": \"THE PRIORY CLINIC, 17/18 PRIORY HALL, STILLORGAN ROAD,
58
+ BLACKROCK, CO. DUBLIN\",\r\n \"unique\": true\r\n }\r\n ]\r\n}"
59
+ http_version:
60
+ recorded_at: Tue, 14 Jul 2015 13:40:00 GMT
61
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://finder-api.eircode.ie/api/autocomplete/en?addressline=priory&key=874d0fd8-d94a-418a-8089-5d901019f88c
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Tue, 14 Jul 2015 13:39:26 GMT
27
+ Expires:
28
+ - '-1'
29
+ Pragma:
30
+ - no-cache
31
+ Content-Length:
32
+ - '49'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: "{\r\n \"totalMatches\": 137,\r\n \"addresses\": null\r\n}"
38
+ http_version:
39
+ recorded_at: Tue, 14 Jul 2015 13:40:00 GMT
40
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,9 @@
1
+ require './lib/eircode'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = "test/fixtures"
8
+ c.hook_into :webmock
9
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eircode
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Colm McBarron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-14 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
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: vcr
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: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Gem to wrap/hack the Eircode API
98
+ email:
99
+ - colm.mcbarron@eachandother.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - eircode.gemspec
110
+ - lib/eircode.rb
111
+ - lib/eircode/version.rb
112
+ - test/address/address_test.rb
113
+ - test/fixtures/no_addresses.yml
114
+ - test/fixtures/some_addresses.yml
115
+ - test/fixtures/too_many_addresses.yml
116
+ - test/test_helper.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.3
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Gem to wrap/hack the Eircode API
141
+ test_files:
142
+ - test/address/address_test.rb
143
+ - test/fixtures/no_addresses.yml
144
+ - test/fixtures/some_addresses.yml
145
+ - test/fixtures/too_many_addresses.yml
146
+ - test/test_helper.rb