Coder Social home page Coder Social logo

amadeus4dev-examples / amadeus-android Goto Github PK

View Code? Open in Web Editor NEW
19.0 5.0 8.0 3.34 MB

Android (Kotlin) library for the Amadeus Self-Service travel APIs

Home Page: https://developers.amadeus.com/

License: MIT License

Kotlin 100.00%
android kotlin sdk amadeus travel api

amadeus-android's People

Contributors

anthonyroux avatar minjikarin avatar pietrini avatar torresc24 avatar tsolakoua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

amadeus-android's Issues

Implement missing endpoints

Based on the test file those endpoints are missing:
(I am putting from the Java SDK)
SeatMap API:

  • SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body);

  • SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params .with("flight-orderId", "eJzTd9f3NjIJdzUGAAp%2fAiY="));

  • Flight Offers Price:

FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post(
                    body,
                    Params.with("include", "other-services")
                          .and("forceClass", "false"));
  • Flight Create Orders:
// Flight Create Orders to book a flight
// Using a JSonObject or String
FlightOrder createdOrder = amadeus.booking.flightOrders.post(body)

// Using a JsonObject for flight offer and Traveler[] as traveler information
// see example at src/main/java/examples/flight/createorders/FlightCreateOrders.java
FlightOrder createdOrder = amadeus.booking.flightOrders.post(flightOffersSearches, travelerArray);
  • Flight Order Mangement - Cancel (new API added recently):
  • amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").delete();

Flight Delay Prediction:

  • Prediction[] flightDelay = amadeus.travel.predictions.flightDelay.get

Flight Offers Search POST version:

  • FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body);

Hotel sentiment by id - Headers issue

