lib/parcel_api/address.rb in parcel_api-0.4.1 vs lib/parcel_api/address.rb in parcel_api-1.0.0
- old
+ new
@@ -19,13 +19,12 @@
# @param [Integer] number of search results to return (max 10)
# @return [Array] array of addresses
def search(query, count=10)
return [] if query.length < 4
-
- response = @connection.get DOMESTIC_URL, { q: query, count: count }
- addresses = response.body['addresses'].each do |a|
+ response = @connection.get DOMESTIC_URL, params: { q: query, count: count }
+ addresses = response.parsed['addresses'].each do |a|
a['address_id'] = Integer(a['address_id'])
a['dpid'] = Integer(a['dpid']) if a['dpid']
end
addresses.map {|address| OpenStruct.new(address)}
end
@@ -35,11 +34,11 @@
# @return address detail object
def details(address_id)
details_url = File.join(DOMESTIC_URL, address_id.to_s)
response = @connection.get details_url
- OpenStruct.new(response.body['address'])
+ OpenStruct.new(response.parsed['address'])
end
# Search for an Australian Address
# @param [String] characters to search for
# @param [Integer] number of search results to return (max 10)
@@ -54,11 +53,11 @@
# @return australian address detail
def australian_details(address_id)
details_url = File.join(AUSTRALIAN_URL, address_id.to_s)
response = @connection.get details_url
- RecursiveOpenStruct.new(response.body['address'], recurse_over_arrays: true)
+ RecursiveOpenStruct.new(response.parsed['address'], recurse_over_arrays: true)
end
# Search for an International Address
# @param [String] characters to search for
# @param [Integer] number of search results to return (max 10)
@@ -66,21 +65,21 @@
# @return [Array] array of international addresses
def international_search(query, count=5, country_code=nil)
return [] if query.length < 4
- response = @connection.get INTERNATIONAL_URL, { q: query, count: count, country_code: country_code }
- response.body['addresses'].map {|address| OpenStruct.new(address)}
+ response = @connection.get INTERNATIONAL_URL, params: { q: query, count: count, country_code: country_code }
+ response.parsed['addresses'].map {|address| OpenStruct.new(address)}
end
# Return international address details for a specific international address id
# @param address_id [String]
# @return international address detail
def international_details(address_id)
details_url = File.join(INTERNATIONAL_URL, address_id.to_s)
response = @connection.get details_url
- RecursiveOpenStruct.new(response.body['result'], recurse_over_arrays: true)
+ RecursiveOpenStruct.new(response.parsed['result'], recurse_over_arrays: true)
end
end
end