heroku_rs 0.6.0

Rust bindings for the Heroku API
Documentation
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
//Anything related to POST requests for Teams and it's variations goes here.
use super::{Team, TeamApp, TeamInvitation, TeamMember};

use crate::framework::endpoint::{HerokuEndpoint, Method};

/// Team Create
///
/// Create a new team.
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#team-create)
///
/// # Example:
///
/// TeamCreate takes one required parameter, name, and returns the created [`Team`][response].
/// ```rust
/// use heroku_rs::prelude::*;
///
///#    let api_client = HttpApiClient::create("API_KEY").unwrap();
/// //only the parameter inside the method `new` is required, all others are optional parameters
/// let response = api_client.request(
///     &TeamCreate::new("herokursteam2020")
///         .address_1("my-first-adress")
///         .address_2("my-second-adress")
///         .card_number("encrypted-card-number")
///         .city("San Francisco")
///         .country("US")
///         .cvv("123")
///         .device_data("VGhpcyBpcyBhIGdvb2QgZGF5IHRvIGRpZQ==")
///         .expiration_month("11")
///         .expiration_year("2014")
///         .first_name("Jason")
///         .last_name("Walker")
///         .nonce("VGhpcyBpcyBhIGdvb2QgZGF5IHRvIGRpZQ==")
///         .other("Additional information for payment method")
///         .postal_code("90210")
///         .state("CA")
///         .build(),
/// );
///
///match response {
///     Ok(success) => println!("Success: {:#?}", success),
///     Err(e) => println!("Error: {}", e),
///}
//
/// ```
/// See how to create the Heroku [`api_client`][httpApiClientConfig].
///
/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
/// [response]: ../struct.Team.html
pub struct TeamCreate<'a> {
    pub params: TeamCreateParams<'a>,
}

#[cfg(feature = "builder")]
impl<'a> TeamCreate<'a> {
    // `new` method has only the required parameters
    pub fn new(name: &'a str) -> TeamCreate {
        TeamCreate {
            params: TeamCreateParams {
                name: name,
                address_1: None,
                address_2: None,
                card_number: None,
                city: None,
                country: None,
                cvv: None,
                expiration_month: None,
                expiration_year: None,
                first_name: None,
                last_name: None,
                other: None,
                postal_code: None,
                state: None,
                nonce: None,
                device_data: None,
            },
        }
    }

    /// # address_1: street address line 1
    pub fn address_1(&mut self, address_1: &'a str) -> &mut Self {
        self.params.address_1 = Some(address_1);
        self
    }

    /// # address_2: street address line 2
    pub fn address_2(&mut self, address_2: &'a str) -> &mut Self {
        self.params.address_2 = Some(address_2);
        self
    }

    /// # card_number: encrypted card number of payment method
    pub fn card_number(&mut self, card_number: &'a str) -> &mut Self {
        self.params.card_number = Some(card_number);
        self
    }

    /// # city: city
    pub fn city(&mut self, city: &'a str) -> &mut Self {
        self.params.city = Some(city);
        self
    }

    /// # country: country
    pub fn country(&mut self, country: &'a str) -> &mut Self {
        self.params.country = Some(country);
        self
    }

    /// # cvv: card verification value
    pub fn cvv(&mut self, cvv: &'a str) -> &mut Self {
        self.params.cvv = Some(cvv);
        self
    }

    /// # expiration_month: expiration month
    pub fn expiration_month(&mut self, expiration_month: &'a str) -> &mut Self {
        self.params.expiration_month = Some(expiration_month);
        self
    }

    /// # expiration_year: expiration year
    pub fn expiration_year(&mut self, expiration_year: &'a str) -> &mut Self {
        self.params.expiration_year = Some(expiration_year);
        self
    }

    /// # first_name: the first name for payment method
    pub fn first_name(&mut self, first_name: &'a str) -> &mut Self {
        self.params.first_name = Some(first_name);
        self
    }

    /// # last_name: the last name for payment method
    pub fn last_name(&mut self, last_name: &'a str) -> &mut Self {
        self.params.last_name = Some(last_name);
        self
    }

    /// # other: metadata
    pub fn other(&mut self, other: &'a str) -> &mut Self {
        self.params.other = Some(other);
        self
    }

    /// # postal_code: postal code
    pub fn postal_code(&mut self, postal_code: &'a str) -> &mut Self {
        self.params.postal_code = Some(postal_code);
        self
    }
    /// # state:state
    pub fn state(&mut self, state: &'a str) -> &mut Self {
        self.params.state = Some(state);
        self
    }