Call: amadeus.ereputation.hotelSentiments.get(listOf("TELONMFS", "ADNYCCTB", "XXXYYY01")

Returns this error: {"errors":[{"status":415,"code":477,"title":"INVALID FORMAT","detail":"Accept header value specified in the request is not supported"}]}

Value sent: Accept: application/json, application/vnd.amadeus+json

Support call by URL

For example in Java:

Resource resource = amadeus.get('/v2/reference-data/urls/checkin-links',
 Params.with("airlineCode", "BA"));

resource.getResult();

Flight Check-in Links status code not managed properly

The Integration tests for Flight Check-in Links fail. The reason seems to be that when you don't pass the "language" optional parameter, the API returns a 200 HTTP status code but with a warning. It seems the SDK doesn't know how to manage this and set the status code to 0.

By changing the API call from amadeus.referenceData.urls.checkinLinks.get("LH") to amadeus.referenceData.urls.checkinLinks.get("LH", "EN") it seems to fix the issue.

Fix next issue with type erasure

Demo development raised an issue around next method on lists. Type erasure makes impossible for json parser to know what's the object type in List

README.md outdated

scope.launch {
  when (val checkinLinks = amadeus.referenceData.urls.checkinLinks.get(airlineCode = "LH")) {
    is Result.Success -> {
      Log.d("Result", "${result.data}")
    }
    is Result.Error -> {
      // Handle your error
    }
  }

Result.Success and Result.Error should be ApiResult?

Issue with Flight Order Management Cancel

I have an issue with the cancel API. When success the API returns a 204 - no content (and doesn't return anything), I think that could be the issue.

    @Test
    fun `Booking FlightCreateOrder with object, retrieve and delete`() = runBlocking {
        // Create fake traveler
        val traveler = Traveler(
            id = "1",
            dateOfBirth = "2000-04-14",
            name = Name("JORGE", "GONZALES"),
            contact = Contact(
                listOf(
                    Phone(
                        countryCallingCode = "33",
                        number = "675426222",
                        deviceType = "MOBILE"
                    )
                )
            ),
            documents = listOf(
                Document(
                    documentType = "PASSPORT",
                    number = "480080076",
                    expiryDate = "2022-10-11",
                    issuanceCountry = "ES",
                    nationality = "ES",
                    holder = true
                )
            )
        )

        val flightOffers = amadeus.shopping.flightOffersSearch.get(
            originLocationCode = "NCE",
            destinationLocationCode = "PAR",
            departureDate = "2020-11-01",
            returnDate = "2020-11-08",
            adults = 1,
            max = 3
        )
        assert(flightOffers?.succeeded ?: false)
        if (flightOffers is Success) {
            val pricing =
                amadeus.shopping.flightOffersSearch.pricing.post(flightOffers.data.first())
            assert(pricing?.succeeded ?: false)

            if (pricing is Success) {
                val order = amadeus.booking.flightOrders.post(
                    flightPrice = pricing.data,
                    travelers = listOf(traveler)
                )

                assert(order?.succeeded ?: false)
                if (order is Success) {
                    order.data.id?.let { amadeus.booking.flightOrder(it).get()?.succeeded } ?: false
                    order.data.id?.let { amadeus.booking.flightOrder(it).delete() is Success} ?: false
                }
            }
        }
    }

java.lang.IllegalArgumentException: Unable to create converter for com.amadeus.android.ApiResult$Success<kotlin.Unit>
for method BookingApi.cancelFlightOrder

at retrofit2.Utils.methodError(Utils.java:53)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:115)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:82)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:37)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:192)
at retrofit2.Retrofit$1.invoke(Retrofit.java:149)
at com.sun.proxy.$Proxy22.cancelFlightOrder(Unknown Source)
at com.amadeus.android.booking.FlightOrder$delete$2.invokeSuspend(FlightOrder.kt:31)
at com.amadeus.android.booking.FlightOrder$delete$2.invoke(FlightOrder.kt)
at com.amadeus.android.BaseApi$safeApiCall$2.invokeSuspend(BaseApi.kt:24)
at |b|b|b(Coroutine boundary.|b(|b)
at com.amadeus.android.service.AmadeusTest$Booking FlightCreateOrder with object and delete$1.invokeSuspend(AmadeusTest.kt:363)
Caused by: java.lang.IllegalArgumentException: Unable to create converter for com.amadeus.android.ApiResult$Success<kotlin.Unit>
for method BookingApi.cancelFlightOrder
at retrofit2.Utils.methodError(Utils.java:53)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:115)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:82)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:37)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:192)
at retrofit2.Retrofit$1.invoke(Retrofit.java:149)
at com.sun.proxy.$Proxy22.cancelFlightOrder(Unknown Source)
at com.amadeus.android.booking.FlightOrder$delete$2.invokeSuspend(FlightOrder.kt:31)
at com.amadeus.android.booking.FlightOrder$delete$2.invoke(FlightOrder.kt)
at com.amadeus.android.BaseApi$safeApiCall$2.invokeSuspend(BaseApi.kt:24)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
Caused by: java.lang.IllegalArgumentException: Platform class kotlin.Unit requires explicit JsonAdapter to be registered
for class kotlin.Unit data
for com.amadeus.android.ApiResult$Success<kotlin.Unit>
at com.squareup.moshi.Moshi$LookupChain.exceptionWithLookupStack(Moshi.java:349)
at com.squareup.moshi.Moshi.adapter(Moshi.java:150)
at com.amadeus.android.ApiResult_SuccessJsonAdapter.(ApiResult_SuccessJsonAdapter.kt:32)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.squareup.moshi.internal.Util.generatedAdapter(Util.java:540)
at com.squareup.moshi.StandardJsonAdapters$1.create(StandardJsonAdapters.java:60)
at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
at com.squareup.moshi.Moshi.adapter(Moshi.java:98)
at retrofit2.converter.moshi.MoshiConverterFactory.responseBodyConverter(MoshiConverterFactory.java:91)
at com.amadeus.android.tools.WrapperConverterFactory.responseBodyConverter(WrapperConverterFactory.kt:18)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:352)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:335)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:113)
... 14 more
Caused by: java.lang.IllegalArgumentException: Platform class kotlin.Unit requires explicit JsonAdapter to be registered
at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:65)
at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
... 28 more

Update contributors guide

Test block should mention this:

Unit-test and Integration tests in Android Studio ... with a note: note that integration tests are here for you to validate your code. We do not run Integration tests on the continuous integration process (only unit-tests).

How to parse raw string result to error response in simple get request

I'm working on hotel booking and I want to show autocomplete cities to the user but I'm stuck on error response when the response is successful it's working fine, but when no data found it throws error and the app crash.

here is a blow code

val apiResponse = amadeus.get("https://test.api.amadeus.com/v1/reference-data/locations/cities?keyword=$keyword")

val type = Types.newParameterizedType(
                List::class.java,
                Location::class.java
            )
            val responseType = Types.newParameterizedTypeWithOwner(
                ApiResult::class.java,
                ApiResult.Success::class.java,
                type
            )

            val locationAdapter =
                amadeus.moshi.adapter<ApiResult.Success<List<Location>>>(resultType)

val cityDetail = locationAdapter.fromJson(apiResponse)

I'm getting error on this line val cityDetail = locationAdapter.fromJson(apiResponse) when user enter invalid location which does not found.
I've attached the error along with raw response.
Any help will be appreciated.

error

Kotlin Multiplatform

Hi,
Is there a plan to use ktor-client instead of retrofit?
That would make it possible to use this API client in kotlin/compose multiplatform projects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.