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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//! Simple crate to login to Pinterest and get the cookies via Chromiumoxide to simulate a browser (open a real browser actually), to use the Pinterest API without needing a developer account or an API key or anything that costs money :).
//!
//! [](https://crates.io/crates/pinterest-login)
//! [](https://docs.rs/pinterest-login)
//! [](https://crates.io/crates/pinterest-login)
//! [][mit]
//!
//! Asynchronous, and uses async-std as the runtime by default (you can use tokio if you want)
//!
//! # Examples
//!
//! ## With the `async-std` runtime
//!
//! ```ignore
//! use pinterest_login::config_builder::DefaultBrowserConfigBuilder;
//! use pinterest_login::login;
//! use pinterest_login::login_bot::DefaultBrowserLoginBot;
//!
//! #[async_std::main]
//! async fn main() {
//! let email = std::env::var("PINTEREST_EMAIL").unwrap();
//! let password = std::env::var("PINTEREST_PASSWORD").unwrap();
//!
//! let bot = DefaultBrowserLoginBot::new(email.as_str(), password.as_str());
//! let config_builder = DefaultBrowserConfigBuilder::default();
//!
//! match login(&bot, &config_builder).await {
//! Ok(cookies) => {
//! // Store the cookies in a file or something, and do whatever you want with them
//! // I like the cookies bay the way
//! // ...
//! println!("{}", cookies.len());
//! println!("{:?}", cookies);
//! }
//! Err(e) => {
//! // The login was unsuccessful
//! eprintln!("The login was unsuccessful: {}", e);
//! }
//! };
//! }
//! ```
//! ```ignore
//! use pinterest_login::config_builder::DefaultBrowserConfigBuilder;
//! use pinterest_login::login;
//! use pinterest_login::login_bot::DefaultBrowserLoginBot;
//! use std::time::Duration;
//!
//! #[async_std::main]
//! async fn main() {
//! let email = std::env::var("PINTEREST_EMAIL").unwrap();
//! let password = std::env::var("PINTEREST_PASSWORD").unwrap();
//!
//! let bot = DefaultBrowserLoginBot::new(email.as_str(), password.as_str());
//!
//! // Show the browser, and set the request timeout to 2 seconds
//! let config_builder = DefaultBrowserConfigBuilder::new(false, Duration::from_secs(2).into(), None);
//!
//! match login(&bot, &config_builder).await {
//! Ok(cookies) => {
//! // ...
//! }
//! Err(e) => {
//! // The login was unsuccessful
//! eprintln!("The login was unsuccessful: {}", e);
//! }
//! };
//! }
//! ```
//!
//! ## With `tokio` runtime
//! ```ignore
//! use pinterest_login::config_builder::DefaultBrowserConfigBuilder;
//! use pinterest_login::login;
//! use pinterest_login::login_bot::DefaultBrowserLoginBot;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() {
//! let email = std::env::var("PINTEREST_EMAIL").unwrap();
//! let password = std::env::var("PINTEREST_PASSWORD").unwrap();
//!
//! let bot = DefaultBrowserLoginBot::new(email.as_str(), password.as_str());
//!
//! // Show the browser, and set the request timeout to 2 seconds
//! let config_builder = DefaultBrowserConfigBuilder::new(false, Duration::from_secs(2).into(), None);
//!
//! match login(&bot, &config_builder).await {
//! Ok(cookies) => {
//! // ...
//! }
//! Err(e) => {
//! // The login was unsuccessful
//! eprintln!("The login was unsuccessful: {}", e);
//! }
//! };
//! }
//! ```
//!
//! # Features
//! * `async-std-runtime`: Use the async-std runtime instead of tokio (enabled by default)
//! * `tokio-runtime`: Use the tokio runtime instead of async-std
//! * `debug`: Enable debug logging
//!
//!
//! # Contributing
//! I'm happy to accept any contributions, just consider reading the [CONTRIBUTING.md](https://github.com/0x61nas/pinterest-login/blob/aurora/CONTRIBUTING.md) guide first. to avoid waste waste our time on some unnecessary things.
//!
//! > the main keywords are: **signed commits**, **conventional commits**, **no emojis**, **linear history**, **the PR shouldn't have more than tree commits most of the time**
//!
//! # License
//! This project is licensed under ether the [MIT license][mit] or the [Unlicense license][unlicense], you can choose which one you want.
//!
//! [mit]: https://github.com/0x61nas/pinterest-login/blob/aurora/LICENSE
//! [unlicense]: https://github.com/0x61nas/pinterest-login/blob/aurora/LICENSE-UNLICENSE
//!
//!
//! > This project is part of the [pinterest-rs](https://github.com/0x61nas/pinterest-rs) project
/// The chromiumoxide browser config builder
/// The pinterest login bot
use HashMap;
// #[cfg(feature = "async-std-runtime")]
// use async_std::prelude::StreamExt;
use StreamExt;
use Browser;
use crateBrowserConfigBuilder;
use crateBrowserLoginBot;
use ;
/// The pinterest login url
pub const PINTEREST_LOGIN_URL: &str = "https://pinterest.com/login";
/// Pinterest login error type
/// A type alias for `Result<T, PinterestLoginError>`
pub type Result<T> = Result;
/// Logs into Pinterest and returns the cookies as a HashMap
///
/// # Arguments
/// * `login_bot` - The login bot to use to fill and submit the login form
/// * `browser_config_builder` - The browser config builder to use to build the browser config
///
/// # Example
/// ```ignore
/// # use std::collections::HashMap;
/// # use pinterest_login::config_builder::DefaultBrowserConfigBuilder;
/// # use pinterest_login::login;
/// # use pinterest_login::login_bot::DefaultBrowserLoginBot;
///
/// async fn login_to_pinterest(email: &str, password: &str) -> pinterest_login::Result<HashMap<String, String>> {
/// let browser_config_builder = DefaultBrowserConfigBuilder::default();
/// let bot = DefaultBrowserLoginBot::new(email, password);
///
/// let cookies = login(&bot, &browser_config_builder).await?;
/// Ok(cookies)
/// }
/// ```
///
/// # Errors
/// * `CdpError` - If there is an error with chromiumoxide (like launching timeout, or request timeout, network error, etc.) see [chromiumoxide::error::CdpError](https://docs.rs/chromiumoxide/latest/chromiumoxide/error/enum.CdpError.html) to see all the errors
/// * `BrowserConfigBuildError` - If there is an error building the browser config
/// * `AuthenticationError` - If the email or password is incorrect
///
pub async