Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Detail API lookup by Mapbox ID #298

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

aokj4ck
Copy link
Contributor

@aokj4ck aokj4ck commented Aug 20, 2024

Description

Fixes SSDK-569

  • Add SearchEngine.select(mapboxID: String, options: DetailsOptions) to invoke a retrieve/ API endpoint call to retreive details from a Mapbox ID.
  • Add DetailsOptions to configure Mapbox ID retrieves for: AttributeSets, Language, Worldview

Checklist

  • Update CHANGELOG

… Mapbox ID

- Refine documentation
- SearchEngine.search and SearchEngine.select are a two-step combination
- Stop wrapping SearchEngine.retrieve(mapboxID:) in an over-loaded SearchEngine.select wrapper
- Mark SearchEngine.retrieve(mapboxID:) public as the main and only way to query Details API / Mapbox ID
@aokj4ck aokj4ck marked this pull request as ready for review August 23, 2024 20:00
@aokj4ck aokj4ck requested review from a team as code owners August 23, 2024 20:00
@aokj4ck aokj4ck requested review from mikeringrose and Udumft August 23, 2024 20:00
@aokj4ck aokj4ck marked this pull request as draft August 26, 2024 20:59
…569-add-Detail-API-lookup-by-mapbox_id

Conflicts:
	MapboxSearch.xcodeproj/project.pbxproj
	Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift
	Sources/MapboxSearch/PublicAPI/ServiceProvider.swift
	Tests/MapboxSearchTests/Legacy/SearchEngineTests.swift
@aokj4ck aokj4ck marked this pull request as ready for review January 7, 2025 21:02
Comment on lines +284 to +288
func retrieveDetails(
for mapboxId: String,
options: CoreDetailsOptions,
completion: @escaping CoreSearchResponseCompletion
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed here to return the request id to match the rest of the implementations?

Suggested change
func retrieveDetails(
for mapboxId: String,
options: CoreDetailsOptions,
completion: @escaping CoreSearchResponseCompletion
) {
@discardableResult
func retrieveDetails(
for mapboxId: String,
options: CoreDetailsOptions,
completion: @escaping CoreSearchResponseCompletion
) -> UInt64 {


guard let result = responseResult.results.first else {
let errorMessage = "Could not retrieve details result."
assertionFailure(errorMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to add assertionFailure here. It does not look like a good practice when a possible backend error triggers the debug crash.

It's better to report error here

/// - Parameters:
/// - mapboxID: The Mapbox ID for a known POI. Mapbox IDs will be returned in Search responses and may be cached.
/// - detailsOptions: Options to configure this query. May be nil.
public func retrieve(mapboxID: String, options detailsOptions: DetailsOptions? = DetailsOptions()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the parameter detailsOptions be non-optional? Currently, there are 2 places, where the default value is provided. But it could be changed to only 1 place in the method definition if the parameter is non-optional.

switch response.process() {
case .success(let responseResult):
// Response Info is not supported for retrieving by Details API at this time.
responseInfo = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responseInfo is used to report user Feedback to the Telemetry. Could you please elaborate on why we need to reset the responseInfo after retrieve(mapboxID:options:) execution? The app user still can send feedback

/// Besides the basic metadata attributes, developers can request additional
/// attributes by setting attribute_sets parameter with attribute set values,
/// for example &attribute_sets=basic,photos,visit.
/// The requested metadata will be provided in metadata object in the response.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the DocC reference to the mentioned metadata property to simplify the understanding where the result can be found


/// The two digit ISO country code (such as 'JP') to request a worldview for the location data, if applicable data
/// is available.
/// This parameters will only be applicable for Boundaries and Places feature types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on what are Boundaries and Places types? Are these any Search SDK types?

@@ -91,7 +91,5 @@ class ServerSearchResult: SearchResult, SearchResultSuggestion, CoreResponseProv
self.brandID = coreResult.brandID

assert(!id.isEmpty)
assert(!name.isEmpty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a valid search response with an empty name?

XCTAssertNotNil(result.routablePoints?.first)

XCTAssertNil(metadata.children)
XCTAssertNotNil(metadata.primaryImage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that the response is provided from the local file Tests/MockData/search-box/search-box-retrieve-mapbox-id.json? Why not test the exact values then? It is an integrating test, it would be more useful if it would help to catch the problems in filling specific metadata fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants