-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aws-geospatial#8 from makeen-project/ALMS-133
ALMS-133, ALMS-141 Generic HTTP client created and reverse geocoding API added
- Loading branch information
Showing
23 changed files
with
403 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
library/src/main/java/software/amazon/location/auth/CognitoCredentialsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...auth/data/request/GetCredentialRequest.kt → ...ata/model/request/GetCredentialRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...auth/data/request/GetIdentityIdRequest.kt → ...ata/model/request/GetIdentityIdRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...y/src/main/java/software/amazon/location/auth/data/model/request/ReverseGeocodeRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package software.amazon.location.auth.data.model.request | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ReverseGeocodeRequest( | ||
@SerializedName("Language") | ||
val language: String, | ||
@SerializedName("MaxResults") | ||
val maxResults: Int, | ||
@SerializedName("Position") | ||
val position: List<Double> | ||
) |
2 changes: 1 addition & 1 deletion
2
...ocation/auth/data/response/Credentials.kt → ...n/auth/data/model/response/Credentials.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...th/data/response/GetCredentialResponse.kt → ...a/model/response/GetCredentialResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...th/data/response/GetIdentityIdResponse.kt → ...a/model/response/GetIdentityIdResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ry/src/main/java/software/amazon/location/auth/data/model/response/ReverseGeocodeLabel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package software.amazon.location.auth.data.model.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ReverseGeocodeLabel( | ||
@SerializedName("Label") | ||
val label: String | ||
) |
8 changes: 8 additions & 0 deletions
8
...ry/src/main/java/software/amazon/location/auth/data/model/response/ReverseGeocodePlace.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package software.amazon.location.auth.data.model.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ReverseGeocodePlace( | ||
@SerializedName("Place") | ||
val place: ReverseGeocodeLabel | ||
) |
8 changes: 8 additions & 0 deletions
8
...src/main/java/software/amazon/location/auth/data/model/response/ReverseGeocodeResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package software.amazon.location.auth.data.model.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ReverseGeocodeResponse( | ||
@SerializedName("Results") | ||
val results: List<ReverseGeocodePlace> | ||
) |
17 changes: 17 additions & 0 deletions
17
library/src/main/java/software/amazon/location/auth/data/network/AwsApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package software.amazon.location.auth.data.network | ||
|
||
import retrofit2.http.Body | ||
import retrofit2.http.Headers | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
import software.amazon.location.auth.data.model.request.ReverseGeocodeRequest | ||
import software.amazon.location.auth.data.model.response.ReverseGeocodeResponse | ||
|
||
interface AwsApiService { | ||
@POST("places/v0/indexes/{indexName}/search/position") | ||
@Headers("Content-Type: application/json") | ||
suspend fun reverseGeocode( | ||
@Path("indexName") indexName: String, | ||
@Body request: ReverseGeocodeRequest | ||
): ReverseGeocodeResponse | ||
} |
35 changes: 35 additions & 0 deletions
35
library/src/main/java/software/amazon/location/auth/data/network/AwsOkHttpClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package software.amazon.location.auth.data.network | ||
|
||
import java.util.concurrent.TimeUnit | ||
import okhttp3.OkHttpClient | ||
import software.amazon.location.auth.AwsSignerInterceptor | ||
import software.amazon.location.auth.LocationCredentialsProvider | ||
import software.amazon.location.auth.utils.Constants.CONNECTION_TIMEOUT | ||
import software.amazon.location.auth.utils.Constants.READ_TIMEOUT | ||
|
||
internal class AwsOkHttpClient { | ||
|
||
companion object { | ||
/** | ||
* Creates and returns an OkHttpClient configured with AWS request signing. | ||
* | ||
* @param serviceName The name of the AWS service (e.g., "execute-api"). | ||
* @param region The AWS region (e.g., "us-west-2"). | ||
* @param credentialsProvider The provider for obtaining AWS credentials. | ||
* @return An OkHttpClient instance with AWS signing interceptor. | ||
*/ | ||
fun getClient( | ||
serviceName: String, | ||
region: String, | ||
credentialsProvider: LocationCredentialsProvider? | ||
): OkHttpClient { | ||
val awsSignerInterceptor = AwsSignerInterceptor(serviceName, region, credentialsProvider) | ||
|
||
return OkHttpClient.Builder() | ||
.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS) | ||
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS) | ||
.addInterceptor(awsSignerInterceptor) | ||
.build() | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
library/src/main/java/software/amazon/location/auth/data/network/AwsRetrofitClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package software.amazon.location.auth.data.network | ||
|
||
import retrofit2.HttpException | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import software.amazon.location.auth.LocationCredentialsProvider | ||
import software.amazon.location.auth.utils.Constants.RESPONSE_CODE_CREDENTIAL_EXPIRED | ||
|
||
/** | ||
* A singleton object that manages the Retrofit client and API service for AWS requests. | ||
*/ | ||
object AwsRetrofitClient { | ||
private lateinit var retrofit: Retrofit | ||
private var _apiService: AwsApiService? = null | ||
|
||
/** | ||
* Initializes the Retrofit client with the given parameters. | ||
* | ||
* @param baseUrl The base URL for the Retrofit client. | ||
* @param serviceName The name of the AWS service (e.g., "execute-api"). | ||
* @param region The AWS region (e.g., "us-west-2"). | ||
* @param credentialsProvider The provider for obtaining AWS credentials. | ||
*/ | ||
fun init(baseUrl: String, serviceName: String, region: String, credentialsProvider: LocationCredentialsProvider?) { | ||
val client = AwsOkHttpClient.getClient(serviceName, region, credentialsProvider) | ||
retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
/** | ||
* Retrieves the API service instance. If it doesn't exist, it will be created. | ||
* | ||
* @return The API service instance. | ||
*/ | ||
val apiService: AwsApiService | ||
get() { | ||
if (_apiService == null) { | ||
createApiService() | ||
} | ||
return _apiService!! | ||
} | ||
|
||
/** | ||
* Creates the API service instance using the Retrofit client. | ||
*/ | ||
private fun createApiService() { | ||
_apiService = retrofit.create(AwsApiService::class.java) | ||
} | ||
|
||
/** | ||
* Clears the current API service instance, forcing it to be recreated on the next access. | ||
*/ | ||
@Synchronized | ||
fun clearApiService() { | ||
_apiService = null | ||
} | ||
|
||
/** | ||
* Checks if the given exception corresponds to an expired credentials error. | ||
* | ||
* @param e The exception to check. | ||
* @return True if the exception is a HttpException with a status code indicating expired credentials, false otherwise. | ||
*/ | ||
fun isHttpStatusCodeCredentialExpired(e: Exception): Boolean { | ||
if (e is HttpException) { | ||
return e.code() == RESPONSE_CODE_CREDENTIAL_EXPIRED | ||
} | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.