Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_next_page code examples #113

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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