Skip to content

Commit

Permalink
add subscription list_with_paginator (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
montdidier authored Dec 30, 2023
1 parent 7a90001 commit dd7877f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ members = [

[package]
name = "pinpayments_rs"
version = "0.1.0"
version = "0.9.0"
description = "API bindings for the Pin Payments HTTP API"
rust-version = "1.65.0"
authors = [
"Chris Kruger <[email protected]>"
]
license = "MIT OR Apache-2.0"
license = "MIT"
readme = "README.md"
homepage = "https://github.com/montdidier/pinpayments_rs"
repository = "https://github.com/montdidier/pinpayments_rs"
keywords = ["pinpayments", "v1", "api", "async"]
categories = ["api-bindings"]
edition = "2021"

include = [
"**/*.rs",
"Cargo.toml"
]

[lib]
name = "pinpayments"

Expand Down
11 changes: 10 additions & 1 deletion src/resources/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use time::{OffsetDateTime};
use serde::{Deserialize, Serialize};

use crate::client::{Client, Response, StatusOnlyResponse};
use crate::client::{Client, Response};
use crate::error::PinError;
use crate::ids::{PlanId, CustomerId, SubscriptionId, CardId};
use crate::params::{unpack_contained, Page, Paginator, paginate};
Expand Down Expand Up @@ -68,6 +68,15 @@ impl Subscription {
client.get_query("/subscriptions", &params)
}

pub fn list_with_paginator(client: &Client, per_page: Option<u32>) -> Paginator<Result<Subscription, PinError>> {
paginate(
move |page, per_page| {
Subscription::list(client, Some(page), Some(per_page))
},
per_page.unwrap_or(25)
)
}

pub fn retrieve(client: &Client, token: &SubscriptionId) -> Response<Subscription> {
unpack_contained(client.get(&format!("/subscriptions/{}", token)))
}
Expand Down

0 comments on commit dd7877f

Please sign in to comment.