    /// # nonce: Nonce generated by Braintree hosted fields form
    pub fn nonce(&mut self, nonce: &'a str) -> &mut Self {
        self.params.nonce = Some(nonce);
        self
    }

    /// # device_data: Device data string generated by the client
    pub fn device_data(&mut self, device_data: &'a str) -> &mut Self {
        self.params.device_data = Some(device_data);
        self
    }

    pub fn build(&self) -> TeamCreate<'a> {
        TeamCreate {
            params: TeamCreateParams {
                name: self.params.name,
                address_1: self.params.address_1,
                address_2: self.params.address_2,
                card_number: self.params.card_number,
                city: self.params.city,
                country: self.params.country,
                cvv: self.params.cvv,
                expiration_month: self.params.expiration_month,
                expiration_year: self.params.expiration_year,
                first_name: self.params.first_name,
                last_name: self.params.last_name,
                other: self.params.other,
                postal_code: self.params.postal_code,
                state: self.params.state,
                nonce: self.params.nonce,
                device_data: self.params.device_data,
            },
        }
    }
}

/// Create a new team with parameters
///
/// Only the name is required
///
/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#team-create-required-parameters)
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct TeamCreateParams<'a> {
    /// unique name of team
    pub name: &'a str,
    /// street address line 1
    pub address_1: Option<&'a str>,
    /// street address line 2
    pub address_2: Option<&'a str>,
    /// encrypted card number of payment method
    pub card_number: Option<&'a str>,
    /// city
    pub city: Option<&'a str>,
    /// country
    pub country: Option<&'a str>,
    /// card verification value
    pub cvv: Option<&'a str>,
    /// expiration month
    pub expiration_month: Option<&'a str>,
    /// expiration year
    pub expiration_year: Option<&'a str>,
    /// the first name for payment method
    pub first_name: Option<&'a str>,
    /// the last name for payment method
    pub last_name: Option<&'a str>,
    /// metadata
    pub other: Option<&'a str>,
    /// postal code
    pub postal_code: Option<&'a str>,
    /// state
    pub state: Option<&'a str>,
    /// Nonce generated by Braintree hosted fields form
    pub nonce: Option<&'a str>,
    /// Device data string generated by the client
    pub device_data: Option<&'a str>,
}

impl<'a> HerokuEndpoint<Team, (), TeamCreateParams<'a>> for TeamCreate<'a> {
    fn method(&self) -> Method {
        Method::Post
    }
    fn path(&self) -> String {
        format!("teams")
    }
    fn body(&self) -> Option<TeamCreateParams<'a>> {
        Some(self.params.clone())
    }
}

/// Team Create in Enterprise Account
///
/// Create a team in an enterprise account.
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#team-create-in-enterprise-account)
///
/// # Example:
///
/// TeamCreateByEA takes two required parameters, account_id and name, and returns the created [`Team`][response].
/// ```rust
/// use heroku_rs::prelude::*;
///
///#    let api_client = HttpApiClient::create("API_KEY").unwrap();
/// let response = api_client.request(
///     &TeamCreateByEA::new("ACCOUNT_ID", "TEAM_NAME"));
///
///match response {
///     Ok(success) => println!("Success: {:#?}", success),
///     Err(e) => println!("Error: {}", e),
///}
//
/// ```
/// See how to create the Heroku [`api_client`][httpApiClientConfig].
///
/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
/// [response]: ../struct.Team.html
pub struct TeamCreateByEA<'a> {
    /// unique account identifier
    pub account_id: &'a str,
    /// parameters to pass to Heroku
    pub params: TeamCreateByEAParams<'a>,
}

#[cfg(feature = "builder")]
impl<'a> TeamCreateByEA<'a> {
    pub fn new(account_id: &'a str, name: &'a str) -> TeamCreateByEA<'a> {
        TeamCreateByEA {
            account_id: account_id,
            params: TeamCreateByEAParams { name },
        }
    }
}

/// Create a new team in an enterprise account with required parametesrs
///
/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#team-create-in-enterprise-account-required-parameters)
#[derive(Serialize, Clone, Debug)]
pub struct TeamCreateByEAParams<'a> {
    /// unique name of team
    pub name: &'a str,
}

impl<'a> HerokuEndpoint<Team, (), TeamCreateByEAParams<'a>> for TeamCreateByEA<'a> {
    fn method(&self) -> Method {
        Method::Post
    }
    fn path(&self) -> String {
        format!("enterprise-accounts/{}/teams", self.account_id)
    }
    fn body(&self) -> Option<TeamCreateByEAParams<'a>> {
        Some(self.params.clone())
    }
}

