Ejemplo n.º 1
0
        public static void GetLocations()
        {
            try
            {
                var apikey    = "MRDG9GUuYOBmPLWGo1RC6mWw1Yj0chQA";
                var apisecret = "vE1cCThQDtyX8Gzb";

                Configuration amadeusconfig = Amadeus.builder(apikey, apisecret);
                amadeusconfig.setLoglevel("debug");
                Amadeus amadeus = amadeusconfig.build();

                Console.WriteLine("Get CheckinLink:");
                amadeus.resources.CheckinLink[] checkinLinks = amadeus.referenceData.urls.checkinLinks.get(Params
                                                                                                           .with("airlineCode", "BA"));

                Console.WriteLine(AmadeusUtil.ArrayToStringGeneric(checkinLinks, "\n"));

                Console.WriteLine("\n\n");

                Console.WriteLine("Get Locations:");

                amadeus.resources.Location[] locations = amadeus.referenceData.locations.get(Params
                                                                                             .with("keyword", "LON")
                                                                                             .and("subType", resources.referenceData.Locations.ANY));


                Console.WriteLine(AmadeusUtil.ArrayToStringGeneric(locations, "\n"));
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.ToString());
            }
        }
Ejemplo n.º 2
0
        public void TestBuildUriForGetRequestWithoutParams()
        {
            Configuration configution = Amadeus.builder("123", "234");
            Amadeus       amadeus     = configution.build();
            Request       request     = new Request("GET", "/foo/bar", null, null, amadeus);

            Assert.IsTrue(request.uri == "https://test.api.amadeus.com:443/foo/bar?");
        }
Ejemplo n.º 3
0
        public void TestBuildUriForGetRequest()
        {
            Configuration configution = Amadeus.builder("123", "234");
            Amadeus       amadeus     = configution.build();
            Params        _params     = Params.with("foo", "bar");
            Request       request     = new Request("GET", "/foo/bar", _params, null, amadeus);

            Assert.IsTrue(request.uri == "https://test.api.amadeus.com:443/foo/bar?foo=bar");
        }
Ejemplo n.º 4
0
        public Connect()
        {
            var apiKey    = AmadeusKey.Key;
            var apiSecret = AmadeusKey.Secret;

            amadeus = Amadeus
                      .builder(apiKey, apiSecret)
                      .build();
        }
Ejemplo n.º 5
0
        public void TestEstablishConnection()
        {
            Configuration configution = Amadeus.builder("123", "234");
            Amadeus       amadeus     = configution.build();
            Params        _params     = Params.with("foo", "bar");
            Request       request     = new Request("POST", "/v1/security/oauth2/token", null, null, amadeus);

            request.establishConnection();
            Assert.IsNotNull(request.connection);
        }
Ejemplo n.º 6
0
        public void TestInitializerWithHTTP()
        {
            Configuration configution = Amadeus.builder("123", "234");

            configution.ssl = false;
            Amadeus amadeus = configution.build();
            Params  _params = Params.with("foo", "bar");
            Request request = new Request("GET", "/foo/bar", _params, "token", amadeus);

            Assert.IsTrue(request.scheme == "http");
        }
Ejemplo n.º 7
0
        public void TestInitializerWithCustomAppInfo()
        {
            Configuration configution = Amadeus.builder("123", "234");

            configution.customAppId      = "amadeus-cli";
            configution.customAppVersion = "123";
            Amadeus amadeus = configution.build();
            Params  _params = Params.with("foo", "bar");
            Request request = new Request("GET", "/foo/bar", _params, "token", amadeus);

            Assert.IsTrue(Regex.Matches(request.headers["User-Agent"], "amadeus-csharp/.* csharp/.* amadeus-cli/.*").Count > 0);
        }
Ejemplo n.º 8
0
        public void TestInitializerWithoutBearerToken()
        {
            try
            {
                Amadeus amadeus = Amadeus.builder("123", "234").build();
                Params  _params = Params.with("foo", "bar");
                Request request = new Request("GET", "/foo/bar", _params, null, amadeus);

                Assert.IsTrue(request.headers.Count == 2);
            } catch (Exception e)
            {
                Assert.IsInstanceOf(typeof(KeyNotFoundException), e);
            }
        }
