1pub mod payment;
9pub mod bookings;
10pub mod locations;
11pub mod catalog;
12pub mod customers;
13pub mod cards;
14pub mod checkout;
15pub mod inventory;
16pub mod sites;
17pub mod terminal;
18pub mod orders;
19
20use crate::client::ClientMode;
21use crate::client::SquareClient;
22use std::fmt;
23
24#[non_exhaustive]
27pub enum SquareAPI {
28 Payments(String),
29 Bookings(String),
30 Locations(String),
31 Catalog(String),
32 Customers(String),
33 Cards(String),
34 Checkout(String),
35 Inventory(String),
36 Sites(String),
37 Terminals(String),
38 Orders(String),
39}
40
41pub enum Verb {
44 GET,
45 POST,
46 PUT,
47 PATCH,
48 DELETE,
49}
50
51impl fmt::Display for SquareAPI {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 match self {
57 SquareAPI::Payments(path) => write!(f, "payments{}", path),
58 SquareAPI::Bookings(path) => write!(f, "bookings{}", path),
59 SquareAPI::Locations(path) => write!(f, "locations{}", path),
60 SquareAPI::Catalog(path) => write!(f, "catalog{}", path),
61 SquareAPI::Customers(path) => write!(f, "customers{}", path),
62 SquareAPI::Cards(path) => write!(f, "cards{}", path),
63 SquareAPI::Checkout(path) => write!(f, "online-checkout{}", path),
64 SquareAPI::Inventory(path) => write!(f, "inventory{}", path),
65 SquareAPI::Sites(path) => write!(f, "sites{}", path),
66 SquareAPI::Terminals(path) => write!(f, "terminals{}", path),
67 SquareAPI::Orders(path) => write!(f, "orders{}", path),
68 }
69 }
70}
71
72impl SquareClient {
73 pub fn endpoint(&self, end_point: SquareAPI) -> String {
74 const SQUARE_PRODUCTION_BASE: &str = "https://connect.squareup.com/v2/";
76 const SQUARE_SANDBOX_BASE: &str = "https://connect.squareupsandbox.com/v2/";
77
78 match self.client_mode {
79 ClientMode::Production => format!("{}{}", SQUARE_PRODUCTION_BASE, end_point),
80 ClientMode::Sandboxed => format!("{}{}", SQUARE_SANDBOX_BASE, end_point),
81 }
82 }
83}