/// Team App Create
///
/// Create a new app in the specified team, in the default team if unspecified, or in personal account, if default team is not set.
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#team-app-create)
///
/// # Example:
///
/// TeamAppCreate takes no required parameters, and returns the created [`TeamApp`][response].
/// ```rust
/// use heroku_rs::prelude::*;
///
///#    let api_client = HttpApiClient::create("API_KEY").unwrap();
/// let response = api_client.request(
///     &TeamAppCreate::new()
///         .locked(true)
///         .name("team-app")
///         .team("My-team-name")
///         .personal(true)
///         .region("us")
///         .space("-(?!-))+[a-z0-9]$`")
///         .stack("cedar-14")
///         .internal_routing(false)
///         .build(),
/// );
///
///match response {
///     Ok(success) => println!("Success: {:#?}", success),
///     Err(e) => println!("Error: {}", e),
///}
//
/// ```
/// See how to create the Heroku [`api_client`][httpApiClientConfig].
///
/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
/// [response]: ../struct.TeamApp.html
pub struct TeamAppCreate<'a> {
    pub params: TeamAppCreateParams<'a>,
}

#[cfg(feature = "builder")]
impl<'a> TeamAppCreate<'a> {
    pub fn new() -> TeamAppCreate<'a> {
        TeamAppCreate {
            params: TeamAppCreateParams {
                locked: None,
                name: None,
                team: None,
                personal: None,
                region: None,
                space: None,
                stack: None,
                internal_routing: None,
            },
        }
    }

    /// # locked: are other team members forbidden from joining this app.
    pub fn locked(&mut self, locked: bool) -> &mut Self {
        self.params.locked = Some(locked);
        self
    }

    /// # name: name of app
    ///
    /// `pattern`:  pattern: ^[a-z][a-z0-9-]{1,28}[a-z0-9]$
    pub fn name(&mut self, name: &'a str) -> &mut Self {
        self.params.name = Some(name);
        self
    }

    /// # team: unique name of team
    pub fn team(&mut self, team: &'a str) -> &mut Self {
        self.params.team = Some(team);
        self
    }

    /// # personal: force creation of the app in the user account even if a default team is set.
    pub fn personal(&mut self, personal: bool) -> &mut Self {
        self.params.personal = Some(personal);
        self
    }

    /// # region: name of region
    pub fn region(&mut self, region: &'a str) -> &mut Self {
        self.params.region = Some(region);
        self
    }

    /// # space: unique name of space
    ///
    /// `pattern`: pattern: `^[a-z0-9](?:[a-z0-9]
    pub fn space(&mut self, space: &'a str) -> &mut Self {
        self.params.space = Some(space);
        self
    }

    /// # stack: unique name
    pub fn stack(&mut self, stack: &'a str) -> &mut Self {
        self.params.stack = Some(stack);
        self
    }

    /// # internal_routing: describes whether a Private Spaces app is externally routable or not
    pub fn internal_routing(&mut self, internal_routing: bool) -> &mut Self {
        self.params.internal_routing = Some(internal_routing);
        self
    }

    pub fn build(&self) -> TeamAppCreate<'a> {
        TeamAppCreate {
            params: TeamAppCreateParams {
                locked: self.params.locked,
                name: self.params.name,
                team: self.params.team,
                personal: self.params.personal,
                region: self.params.region,
                space: self.params.space,
                stack: self.params.stack,
                internal_routing: self.params.internal_routing,
            },
        }
    }
}

/// Create a new team app with parameters
///
/// All parameters are optional
///
/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#team-app-create-optional-parameters)
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct TeamAppCreateParams<'a> {
    /// are other team members forbidden from joining this app.
    pub locked: Option<bool>,
    /// name of app
    /// pattern: ^[a-z][a-z0-9-]{1,28}[a-z0-9]$
    pub name: Option<&'a str>,
    /// unique name of team
    pub team: Option<&'a str>,
    /// force creation of the app in the user account even if a default team is set.
    pub personal: Option<bool>,
    /// name of region
    pub region: Option<&'a str>,
    /// unique name of space
    ///  pattern: `^[a-z0-9](?:[a-z0-9]
    pub space: Option<&'a str>,
    /// unique name
    pub stack: Option<&'a str>,
    /// describes whether a Private Spaces app is externally routable or not
    pub internal_routing: Option<bool>,
}

