1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! Shipping Groups API
//!
//! This module provides functionality to manage bulk shipping groups.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::shipping_groups::*;
use uuid::Uuid;
impl RainClient {
/// Get all bulk shipping groups
///
/// # Arguments
///
/// * `params` - Query parameters for filtering shipping groups
///
/// # Returns
///
/// Returns a [`Vec<ShippingGroup>`] containing the list of shipping groups.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::shipping_groups::{ListShippingGroupsParams, ShippingGroup};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let params = ListShippingGroupsParams {
/// cursor: None,
/// limit: Some(20),
/// };
/// let shipping_groups = client.list_shipping_groups(¶ms).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn list_shipping_groups(
&self,
params: &ListShippingGroupsParams,
) -> Result<Vec<ShippingGroup>> {
let path = "/shipping-groups";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get(&full_path).await
}
/// Create a bulk shipping group
///
/// # Arguments
///
/// * `request` - The shipping group creation request
///
/// # Returns
///
/// Returns a [`ShippingGroup`] containing the created shipping group information (202 Accepted).
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::shipping_groups::CreateShippingGroupRequest;
/// use rain_sdk::models::common::Address;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let request = CreateShippingGroupRequest {
/// recipient_first_name: "John".to_string(),
/// recipient_last_name: Some("Doe".to_string()),
/// recipient_phone_country_code: Some("1".to_string()),
/// recipient_phone_number: Some("5555555555".to_string()),
/// address: Address {
/// line1: "123 Main St".to_string(),
/// line2: None,
/// city: "New York".to_string(),
/// region: "NY".to_string(),
/// postal_code: "10001".to_string(),
/// country_code: "US".to_string(),
/// country: None,
/// },
/// };
/// let shipping_group = client.create_shipping_group(&request).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn create_shipping_group(
&self,
request: &CreateShippingGroupRequest,
) -> Result<ShippingGroup> {
let path = "/shipping-groups";
// Returns 202 Accepted
self.post(path, request).await
}
/// Get a bulk shipping group by its id
///
/// # Arguments
///
/// * `shipping_group_id` - The unique identifier of the shipping group
///
/// # Returns
///
/// Returns a [`ShippingGroup`] containing the shipping group information.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `404` - Shipping group not found
/// - `500` - Internal server error
#[cfg(feature = "async")]
pub async fn get_shipping_group(&self, shipping_group_id: &Uuid) -> Result<ShippingGroup> {
let path = format!("/shipping-groups/{shipping_group_id}");
self.get(&path).await
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Get all bulk shipping groups (blocking)
#[cfg(feature = "sync")]
pub fn list_shipping_groups_blocking(
&self,
params: &ListShippingGroupsParams,
) -> Result<Vec<ShippingGroup>> {
let path = "/shipping-groups";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get_blocking(&full_path)
}
/// Create a bulk shipping group (blocking)
#[cfg(feature = "sync")]
pub fn create_shipping_group_blocking(
&self,
request: &CreateShippingGroupRequest,
) -> Result<ShippingGroup> {
let path = "/shipping-groups";
// Returns 202 Accepted
self.post_blocking(path, request)
}
/// Get a bulk shipping group by its id (blocking)
#[cfg(feature = "sync")]
pub fn get_shipping_group_blocking(&self, shipping_group_id: &Uuid) -> Result<ShippingGroup> {
let path = format!("/shipping-groups/{shipping_group_id}");
self.get_blocking(&path)
}
}