コード例 #1
0
        public string GetAsyncResult(string async)
        {
            var aysncrequest = JsonConvert.DeserializeObject <AsyncRequest>(async);

            var dateTime  = DateTime.Now.ToUniversalTime();
            var secure    = new ParamSecure(Config.Secret, Config.ApiKey, dateTime, aysncrequest);
            var signature = secure.Sign();

            var client = new RestClient(Config.GrailTravelHost);

            var request = new RestRequest($"/api/v2/async_results/{aysncrequest.async_key}", Method.GET);

            request.AddHeader("From", Config.ApiKey);
            request.AddHeader("Date", dateTime.ToString("r"));
            request.AddHeader("Authorization", signature);

            var response = string.Empty;

            for (var second = 0; second < 60; second++)
            {
                var res = client.Get(request);
                if (!res.Content.Contains("not ready"))
                {
                    response = res.Content;
                    break;
                }
                Thread.Sleep(1000);
            }

            return(response);
        }
コード例 #2
0
        public string GetSearch(SearchRequest searchReqeust)
        {
            var dateTime  = DateTime.Now.ToUniversalTime();
            var secure    = new ParamSecure(Config.Secret, Config.ApiKey, dateTime, searchReqeust);
            var signature = secure.Sign();

            var client = new RestClient(Config.GrailTravelHost);

            Console.WriteLine(searchReqeust.GetURL());
            var request = new RestRequest($"/api/v2/online_solutions?{searchReqeust.GetURL()}", Method.GET);

            request.AddHeader("From", Config.ApiKey);
            request.AddHeader("Date", dateTime.ToString("r"));
            request.AddHeader("Authorization", signature);

            var response = client.Get(request);

            return(response.Content);
        }
コード例 #3
0
        public string GetDownload(ConfirmRequest downloadReqeust)
        {
            var dateTime  = DateTime.Now.ToUniversalTime();
            var secure    = new ParamSecure(Config.Secret, Config.ApiKey, dateTime, downloadReqeust);
            var signature = secure.Sign();

            var client = new RestClient(Config.GrailTravelHost);

            Console.WriteLine(downloadReqeust.GetURL());
            var request = new RestRequest($"/api/v2/online_orders/{downloadReqeust.online_order_id}/online_tickets?online_order_id={downloadReqeust.online_order_id}", Method.GET);

            request.AddHeader("From", Config.ApiKey);
            request.AddHeader("Date", dateTime.ToString("r"));
            request.AddHeader("Authorization", signature);

            var response = client.Get(request);

            return(response.Content);
        }
コード例 #4
0
        public string PostBook(BookRequest bookRequest)
        {
            var dateTime  = DateTime.Now.ToUniversalTime();
            var secure    = new ParamSecure(Config.Secret, Config.ApiKey, dateTime, bookRequest);
            var signature = secure.Sign();

            var client = new RestClient(Config.GrailTravelHost);

            var request = new RestRequest($"/api/v2/online_orders", Method.POST);

            request.AddHeader("From", Config.ApiKey);
            request.AddHeader("Date", dateTime.ToString("r"));
            request.AddHeader("Authorization", signature);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(bookRequest);

            var response = client.Post(request);

            return(response.Content);
        }
コード例 #5
0
        public string PostConfirm(ConfirmRequest confirmReqeust)
        {
            var dateTime  = DateTime.Now.ToUniversalTime();
            var secure    = new ParamSecure(Config.Secret, Config.ApiKey, dateTime, confirmReqeust);
            var signature = secure.Sign();

            var client = new RestClient(Config.GrailTravelHost);

            Console.WriteLine(confirmReqeust.GetURL());
            var request = new RestRequest($"/api/v2/online_orders/{confirmReqeust.online_order_id}/online_confirmations", Method.POST);

            request.AddHeader("From", Config.ApiKey);
            request.AddHeader("Date", dateTime.ToString("r"));
            request.AddHeader("Authorization", signature);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(confirmReqeust);

            var response = client.Post(request);

            return(response.Content);
        }