impl<'a> HerokuEndpoint<TeamApp, (), TeamAppCreateParams<'a>> for TeamAppCreate<'a> {
    fn method(&self) -> Method {
        Method::Post
    }
    fn path(&self) -> String {
        format!("teams/apps")
    }
    fn body(&self) -> Option<TeamAppCreateParams<'a>> {
        Some(self.params.clone())
    }
}

/// Team Invitation Accept
///
/// Accept Team Invitation
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#team-invitation-accept)
///
/// # Example:
///
/// TeamInvitationAccept takes one required parameter, token_id, and returns the [`TeamInvitation`][response].
/// ```rust
/// use heroku_rs::prelude::*;
///
///#    let api_client = HttpApiClient::create("API_KEY").unwrap();
/// let response = api_client.request(
///     &TeamInvitationAccept::new("TOKEN_ID"));
///
///match response {
///     Ok(success) => println!("Success: {:#?}", success),
///     Err(e) => println!("Error: {}", e),
///}
//
/// ```
/// See how to create the Heroku [`api_client`][httpApiClientConfig].
///
/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
/// [response]: ../struct.TeamInvitation.html
pub struct TeamInvitationAccept<'a> {
    /// unique token identifier
    pub token_id: &'a str,
}

#[cfg(feature = "builder")]
impl<'a> TeamInvitationAccept<'a> {
    pub fn new(token_id: &'a str) -> TeamInvitationAccept<'a> {
        TeamInvitationAccept { token_id }
    }
}

impl<'a> HerokuEndpoint<TeamInvitation> for TeamInvitationAccept<'a> {
    fn method(&self) -> Method {
        Method::Post
    }
    fn path(&self) -> String {
        format!("teams/invitations/{}/accept", self.token_id)
    }
}

/// Team Member Create
///
/// Create a new team member.
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#team-member-create)
///
/// # Example:
///
/// TeamMemberUpdate takes three required parameters, team_id email and role and returns the [`TeamMember`][response].
/// ```rust
/// use heroku_rs::prelude::*;
///#    let api_client = HttpApiClient::create("API_KEY").unwrap();
///
/// let response = api_client.request(&TeamMemberCreate::new("TEAM_ID", "EMAIL", "ROLE"));
///
///match response {
///     Ok(success) => println!("Success: {:#?}", success),
///     Err(e) => println!("Error: {}", e),
///}
//
/// ```
/// See how to create the Heroku [`api_client`][httpApiClientConfig].
///
/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
/// [response]: ../struct.TeamMember.html
pub struct TeamMemberCreate<'a> {
    /// unique team identifier
    pub team_id: &'a str,
    /// parameters to pass to Heroku
    pub params: TeamMemberCreateParams<'a>,
}

#[cfg(feature = "builder")]
impl<'a> TeamMemberCreate<'a> {
    /// Only required parameters passed
    pub fn new(team_id: &'a str, email: &'a str, role: &'a str) -> TeamMemberCreate<'a> {
        TeamMemberCreate {
            team_id,
            params: TeamMemberCreateParams {
                email: email,
                role: role,
                federated: None,
            },
        }
    }

    /// # federated: whether the user is federated and belongs to an Identity Provider
    pub fn federated(&mut self, federated: bool) -> &mut Self {
        self.params.federated = Some(federated);
        self
    }

    pub fn build(&self) -> TeamMemberCreate<'a> {
        TeamMemberCreate {
            team_id: self.team_id,
            params: TeamMemberCreateParams {
                email: self.params.email,
                role: self.params.role,
                federated: self.params.federated,
            },
        }
    }
}

/// Create team member with parameters
///
/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#team-member-create-required-parameters)
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct TeamMemberCreateParams<'a> {
    /// unique email address
    pub email: &'a str,
    /// Even though marked with `Option`, this parameter is NOT optional.
    /// role in the team
    /// one of:"admin" or "collaborator" or "member" or "owner" or null
    pub role: &'a str,
    /// whether the user is federated and belongs to an Identity Provider
    pub federated: Option<bool>,
}

impl<'a> HerokuEndpoint<TeamMember, (), TeamMemberCreateParams<'a>> for TeamMemberCreate<'a> {
    fn method(&self) -> Method {
        Method::Post
    }
    fn path(&self) -> String {
        format!("teams/{}/members", self.team_id)
    }
    fn body(&self) -> Option<TeamMemberCreateParams<'a>> {
        Some(self.params.clone())
    }
}