Skip to content

Commit

Permalink
Merge pull request #1644 from astoica1986/master
Browse files Browse the repository at this point in the history
Add place_id as a result attribute from amazon_location_service
  • Loading branch information
alexreisner authored Mar 5, 2024
2 parents c41b906 + 86a1c5d commit 0ea4526
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/geocoder/lookups/amazon_location_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def results(query)
client.search_place_index_for_text(params.merge(text: query.text))
end

resp.results.map(&:place)
resp.results
end

private
Expand Down
7 changes: 6 additions & 1 deletion lib/geocoder/results/amazon_location_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Geocoder::Result
class AmazonLocationService < Base
def initialize(result)
@place = result
@place = result.place
super
end

def coordinates
Expand Down Expand Up @@ -53,5 +54,9 @@ def country
def country_code
@place.country
end

def place_id
data.place_id if data.respond_to?(:place_id)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"AQABAFMAf5Cj6ApTW9YHMA3COqc3G1_dNHr1qtFl-W36hTyQd_Jw0f-t-7oaBxmbWd9vNecT3rIiH6O6DJ36qPk7seUIuIp8tOOZDoQnuweFUE5fHjvl15sTbn1PREQwp_66LjvkkubhQ3seXgBrCMZT3rt_dBzubg",
nil,
"USA",
MockAWSPlaceGeometry.new([-74.15434739412053, 40.61681535865544]),
Expand Down
11 changes: 5 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,7 @@ def default_fixture_filename
MockAWSPlace = Struct.new(*%i[
address_number country geometry label municipality neighborhood postal_code region street sub_region
])
class MockAWSPlace
def place
self
end
end
MockAWSResult = Struct.new(:place_id, :place)

class MockAmazonLocationServiceClient
def search_place_index_for_position(params = {}, options = {})
Expand All @@ -578,7 +574,10 @@ def fixture
end

def mock_results
MockResults.new([MockAWSPlace.new(*fixture)])
fixture_copy = fixture.dup
place_id = fixture_copy.shift
place = MockAWSPlace.new(*fixture_copy)
MockResults.new([MockAWSResult.new(place_id, place)])
end

def mock_no_results
Expand Down
5 changes: 5 additions & 0 deletions test/unit/result_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_forward_geocoding_result_has_required_attributes
set_api_key!(l)
result = Geocoder.search("Madison Square Garden").first
assert_result_has_required_attributes(result)
assert_aws_result_supports_place_id(result) if l == :amazon_location_service
end
end

Expand Down Expand Up @@ -56,4 +57,8 @@ def assert_result_has_required_attributes(result)
assert result.country_code.is_a?(String), m % "country_code"
assert_not_nil result.address, m % "address"
end

def assert_aws_result_supports_place_id(result)
assert result.place_id.is_a?(String)
end
end

0 comments on commit 0ea4526

Please sign in to comment.