Ejemplo n.º 9
0
        public void TestBuilderWithEnvironment()
        {
            System.Environment.SetEnvironmentVariable("AMADEUS_CLIENT_ID", "123");
            System.Environment.SetEnvironmentVariable("AMADEUS_CLIENT_SECRET", "234");
            System.Environment.SetEnvironmentVariable("AMADEUS_LOG_LEVEL", "debug");
            System.Environment.SetEnvironmentVariable("AMADEUS_PORT", "123");
            System.Environment.SetEnvironmentVariable("AMADEUS_HOST", "my.custom.host.com");
            Assert.IsInstanceOf(typeof(Configuration), Amadeus.builder(), "should return a Configuration");
            Amadeus amadeus = Amadeus.builder().build();

            Assert.IsTrue(amadeus.configuration.logLevel == "debug");
            Assert.IsTrue(amadeus.configuration.port == 123);
            Assert.IsTrue(amadeus.configuration.host == "my.custom.host.com");
            System.Environment.SetEnvironmentVariable("AMADEUS_CLIENT_ID", null);
            System.Environment.SetEnvironmentVariable("AMADEUS_CLIENT_SECRET", null);
            System.Environment.SetEnvironmentVariable("AMADEUS_LOG_LEVEL", null);
            System.Environment.SetEnvironmentVariable("AMADEUS_PORT", null);
            System.Environment.SetEnvironmentVariable("AMADEUS_HOST", null);
        }
Ejemplo n.º 10
0
        public void TestAllNamespacesExist()
        {
            Amadeus client = Amadeus.builder("id", "secret").build();

            Assert.IsNotNull(client.referenceData.urls.checkinLinks);
            Assert.IsNotNull(client.referenceData.locations.airports);
            Assert.IsNotNull(client.referenceData.location("123"));
            Assert.IsNotNull(client.referenceData.airlines);
            Assert.IsNotNull(client.travel.analytics.airTraffic.traveled);
            Assert.IsNotNull(client.travel.analytics.airTraffic.booked);
            Assert.IsNotNull(client.travel.analytics.airTraffic.searched);
            Assert.IsNotNull(client.travel.analytics.airTraffic.searchedByDestination);
            Assert.IsNotNull(client.shopping.flightDates);
            Assert.IsNotNull(client.shopping.flightDestinations);
            Assert.IsNotNull(client.shopping.flightOffers);
            Assert.IsNotNull(client.shopping.hotelOffers);
            Assert.IsNotNull(client.shopping.hotelOffersByHotel);
            Assert.IsNotNull(client.shopping.hotelOffer("XXX"));
        }
Ejemplo n.º 11
0
        public void TestInitializer()
        {
            Amadeus amadeus = Amadeus.builder("123", "234").build();
            Params  _params = Params.with("foo", "bar");
            Request request = new Request("GET", "/foo/bar", _params, "token", amadeus);

            Assert.IsTrue(request.verb == "GET");
            Assert.IsTrue(request.host == "test.api.amadeus.com");
            Assert.IsTrue(request.path == "/foo/bar");
            Assert.IsTrue(request._params == _params);
            Assert.IsTrue(request.bearerToken == "token");
            Assert.IsTrue(request.languageVersion == typeof(string).Assembly.ImageRuntimeVersion);
            Assert.IsTrue(request.clientVersion == Amadeus.VERSION);
            Assert.IsTrue(request.appId == null);
            Assert.IsTrue(request.appVersion == null);
            Assert.IsTrue(request.port == 443);
            Assert.IsTrue(request.ssl);
            Assert.IsTrue(request.scheme == "https");
            Assert.IsTrue(request.headers.Count == 3);
            Assert.IsTrue(request.headers["Accept"] == "application/json, application/vnd.amadeus+json");
            Assert.IsTrue(request.headers["Authorization"] == "token");
            Assert.IsTrue(Regex.Matches(request.headers["User-Agent"], "amadeus-csharp/.* csharp/.*").Count > 0);
        }
Ejemplo n.º 12
0
 public void TestBuilderWithNullClientSecret()
 {
     Assert.IsNotNull(Amadeus.builder("client", null).build(), "should return null");
 }
Ejemplo n.º 13
0
 public void TestBuilderWithNullClientId()
 {
     Assert.IsNotNull(Amadeus.builder(null, "secret").build(), "should return null");
 }
Ejemplo n.º 14
0
 public void TestBuilder()
 {
     Assert.IsInstanceOf(typeof(Configuration), Amadeus.builder("id", "secret"), "should return a Configuration");
 }