ruby-postcodeanywhere 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "httparty"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.3.0"
12
+ gem "bundler"
13
+ gem "jeweler", "~> 1.6.2"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ diff-lcs (1.1.2)
6
+ git (1.2.5)
7
+ httparty (0.7.8)
8
+ crack (= 0.1.8)
9
+ jeweler (1.6.2)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rake (0.9.2)
14
+ rcov (0.9.9)
15
+ rspec (2.3.0)
16
+ rspec-core (~> 2.3.0)
17
+ rspec-expectations (~> 2.3.0)
18
+ rspec-mocks (~> 2.3.0)
19
+ rspec-core (2.3.1)
20
+ rspec-expectations (2.3.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.3.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler
29
+ httparty
30
+ jeweler (~> 1.6.2)
31
+ rcov
32
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Chris Norman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>documents</key>
6
+ <array/>
7
+ <key>fileHierarchyDrawerWidth</key>
8
+ <integer>200</integer>
9
+ <key>metaData</key>
10
+ <dict/>
11
+ <key>showFileHierarchyDrawer</key>
12
+ <true/>
13
+ <key>windowFrame</key>
14
+ <string>{{413, 35}, {987, 817}}</string>
15
+ </dict>
16
+ </plist>
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ruby-postcodeanywhere
2
+
3
+ Ruby gem exposing the functionality of PostcodeAnywhere web services (specifically PAF related service)
4
+
5
+ == Contributing to ruby-postcodeanywhere
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Chris Norman. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "ruby-postcodeanywhere"
19
+ gem.homepage = "http://github.com/intothefire/ruby-postcodeanywhere"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Gem to provide basic access to PostcodeAnywhere services}
22
+ gem.description = %Q{Gem to provide basic access to PostcodeAnywhere services}
23
+ gem.email = "chris@norman.me"
24
+ gem.authors = ["Chris Norman"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "ruby-postcodeanywhere #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,112 @@
1
+ require 'httparty'
2
+
3
+ module PostcodeAnywhere
4
+
5
+ ADDRESS_LOOKUP = "http://services.postcodeanywhere.co.uk/xml.aspx"
6
+ ADDRESS_FETCH = "http://services.postcodeanywhere.co.uk/dataset.aspx?action=fetch"
7
+
8
+ # Account codes to access the PostcodeAnywhere Service
9
+ mattr_accessor :account_code
10
+ @@account_code = "TEST"
11
+ mattr_accessor :license_code
12
+ @@license_code = "TEST"
13
+
14
+ # Default way to setup Devise. Run rails generate devise_install to create
15
+ # a fresh initializer with all configuration values.
16
+ def self.setup
17
+ yield self
18
+ end
19
+
20
+ class PostcodeSearch
21
+
22
+ include HTTParty
23
+ format :xml
24
+
25
+ attr_accessor :postcode, :country_code, :fetch_id
26
+
27
+ def initialize(args={})
28
+ self.postcode = args[:postcode]
29
+ self.country_code = args[:country_code]
30
+ self.fetch_id = args[:fetch_id]
31
+ end
32
+
33
+ def lookup
34
+ data = PostcodeSearch.get self.lookup_url
35
+ formatted_data = []
36
+ unless data["PostcodeAnywhere"]["Schema"]["Field"][0]["Name"] == "error_number"
37
+ formatted_data = data["PostcodeAnywhere"]["Data"]["Item"]
38
+ end
39
+ formatted_data
40
+ end
41
+
42
+ def fetch
43
+ data = PostcodeSearch.get self.fetch_url
44
+ formatted_data = data["NewDataSet"]["Data"]
45
+ @address_lookup = AddressLookup.new
46
+ if self.country_code == 'GB'
47
+ @address_lookup.postcode = formatted_data["postcode"]
48
+ @address_lookup.address_line_1 = formatted_data["line1"]
49
+ @address_lookup.address_line_2 = formatted_data["line2"]
50
+ @address_lookup.address_line_3 = formatted_data["line3"]
51
+ @address_lookup.post_town = formatted_data["post_town"]
52
+ @address_lookup.county = formatted_data["county"].blank? ? formatted_data["post_town"] : formatted_data["county"]
53
+ elsif self.country_code == 'US'
54
+ @address_lookup.postcode = formatted_data["zip4"].blank? ? @postcode_search.postcode : formatted_data["zip4"]
55
+ @address_lookup.address_line_1 = formatted_data["line1"]
56
+ @address_lookup.address_line_2 = formatted_data["line2"]
57
+ @address_lookup.address_line_3 = formatted_data["line3"]
58
+ @address_lookup.post_town = formatted_data["city"]
59
+ @address_lookup.county = formatted_data["county_name"]+", "+formatted_data["state"]
60
+ else
61
+
62
+ end
63
+ @address_lookup
64
+ end
65
+
66
+ def lookup_url
67
+ ADDRESS_LOOKUP+"?"+self.lookup_type+"&"+self.postcode_with_no_spaces+self.selected_country+"&"+self.license_information
68
+ end
69
+
70
+ def fetch_url
71
+ ADDRESS_FETCH+"&"+self.address_fetch_id+self.selected_country+"&"+self.license_information
72
+ end
73
+
74
+ def selected_country
75
+ if self.country_code == "GB"
76
+ ""
77
+ else
78
+ "&country="+self.country_code
79
+ end
80
+ end
81
+
82
+ def address_fetch_id
83
+ "id="+self.fetch_id
84
+ end
85
+
86
+ def lookup_type
87
+ if self.country_code == "GB"
88
+ "action=lookup&type=by_postcode"
89
+ elsif self.country_code == "US"
90
+ "action=lookup&type=by_zip"
91
+ else
92
+ "action=international&type=fetch_streets"
93
+ end
94
+ end
95
+
96
+ def postcode_with_no_spaces
97
+ (self.country_code=="US" ? "zip=" : "postcode=")+self.postcode.gsub(/\s/, '')
98
+ end
99
+
100
+ def license_information
101
+ "account_code="+PostcodeAnywhere.account_code+"&license_code="+PostcodeAnywhere.license_code
102
+ end
103
+
104
+ end
105
+
106
+ class AddressLookup
107
+
108
+ attr_accessor :postcode, :address_line_1, :address_line_2, :address_line_3, :post_town, :county
109
+ attr_accessor :city, :county_name, :zip4, :state
110
+
111
+ end
112
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruby-postcodeanywhere}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Chris Norman}]
12
+ s.date = %q{2011-06-22}
13
+ s.description = %q{Gem to provide basic access to PostcodeAnywhere services}
14
+ s.email = %q{chris@norman.me}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "Postcode Anywhere.tmproj",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/ruby-postcodeanywhere.rb",
30
+ "ruby-postcodeanywhere.gemspec",
31
+ "spec/ruby-postcodeanywhere_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/intothefire/ruby-postcodeanywhere}
35
+ s.licenses = [%q{MIT}]
36
+ s.require_paths = [%q{lib}]
37
+ s.rubygems_version = %q{1.8.5}
38
+ s.summary = %q{Gem to provide basic access to PostcodeAnywhere services}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
46
+ s.add_development_dependency(%q<bundler>, [">= 0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
48
+ s.add_development_dependency(%q<rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<httparty>, [">= 0"])
51
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_dependency(%q<bundler>, [">= 0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<httparty>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<bundler>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RubyPostcodeanywhere" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ruby-postcodeanywhere'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-postcodeanywhere
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Chris Norman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-22 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.2
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ description: Gem to provide basic access to PostcodeAnywhere services
71
+ email: chris@norman.me
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - LICENSE.txt
78
+ - README.rdoc
79
+ files:
80
+ - .document
81
+ - .rspec
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - Postcode Anywhere.tmproj
86
+ - README.rdoc
87
+ - Rakefile
88
+ - VERSION
89
+ - lib/ruby-postcodeanywhere.rb
90
+ - ruby-postcodeanywhere.gemspec
91
+ - spec/ruby-postcodeanywhere_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: http://github.com/intothefire/ruby-postcodeanywhere
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 4470715333765892693
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.5
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Gem to provide basic access to PostcodeAnywhere services
123
+ test_files: []
124
+