From b5b0dfb5af5653b98a66043352def3c67f080dce Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Thu, 30 Dec 2021 23:48:09 +0100 Subject: [PATCH] upd deps and fix invoice date --- Cargo.toml | 22 +++++++++++----------- src/client.rs | 0 src/invoice.rs | 5 ++--- src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++---------- 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 src/client.rs diff --git a/Cargo.toml b/Cargo.toml index 04643f4..d90a070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,16 +13,16 @@ edition = "2018" [dependencies] -reqwest = { version = "0.11", features = ["json"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -serde_with = "1.9" -chrono = { version = "0.4", features = ["serde"] } -jsonwebtoken = "7.2" -base64 = "0.13" -log = "0.4" -bytes = "1.0" +reqwest = { version = "0.11.8", features = ["json"] } +serde = { version = "1.0.132", features = ["derive"] } +serde_json = "1.0.73" +serde_with = "1.11.0" +chrono = { version = "0.4.19", features = ["serde"] } +jsonwebtoken = "7.2.0" +base64 = "0.13.0" +log = "0.4.14" +bytes = "1.1.0" [dev-dependencies] -tokio = { version = "1", features = ["macros", "rt-multi-thread"] } -dotenv = "0.15" +tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } +dotenv = "0.15.0" diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/invoice.rs b/src/invoice.rs index 4e93c5b..ced3505 100644 --- a/src/invoice.rs +++ b/src/invoice.rs @@ -10,7 +10,6 @@ use crate::common::*; use crate::errors::{PaypalError, ResponseError}; use crate::HeaderParams; use bytes::Bytes; -use chrono::NaiveDate; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use std::collections::HashMap; @@ -125,7 +124,7 @@ pub struct InvoiceDetail { /// The invoice number. Default is the number that is auto-incremented number from the last number. pub invoice_number: Option, /// The invoice date as specificed by the sender - pub invoice_date: Option>, + pub invoice_date: Option, /// The payment due date for the invoice. pub payment_term: Option, /// The audit metadata @@ -910,6 +909,6 @@ mod tests { let list = client.list_invoices(1, 10, HeaderParams::default()).await.unwrap(); - println!("{:?}", list); + println!("{:#?}", list); } } diff --git a/src/lib.rs b/src/lib.rs index 035d0a3..3e783d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,7 @@ -//! [![Crates.io](https://meritbadge.herokuapp.com/paypal-rs)](https://crates.io/crates/paypal-rs) +//! +//! [![Version](https://img.shields.io/crates/v/paypal-rs)](https://crates.io/crates/paypal-rs) +//! [![Downloads](https://img.shields.io/crates/d/paypal-rs)](https://crates.io/crates/paypal-rs) +//! [![License](https://img.shields.io/crates/l/paypal-rs)](https://crates.io/crates/paypal-rs) //! ![Rust](https://github.com/edg-l/paypal-rs/workflows/Rust/badge.svg) //! [![Docs](https://docs.rs/paypal-rs/badge.svg)](https://docs.rs/paypal-rs) //! @@ -88,7 +91,7 @@ use reqwest::header; use reqwest::header::HeaderMap; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -use std::time::{Duration, Instant}; +use std::{borrow::Cow, time::{Duration, Instant}}; /// The paypal api endpoint used on a live application. pub const LIVE_ENDPOINT: &str = "https://api-m.paypal.com"; @@ -131,7 +134,7 @@ pub struct Auth { #[derive(Debug)] pub struct Client { /// Internal http client - pub client: reqwest::Client, + pub(crate) client: reqwest::Client, /// Whether you are or not in a sandbox enviroment. pub sandbox: bool, /// Api Auth information @@ -244,13 +247,13 @@ impl Client { /// client.get_access_token().await.unwrap(); /// } /// ``` - pub fn new>(client_id: S, secret: S, sandbox: bool) -> Client { + pub fn new(client_id: String, secret: String, sandbox: bool) -> Client { Client { client: reqwest::Client::new(), sandbox, auth: Auth { - client_id: client_id.into(), - secret: secret.into(), + client_id, + secret, access_token: None, expires: None, }, @@ -365,11 +368,37 @@ impl Client { } } +pub(crate) trait FromResponse: Sized { + type Response; + + fn from_response(res: Self::Response) -> Self; +} + +pub(crate) trait Endpoint { + type Query: Serialize; + type Body: Serialize; + type Response: FromResponse; + + fn path(&self) -> Cow; + + fn method(&self) -> reqwest::Method { + reqwest::Method::GET + } + + fn query(&self) -> Option<&Self::Query> { + None + } + + fn body(&self) -> Option<&Self::Body> { + None + } +} + #[cfg(test)] mod tests { use crate::common::Currency; use crate::countries::Country; - use crate::{orders::*, Client, HeaderParams, Prefer}; + use crate::{orders::*, Client, HeaderParams}; use std::env; use std::str::FromStr; @@ -378,9 +407,7 @@ mod tests { let clientid = env::var("PAYPAL_CLIENTID").unwrap(); let secret = env::var("PAYPAL_SECRET").unwrap(); - let client = Client::new(clientid, secret, true); - - client + Client::new(clientid, secret, true) } #[tokio::test]