Skip to content

Commit

Permalink
fix: buy calls for batches
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Jun 25, 2024
1 parent dd47229 commit eeb262f
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 8 deletions.
31 changes: 30 additions & 1 deletion official/docs/csharp/current/batches/buy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,36 @@ public static async Task Main()
{
var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

batch = await client.Batch.Buy("batch_...");
Parameters.Shipment.Create shipmentParameters = new()
{
ToAddress = new Parameters.Address.Create
{
Id = "adr_..."
},
FromAddress = new Parameters.Address.Create
{
Id = "adr_..."
},
Parcel = new Parameters.Parcel.Create
{
Id = "prcl_..."
},
Service = "First",
Carrier = "USPS",
CarrierAccountIds = new List<string> { "ca_..." }
};

Parameters.Batch.Create parameters = new()
{
Shipments = new List<IShipmentParameter>()
{
shipmentParameters
}
};

Batch batch = await client.Batch.Create(parameters);

batch = await client.Batch.Buy(batch.Id);

Console.WriteLine(JsonConvert.SerializeObject(batch, Formatting.Indented));
}
Expand Down
19 changes: 18 additions & 1 deletion official/docs/golang/current/batches/buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ import (
func main() {
client := easypost.New("EASYPOST_API_KEY")

batch, _ := client.BuyBatch("batch_...")
createdBatch, _ := client.CreateBatch(
&easypost.Shipment{
FromAddress: &easypost.Address{
ID: "adr_...",
},
ToAddress: &easypost.Address{
ID: "adr_...",
},
Parcel: &easypost.Parcel{
ID: "prcl_...",
},
Service: "First",
Carrier: "USPS",
CarrierAccountIDs: []string{"ca_..."},
},
)

batch, _ := client.BuyBatch(createdBatch.ID)

fmt.Println(batch)
}
35 changes: 34 additions & 1 deletion official/docs/java/current/batches/buy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,44 @@
import com.easypost.model.Batch;
import com.easypost.service.EasyPostClient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Buy {
public static void main(String[] args) throws EasyPostException {
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

Batch batch = client.batch.buy("batch_...");
List<HashMap<String, Object>> shipmentsList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> shipmentMap = new HashMap<String, Object>();

HashMap<String, Object> fromAddress = new HashMap<String, Object>();
fromAddress.put("id", "adr_...");
shipmentMap.put("from_address", fromAddress);

HashMap<String, Object> toAddress = new HashMap<String, Object>();
toAddress.put("id", "adr_...");
shipmentMap.put("to_address", toAddress);

HashMap<String, Object> parcel = new HashMap<String, Object>();
parcel.put("id", "prcl_...");
shipmentMap.put("parcel", parcel);

shipmentMap.put("service", "First");
shipmentMap.put("carrier", "USPS");

String[] carrierAccounts = { "ca_..." };
shipmentMap.put("carrier_accounts", carrierAccounts);

shipmentsList.add(shipmentMap);

HashMap<String, Object> params = new HashMap<String, Object>();

params.put("shipment", shipmentsList);

Batch createdBatch = client.batch.create(params);

Batch batch = client.batch.buy(createdBatch.getId());

System.out.println(batch);
}
Expand Down
15 changes: 14 additions & 1 deletion official/docs/node/current/batches/buy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ const EasyPostClient = require('@easypost/api');
const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
const batch = await client.Batch.buy('batch_...');
const createdBatch = await client.Batch.create({
shipments: [
{
from_address: { id: 'adr_...' },
to_address: { id: 'adr_...' },
parcel: { id: 'prcl_...' },
service: 'First',
carrier: 'USPS',
carrier_accounts: ['ca_...'],
},
],
});

const batch = await client.Batch.buy(createdBatch.id);

console.log(batch);
})();
13 changes: 12 additions & 1 deletion official/docs/php/current/batches/buy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$batch = $client->batch->buy('batch_...');
$createdBatch = $client->batch->create([
'shipments' => [
['from_address' => ['id' => 'adr_...']],
['to_address' => ['id' => 'adr_...']],
['parcel' => ['id' => 'prcl_...']],
['service' => 'First'],
['carrier' => 'USPS'],
['carrier_accounts' => ['ca_...']],
]
]);

$batch = $client->batch->buy($createdBatch['id']);

echo $batch;
15 changes: 14 additions & 1 deletion official/docs/python/current/batches/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

client = easypost.EasyPostClient("EASYPOST_API_KEY")

batch = client.batch.buy("batch_...")
createdBatch = client.batch.create(
shipments=[
{
"from_address": {"id": "adr_..."},
"to_address": {"id": "adr_..."},
"parcel": {"id": "prcl_..."},
"service": "First",
"carrier": "USPS",
"carrier_accounts": ["ca_..."],
},
],
)

batch = client.batch.buy(createdBatch["id"])

print(batch)
15 changes: 14 additions & 1 deletion official/docs/ruby/current/batches/buy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

batch = client.batch.buy('batch_...')
created_batch = client.batch.create(
shipments: [
{
from_address: { id: 'adr_...' },
to_address: { id: 'adr_...' },
parcel: { id: 'prcl_...' },
service: 'First',
carrier: 'USPS',
carrier_accounts: ['ca_...'],
},
],
)

batch = client.batch.buy(created_batch.id)

puts batch
1 change: 0 additions & 1 deletion official/docs/ruby/current/batches/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

batch = client.batch.create(
'batch_...',
shipments: [
{ id: 'shp_...' },
{ id: 'shp_...' },
Expand Down

0 comments on commit eeb262f

Please sign in to comment.