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
/// see API docs at https://audible.readthedocs.io/en/latest/misc/external_api.html
use serde_json::Value;
use super::Client;
use crate::Result;
impl Client {
/// GET /1.0/collections
///
/// Query Parameters:
/// - `state_token` (string) – [ey…]
/// - `visibility_types` (string) – [Private, Discoverable]
pub async fn get_collections(&self, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/collections", self.base_url);
let mut req = self.client.get(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// POST /1.0/collections
/// Create a new collection
///
/// Request JSON Object:
/// - `name` (string)
/// - `asins` (array of strings) – []
/// - `description` (string)
///
/// Response JSON Object:
/// - `collection_id` (string)
/// - `creation_date` (string)
/// - `customer_id` (string)
/// - `marketplace` (string)
pub async fn post_collections(&self, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/collections", self.base_url);
let mut req = self.client.post(url);
if let Some(params) = params {
req = req.json(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// GET /1.0/collections/(collection_id)
///
/// Parameters:
/// - `collection_id` (string)
pub async fn get_collection_by_id(
&self,
collection_id: &str,
params: Option<Value>,
) -> Result<Value> {
let url = format!("{}/1.0/collections/{}", self.base_url, collection_id);
let mut req = self.client.get(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// PUT /1.0/collections/(collection_id)
/// Modify a collection
///
/// Parameters:
/// - `collection_id` (string)
///
/// Request JSON Object:
/// - `state_token` (string)
/// - `collection_id` (string)
/// - `name` (string)
/// - `description` (string)
///
/// Response JSON Object:
/// - `state_token` (string)
/// - `collection_id` (string)
/// - `name` (string)
/// - `description` (string)
pub async fn put_collection_by_id(
&self,
collection_id: &str,
params: Option<Value>,
) -> Result<Value> {
let url = format!("{}/1.0/collections/{}", self.base_url, collection_id);
let mut req = self.client.put(url);
if let Some(params) = params {
req = req.json(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// GET /1.0/collections/(collection_id)/items
///
/// Parameters:
/// - `collection_id` (string) – e.g. __FAVORITES
///
/// Query Parameters:
/// - `response_groups` (string) – [always-returned]
pub async fn get_items_by_collection_id(
&self,
collection_id: &str,
params: Option<Value>,
) -> Result<Value> {
let url = format!("{}/1.0/collections/{}/items", self.base_url, collection_id);
let mut req = self.client.get(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// POST /1.0/collections/(collection_id)/items
/// Add item(s) to a collection
///
/// Parameters:
/// - `collection_id` (string)
///
/// Request JSON Object:
/// - `collection_id` (string)
/// - `asins` (array of strings) – []
///
/// Response JSON Object:
/// - `description` (string)
/// - `name` (string)
/// - `num_items_added` (integer)
/// - `state_token` (string)
pub async fn post_items_by_collection_id(
&self,
collection_id: &str,
params: Option<Value>,
) -> Result<Value> {
let url = format!("{}/1.0/collections/{}/items", self.base_url, collection_id);
let mut req = self.client.post(url);
if let Some(params) = params {
req = req.json(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
}