postcode_anywhere 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,4 @@
1
+ Postcode Anywhere
2
+ =================
3
+
4
+ A simple plugin for Rails 3 to find addresses by postcode and building number using the Postcode Anywhere service.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rake/gempackagetask'
2
+ PKG_FILES = FileList[
3
+ '[a-zA-Z]*',
4
+ 'generators/**/*',
5
+ 'lib/**/*',
6
+ 'rails/**/*',
7
+ 'tasks/**/*',
8
+ 'test/**/*'
9
+ ]
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.name = "postcode_anywhere"
13
+ s.version = "0.1"
14
+ s.author = "Matthew Crouch"
15
+ s.email = "mcrouch@mobilezil.la"
16
+ s.homepage = "http://mobilezil.la/"
17
+ s.platform = Gem::Platform::RUBY
18
+ s.summary = "Find addresses by postcode and building number via Postcode Anywhere API"
19
+ s.files = PKG_FILES.to_a
20
+ s.require_path = "lib"
21
+ s.has_rdoc = false
22
+ s.extra_rdoc_files = ["README.markdown"]
23
+ s.add_dependency("httparty", "~> 0.7.7")
24
+ end
25
+
26
+ desc 'Turn this plugin into a gem.'
27
+ Rake::GemPackageTask.new(spec) do |pkg|
28
+ pkg.gem_spec = spec
29
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "postcode_anywhere"
@@ -0,0 +1,39 @@
1
+ require "httparty"
2
+ module PostcodeAnywhere
3
+
4
+ SERVICE_ADDRESS = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByPostcodeAndBuilding/v1.00/xmle.ws"
5
+
6
+ include HTTParty
7
+ format :xml
8
+
9
+ class << self
10
+
11
+ attr_accessor :key
12
+
13
+ def license_key
14
+ @key
15
+ end
16
+ end
17
+
18
+ def self.find_by_number_and_postcode(number, postcode)
19
+ PostcodeAnywhere.validate_key
20
+ sanitised_postcode = postcode.gsub(/\s/, "")
21
+ data = PostcodeAnywhere.lookup(number, sanitised_postcode)
22
+ data["Table"]["Row"]
23
+ end
24
+
25
+ protected
26
+
27
+ def self.validate_key
28
+ unless PostcodeAnywhere.key
29
+ raise PostcodeAnywhereException, "Please provide a valid Postcode Anywhere License Key"
30
+ end
31
+ end
32
+
33
+ def self.lookup(number, postcode)
34
+ PostcodeAnywhere.get SERVICE_ADDRESS+"?Key=#{PostcodeAnywhere.key}&Postcode=#{postcode}&Building=#{number}"
35
+ end
36
+
37
+ class PostcodeAnywhereException < StandardError;end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postcode_anywhere
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Matthew Crouch
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-05-31 00:00:00 +01:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: httparty
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 7
30
+ - 7
31
+ version: 0.7.7
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description:
35
+ email: mcrouch@mobilezil.la
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.markdown
42
+ files:
43
+ - init.rb
44
+ - Rakefile
45
+ - README.markdown
46
+ - lib/postcode_anywhere.rb
47
+ has_rdoc: true
48
+ homepage: http://mobilezil.la/
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Find addresses by postcode and building number via Postcode Anywhere API
79
+ test_files: []
80
+