Skip to content

Commit

Permalink
Add get_next_page code examples (#113)
Browse files Browse the repository at this point in the history
* Add get_next_page code examples

* Lints

* Add curl example

* Lint

* Lint the right curl command

* Typo
  • Loading branch information
dcaballeroc authored Oct 10, 2023
1 parent 22b9ed0 commit 91e3f5a
Show file tree
Hide file tree
Showing 10 changed files with 598 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ venv
/style_suppressions.xml
/.dummy
/.eslintignore
*.sw*
33 changes: 33 additions & 0 deletions official/docs/csharp/current/pagination/get-next-page.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using EasyPost;
using EasyPost.Models.API;
using EasyPost.Parameters;

namespace EasyPostExamples
{
public class Examples
{
public static async Task Main()
{
string apiKey = Environment.GetEnvironmentVariable("EASYPOST_API_KEY")!;

var client = new EasyPost.Client(apiKey);

// Get first page of results
Parameters.Shipment.All parameters = new()
{
PageSize = 5
};

ShipmentCollection shipmentCollection = await client.Shipment.All(parameters);

// Provide the previous results page to move onto the next page
ShipmentCollection nextPage = await client.Shipment.GetNextPage(shipmentCollection)

Console.WriteLine(JsonConvert.SerializeObject(nextPage, Formatting.Indented));
}
}
}
7 changes: 7 additions & 0 deletions official/docs/curl/current/pagination/get-next-page.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get first page of results
curl -X 'GET https://api.easypost.com/v2/shipments?page_size=5' \
-u "$EASYPOST_API_KEY":

# Provide the ID of the last element of the previous page in the before_id param
curl -X 'GET https://api.easypost.com/v2/shipments?page_size=5&before_id=shp_...' \
-u "$EASYPOST_API_KEY":
28 changes: 28 additions & 0 deletions official/docs/golang/current/pagination/get-next-page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package example

import (
"fmt"
"os"

"github.com/EasyPost/easypost-go/v3"
)

func main() {
apiKey := os.Getenv("EASYPOST_API_KEY")
client := easypost.New(apiKey)

// Get first page of results
shipments, _ := client.ListShipments(
&easypost.ListShipmentsOptions{
PageSize: 5,
},
)

// Provide the previous results page to move onto the next page
secondPage, _ := client.GetNextShipmentPage(shipments)

// You can also ask for the next page to be of a specific size
lastPage, _ := client.GetNextShipmentPageWithPageSize(secondPage, 10)

fmt.Println(lastPage)
}
24 changes: 24 additions & 0 deletions official/docs/java/current/pagination/get-next-page.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package shipments;

import com.easypost.exception.EasyPostException;
import com.easypost.model.ShipmentCollection;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

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

// Get the first page of results
HashMap<String, Object> params = new HashMap<>();
params.put("page_size", 5);

ShipmentCollection shipments = client.shipment.all(params);

// Provide the previous results page to move onto the next page
ShipmentCollection nextPage = client.shipment.getNextPage(shipments);

System.out.println(nextPage);
}
}
15 changes: 15 additions & 0 deletions official/docs/node/current/pagination/get-next-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient(process.env.EASYPOST_API_KEY);

(async () => {
// Get first page of results
const shipments = await client.Shipment.all({
page_size: 5,
});

// Provide the previous results page to move onto the next page
const nextPage = await client.Shipment.getNextPage(shipments);

console.log(nextPage);
})();
13 changes: 13 additions & 0 deletions official/docs/php/current/pagination/get-next-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

// Get first page of results
$shipments = $client->shipment->all([
'page_size' => 5,
]);

// Provide the previous results page to move onto the next page
$nextPage = $client->shipments->getNextPage($shipments);

echo $nextPage;
14 changes: 14 additions & 0 deletions official/docs/python/current/pagination/get-next-page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import easypost
import os

client = easypost.EasyPostClient(os.getenv("EASYPOST_API_KEY"))

# Get first page of results
shipments = client.shipment.all(
page_size=5,
)

# Provide the previous results page to move onto the next page
next_page = client.shipments.get_next_page(shipments)

print(next_page)
Loading

0 comments on commit 91e3f5a

Please sign in to comment.