pub struct SquareClient { /* private fields */ }Expand description
The SquareClient contains many useful methods allowing for convenient use of the Square API.
Implementations§
Source§impl SquareClient
impl SquareClient
Sourcepub fn new(access_token: &str) -> Self
pub fn new(access_token: &str) -> Self
Create a new SquareClient
§Arguments
access_token- The access token for the Square App you want to use the client with is required.
§Example: Create a new client
const ACCESS_TOKEN:&str = "your_square_access_token";
use square_ox::client::SquareClient;
let client = SquareClient::new(ACCESS_TOKEN);Sourcepub fn production(self) -> Self
pub fn production(self) -> Self
Sourcepub async fn request<T>(
&self,
verb: Verb,
endpoint: SquareAPI,
json: Option<&T>,
parameters: Option<Vec<(String, String)>>,
) -> Result<SquareResponse, SquareError>
pub async fn request<T>( &self, verb: Verb, endpoint: SquareAPI, json: Option<&T>, parameters: Option<Vec<(String, String)>>, ) -> Result<SquareResponse, SquareError>
Sends a request to a given SquareAPI
§Arguments
api- The SquareAPI to send the request tobody- The json that will be included in the request. All types that meet the conditions to be deserialized to JSON are accepted.
§Example:
use env_logger::Builder;
async {
use square_ox::{
api::{
Verb, SquareAPI, payment::PaymentRequest
},
client,
builder::Builder
};
const ACCESS_TOKEN:&str = "your_square_access_token";
let payment = Builder::from(PaymentRequest::default()).build().await;
let client = client::SquareClient::new(ACCESS_TOKEN);
client.request( Verb::POST, SquareAPI::Payments("".to_string()), Some(&payment), None).await.expect("");
};
Source§impl SquareClient
impl SquareClient
Sourcepub fn inventory(&self) -> Inventory<'_>
pub fn inventory(&self) -> Inventory<'_>
Returns an Inventory object through which you can make calls specifically to the Inventory endpoint of the Square API.
§Example: Using the inventory endpoint to make a retrieve_count request.
use square_ox::{
response::{SquareResponse, ResponseError},
client::SquareClient,
api::inventory::Inventory,
};
async {
let count = SquareClient::new("some_token")
.inventory()
.retrieve_count(
"some_obj_id".to_string(),
Some("some_loc_id".to_string())
)
.await;
};Trait Implementations§
Source§impl Clone for SquareClient
impl Clone for SquareClient
Source§fn clone(&self) -> SquareClient
fn clone(&self) -> SquareClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SquareClient
impl RefUnwindSafe for SquareClient
impl Send for SquareClient
impl Sync for SquareClient
impl Unpin for SquareClient
impl UnwindSafe for SquareClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more