ruby-postcodeanywhere 0.0.2 → 0.0.10
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/VERSION +1 -1
- data/lib/ruby-postcodeanywhere.rb +76 -90
- data/ruby-postcodeanywhere.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
@@ -2,10 +2,10 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module PostcodeAnywhere
|
4
4
|
|
5
|
-
ADDRESS_LOOKUP = "
|
6
|
-
ADDRESS_FETCH = "
|
5
|
+
ADDRESS_LOOKUP = "https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/xmla.ws"
|
6
|
+
ADDRESS_FETCH = "https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveById/v1.20/xmla.ws"
|
7
7
|
|
8
|
-
RETRIEVE_BY_PARTS_URL = "
|
8
|
+
RETRIEVE_BY_PARTS_URL = "https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByParts/v1.00/xmla.ws"
|
9
9
|
|
10
10
|
# Account codes to access the PostcodeAnywhere Service
|
11
11
|
mattr_accessor :account_code
|
@@ -22,112 +22,98 @@ module PostcodeAnywhere
|
|
22
22
|
include HTTParty
|
23
23
|
format :xml
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
self.fetch_id = args[:fetch_id]
|
31
|
-
end
|
32
|
-
|
33
|
-
def lookup
|
34
|
-
data = PostcodeSearch.get self.lookup_url
|
25
|
+
def lookup(postcode)
|
26
|
+
options={ "SearchTerm" => postcode }
|
27
|
+
options.merge!(self.license_information)
|
28
|
+
|
29
|
+
data = PostcodeSearch.get( ADDRESS_LOOKUP, {:query => options} )
|
35
30
|
formatted_data = []
|
36
|
-
|
37
|
-
|
31
|
+
|
32
|
+
raise 'No Data Found' if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
|
33
|
+
|
34
|
+
unless data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
|
35
|
+
data.parsed_response["Table"]["Rows"]["Row"].each do |item|
|
36
|
+
data_item = AddressListItem.new
|
37
|
+
data_item.id = item['Id']
|
38
|
+
data_item.street_address = item['StreetAddress']
|
39
|
+
data_item.place = item['Place']
|
40
|
+
|
41
|
+
formatted_data << data_item
|
42
|
+
end
|
38
43
|
end
|
39
44
|
formatted_data
|
40
45
|
end
|
41
46
|
|
42
|
-
def fetch_by_parts
|
43
|
-
|
44
|
-
formatted_data = data["NewDataSet"]["Data"]
|
45
|
-
@address_lookup = AddressLookup.new
|
47
|
+
def fetch_by_parts(options={})
|
48
|
+
options.merge!(self.license_information)
|
46
49
|
|
47
|
-
if
|
48
|
-
|
49
|
-
@address_lookup.address_line_1 = formatted_data["line1"]
|
50
|
-
@address_lookup.address_line_2 = formatted_data["line2"]
|
51
|
-
@address_lookup.address_line_3 = formatted_data["line3"]
|
52
|
-
@address_lookup.post_town = formatted_data["post_town"]
|
53
|
-
@address_lookup.county = formatted_data["county"].blank? ? formatted_data["post_town"] : formatted_data["county"]
|
50
|
+
if options['postcode']
|
51
|
+
options['postcode'] = options['postcode'].gsub(/\s/, '')
|
54
52
|
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def fetch
|
60
|
-
data = PostcodeSearch.get self.fetch_url
|
61
|
-
formatted_data = data["NewDataSet"]["Data"]
|
62
|
-
@address_lookup = AddressLookup.new
|
63
|
-
if self.country_code == 'GB'
|
64
|
-
@address_lookup.postcode = formatted_data["postcode"]
|
65
|
-
@address_lookup.address_line_1 = formatted_data["line1"]
|
66
|
-
@address_lookup.address_line_2 = formatted_data["line2"]
|
67
|
-
@address_lookup.address_line_3 = formatted_data["line3"]
|
68
|
-
@address_lookup.post_town = formatted_data["post_town"]
|
69
|
-
@address_lookup.county = formatted_data["county"].blank? ? formatted_data["post_town"] : formatted_data["county"]
|
70
|
-
elsif self.country_code == 'US'
|
71
|
-
@address_lookup.postcode = formatted_data["zip4"].blank? ? @postcode_search.postcode : formatted_data["zip4"]
|
72
|
-
@address_lookup.address_line_1 = formatted_data["line1"]
|
73
|
-
@address_lookup.address_line_2 = formatted_data["line2"]
|
74
|
-
@address_lookup.address_line_3 = formatted_data["line3"]
|
75
|
-
@address_lookup.post_town = formatted_data["city"]
|
76
|
-
@address_lookup.county = formatted_data["county_name"]+", "+formatted_data["state"]
|
77
|
-
else
|
78
|
-
|
79
|
-
end
|
80
|
-
@address_lookup
|
81
|
-
end
|
82
|
-
|
83
|
-
def lookup_url
|
84
|
-
ADDRESS_LOOKUP+"?"+self.lookup_type+"&"+self.postcode_with_no_spaces+self.selected_country+"&"+self.license_information
|
85
|
-
end
|
86
|
-
|
87
|
-
def fetch_by_parts_url
|
88
|
-
RETRIEVE_BY_PARTS_URL+"&"+self.address_building+"&"+self.address_fetch_id+self.selected_country+"&"+self.license_information
|
89
|
-
end
|
90
|
-
|
91
|
-
def selected_country
|
92
|
-
if self.country_code == "GB"
|
93
|
-
""
|
94
|
-
else
|
95
|
-
"&country="+self.country_code
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def address_fetch_id
|
100
|
-
"id="+self.fetch_id
|
101
|
-
end
|
102
|
-
|
103
|
-
def address_building
|
104
|
-
"building="+self.building
|
105
|
-
end
|
106
|
-
|
107
|
-
def lookup_type
|
108
|
-
if self.country_code == "GB"
|
109
|
-
"action=lookup&type=by_postcode"
|
110
|
-
elsif self.country_code == "US"
|
111
|
-
"action=lookup&type=by_zip"
|
112
|
-
else
|
113
|
-
"action=international&type=fetch_streets"
|
114
|
-
end
|
54
|
+
data = PostcodeSearch.get( RETRIEVE_BY_PARTS_URL, {:query => options} )
|
55
|
+
|
56
|
+
process_address(data)
|
115
57
|
end
|
116
58
|
|
117
|
-
def
|
118
|
-
|
59
|
+
def fetch(id)
|
60
|
+
options={ :id => id }
|
61
|
+
options.merge!(self.license_information)
|
62
|
+
|
63
|
+
data = PostcodeSearch.get( ADDRESS_FETCH, {:query => options} )
|
64
|
+
|
65
|
+
process_address(data)
|
119
66
|
end
|
120
67
|
|
121
68
|
def license_information
|
122
|
-
|
69
|
+
{:account_code => PostcodeAnywhere.account_code, :license_code => PostcodeAnywhere.license_code}
|
123
70
|
end
|
71
|
+
|
72
|
+
|
73
|
+
private
|
74
|
+
def process_address(data)
|
75
|
+
|
76
|
+
raise 'No Data Found' if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
|
77
|
+
|
78
|
+
formatted_data = data.parsed_response["Table"]["Rows"]["Row"]
|
79
|
+
|
80
|
+
address_lookup = AddressLookup.new
|
81
|
+
|
82
|
+
address_lookup.mailsort = formatted_data["Mailsort"]
|
83
|
+
address_lookup.barcode = formatted_data["Barcode"]
|
84
|
+
address_lookup.type = formatted_data["Type"]
|
85
|
+
|
86
|
+
address_lookup.udprn = formatted_data["Udprn"]
|
87
|
+
address_lookup.company = formatted_data["Company"]
|
88
|
+
address_lookup.department = formatted_data["Department"]
|
89
|
+
address_lookup.postcode = formatted_data["Postcode"]
|
90
|
+
address_lookup.address_line_1 = formatted_data["Line1"]
|
91
|
+
address_lookup.address_line_2 = formatted_data["Line2"]
|
92
|
+
address_lookup.address_line_3 = formatted_data["Line3"]
|
93
|
+
address_lookup.address_line_4 = formatted_data["Line4"]
|
94
|
+
address_lookup.address_line_5 = formatted_data["Line5"]
|
95
|
+
address_lookup.post_town = formatted_data["PostTown"]
|
96
|
+
address_lookup.county = formatted_data["County"].blank? ? formatted_data["PostTown"] : formatted_data["County"]
|
97
|
+
|
98
|
+
|
99
|
+
address_lookup
|
100
|
+
end
|
101
|
+
|
124
102
|
|
125
103
|
end
|
126
104
|
|
127
105
|
class AddressLookup
|
128
106
|
|
129
|
-
attr_accessor :postcode, :address_line_1, :address_line_2, :address_line_3, :
|
130
|
-
attr_accessor :city, :county_name, :zip4, :state
|
107
|
+
attr_accessor :postcode, :address_line_1, :address_line_2, :address_line_3, :address_line_4, :address_line_5
|
108
|
+
attr_accessor :post_town, :county, :city, :county_name, :zip4, :state, :udprn, :company, :department
|
109
|
+
attr_accessor :mailsort, :barcode, :type
|
131
110
|
|
111
|
+
end
|
112
|
+
|
113
|
+
class AddressListItem
|
114
|
+
|
115
|
+
attr_accessor :id, :street_address, :place
|
116
|
+
|
132
117
|
end
|
118
|
+
|
133
119
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ruby-postcodeanywhere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Norman
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
hash:
|
106
|
+
hash: 3507365170554414100
|
107
107
|
segments:
|
108
108
|
- 0
|
109
109
|
version: "0"
|