public async Task <AvailabeRatesResponse> RatesQuery_GetAsync(RatesQueryOrShipmentRequest request) { HttpResponseMessage response = await Common.GetHttpClient(API_TOKEN).PostAsJsonAsync("api/rates", request); if (response.IsSuccessStatusCode) { var data = response.Content.ReadAsAsync <AvailabeRatesResponse>(); return(data.Result); } else { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} ({1}) - {2}", (int)response.StatusCode, response.ReasonPhrase, response.Content.ReadAsStringAsync().Result); throw new HttpRequestException(sb.ToString()); } }
public async Task <CreateShipmentResponse> Shipment_CreateAsync(RatesQueryOrShipmentRequest request, Guid quoteId) { request.QuoteId = quoteId; HttpResponseMessage response = await Common.GetHttpClient(API_TOKEN).PostAsJsonAsync("api/shipments", request); if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var data = response.Content.ReadAsAsync <CreateShipmentResponse>(); return(data.Result); } else { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} ({1}) - {2}", (int)response.StatusCode, response.ReasonPhrase, response.Content.ReadAsStringAsync().Result); throw new HttpRequestException(sb.ToString()); } }
public void CreateDomesticOutboundShipmentWithPreRating() { GoSweetSpotApiClient client = new GoSweetSpotApiClient(api_token); var payload = new RatesQueryOrShipmentRequest { DeliveryReference = "ORDER123", Destination = new RatesQueryOrShipmentRequest.Contact { Name = "DestinationName", Address = new RatesQueryOrShipmentRequest.Contact.AddressModel { BuildingName = "", StreetAddress = "DestinationStreetAddress", Suburb = "Avonside", City = "Christchurch", PostCode = "8061", CountryCode = "NZ", }, ContactPerson = "DestinationContact", PhoneNumber = "123456789", Email = "*****@*****.**", DeliveryInstructions = "Desinationdeliveryinstructions" }, IsSaturdayDelivery = false, IsSignatureRequired = true, Packages = new List <RatesQueryOrShipmentRequest.RatesPackage>(new RatesQueryOrShipmentRequest.RatesPackage[] { new RatesQueryOrShipmentRequest.RatesPackage { Height = 1, Length = 1, Id = 0, Width = 10, Kg = 0.1M, Name = "GSS-DLE SATCHEL", } }) }; var rates = client.RatesQuery_GetAsync(payload).Result; var conn = client.Shipment_CreateAsync(payload, rates.Available.First().QuoteId).Result; Assert.IsTrue(conn.Consignments.Count > 0); }
public async Task <CreateShipmentResponse> Shipment_CreateAsync(RatesQueryOrShipmentRequest request) { return(await Shipment_CreateAsync(request, Guid.Empty)); }