reflow_api_services 0.2.1

Generated API-service actor catalog for Reflow — thousands of actors across ~90 third-party services.
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
614
615
616
#![allow(clippy::all, unused_imports, dead_code)]

//! Auto-generated API actors for Firebase
//!
//! Service: Firebase (firebase)
//! Google's mobile and web application development platform
//!
//! Required env var: FIREBASE_API_KEY (OAuth2 access token)
//!
//! Generated by api-schema-gen codegen — do not edit manually.

use crate::{Actor, ActorBehavior, ClientBuilderExt, Message, Port};
use anyhow::{Error, Result};
use reflow_actor::{message::EncodableValue, ActorContext};
use reflow_actor_macro::actor;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::time::Duration;

const BASE_URL: &str = "https://firebase.googleapis.com/v1";
const ENV_KEY: &str = "FIREBASE_API_KEY";

/// Apply authentication to the request builder.
fn apply_auth(
    config: &reflow_actor::ActorConfig,
    mut builder: reqwest::RequestBuilder,
) -> Result<reqwest::RequestBuilder> {
    let credential = config
        .get_config_or_env(ENV_KEY)
        .ok_or_else(|| anyhow::anyhow!("Missing env var: {}", ENV_KEY))?;
    builder = builder.header("Authorization", format!("Bearer {}", credential));
    Ok(builder)
}

/// create document via Firebase API
///
/// Method: POST /projects/{projectId}/databases/{databaseId}/documents/{collectionId}
#[actor(
    FirebaseCreateDocumentActor,
    inports::<100>(projectId, databaseId, collectionId),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_create_document(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint =
        "/projects/{projectId}/databases/{databaseId}/documents/{collectionId}".to_string();
    if let Some(val) = inputs.get("projectId") {
        endpoint = endpoint.replace("{{projectId}}", &super::message_to_str(val));
    }
    if let Some(val) = inputs.get("databaseId") {
        endpoint = endpoint.replace("{{databaseId}}", &super::message_to_str(val));
    }
    if let Some(val) = inputs.get("collectionId") {
        endpoint = endpoint.replace("{{collectionId}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.post(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert("error".to_string(), Message::Error(format!("POST /projects/{{projectId}}/databases/{{databaseId}}/documents/{{collectionId}} failed: {}", e).into()));
        }
    }

    Ok(output)
}

/// read document via Firebase API
///
/// Method: GET /projects/{projectId}/databases/{databaseId}/documents/{documentPath}
#[actor(
    FirebaseReadDocumentActor,
    inports::<100>(projectId, databaseId, documentPath),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_read_document(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint =
        "/projects/{projectId}/databases/{databaseId}/documents/{documentPath}".to_string();
    if let Some(val) = inputs.get("projectId") {
        endpoint = endpoint.replace("{{projectId}}", &super::message_to_str(val));
    }
    if let Some(val) = inputs.get("databaseId") {
        endpoint = endpoint.replace("{{databaseId}}", &super::message_to_str(val));
    }
    if let Some(val) = inputs.get("documentPath") {
        endpoint = endpoint.replace("{{documentPath}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.get(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert("error".to_string(), Message::Error(format!("GET /projects/{{projectId}}/databases/{{databaseId}}/documents/{{documentPath}} failed: {}", e).into()));
        }
    }

    Ok(output)
}

/// Lists each [Google Cloud Platform (GCP) `Project`] (https://cloud.google.com/resource-manager/reference/rest/v1/projects) that can have Firebase resources added to it. A Project will only be listed if: - The caller has sufficient [Google IAM](https://cloud.google.com/iam) permissions to call AddFirebase. - The Project is not already a FirebaseProject. - The Project is not in an Organization which has policies that prevent Firebase resources from being added.
///
/// Method: GET /v1beta1/availableProjects
#[actor(
    FirebaseListAvailableProjectsActor,
    inports::<100>(pageSize, pageToken),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_list_available_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let endpoint = "/v1beta1/availableProjects".to_string();

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.get(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut query_pairs: Vec<(&str, String)> = Vec::new();
    if let Some(val) = inputs.get("pageSize") {
        query_pairs.push(("pageSize", super::message_to_str(val)));
    }
    if let Some(val) = inputs.get("pageToken") {
        query_pairs.push(("pageToken", super::message_to_str(val)));
    }
    if !query_pairs.is_empty() {
        builder = builder.query(&query_pairs);
    }

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("GET /v1beta1/availableProjects failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}

/// Lists each FirebaseProject accessible to the caller. The elements are returned in no particular order, but they will be a consistent view of the Projects when additional requests are made with a `pageToken`. This method is eventually consistent with Project mutations, which means newly provisioned Projects and recent modifications to existing Projects might not be reflected in the set of Projects. The list will include only ACTIVE Projects. Use GetFirebaseProject for consistent reads as well as for additional Project details.
///
/// Method: GET /v1beta1/projects
#[actor(
    FirebaseListProjectsActor,
    inports::<100>(pageSize, pageToken, showDeleted),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_list_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let endpoint = "/v1beta1/projects".to_string();

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.get(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut query_pairs: Vec<(&str, String)> = Vec::new();
    if let Some(val) = inputs.get("pageSize") {
        query_pairs.push(("pageSize", super::message_to_str(val)));
    }
    if let Some(val) = inputs.get("pageToken") {
        query_pairs.push(("pageToken", super::message_to_str(val)));
    }
    if let Some(val) = inputs.get("showDeleted") {
        query_pairs.push(("showDeleted", super::message_to_str(val)));
    }
    if !query_pairs.is_empty() {
        builder = builder.query(&query_pairs);
    }

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("GET /v1beta1/projects failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}

/// Updates the attributes of the specified WebApp.
///
/// Method: PATCH /v1beta1/{name}
#[actor(
    FirebaseUpdateProjectsActor,
    inports::<100>(name, updateMask, projectId, appUrls, state, webId, displayName, appId, apiKeyId, etag, expireTime),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_update_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint = "/v1beta1/{name}".to_string();
    if let Some(val) = inputs.get("name") {
        endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.patch(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut query_pairs: Vec<(&str, String)> = Vec::new();
    if let Some(val) = inputs.get("updateMask") {
        query_pairs.push(("updateMask", super::message_to_str(val)));
    }
    if !query_pairs.is_empty() {
        builder = builder.query(&query_pairs);
    }

    let mut body = serde_json::Map::new();
    if let Some(val) = inputs.get("projectId") {
        body.insert("projectId".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("appUrls") {
        body.insert("appUrls".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("state") {
        body.insert("state".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("name") {
        body.insert("name".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("webId") {
        body.insert("webId".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("displayName") {
        body.insert("displayName".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("appId") {
        body.insert("appId".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("apiKeyId") {
        body.insert("apiKeyId".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("etag") {
        body.insert("etag".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("expireTime") {
        body.insert("expireTime".to_string(), val.clone().into());
    }
    if !body.is_empty() {
        builder = builder.json(&serde_json::Value::Object(body));
    }

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("PATCH /v1beta1/{{name}} failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}

/// Removes a ShaCertificate from the specified AndroidApp.
///
/// Method: DELETE /v1beta1/{name}
#[actor(
    FirebaseDeleteProjectsActor,
    inports::<100>(name),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_delete_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint = "/v1beta1/{name}".to_string();
    if let Some(val) = inputs.get("name") {
        endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.delete(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("DELETE /v1beta1/{{name}} failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}

/// Gets the configuration artifact associated with the specified WebApp.
///
/// Method: GET /v1beta1/{name}
#[actor(
    FirebaseReadProjectsActor,
    inports::<100>(name),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_read_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint = "/v1beta1/{name}".to_string();
    if let Some(val) = inputs.get("name") {
        endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.get(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("GET /v1beta1/{{name}} failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}

/// Removes the specified WebApp from the FirebaseProject.
///
/// Method: POST /v1beta1/{name}:remove
#[actor(
    FirebaseCreateProjectsActor,
    inports::<100>(name, etag, allowMissing, immediate, validateOnly),
    outports::<50>(response, error),
    state(MemoryState)
)]
pub async fn firebase_create_projects(
    context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
    let inputs = context.get_payload();
    let actor_config = context.get_config();

    let mut endpoint = "/v1beta1/{name}:remove".to_string();
    if let Some(val) = inputs.get("name") {
        endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
    }

    let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);

    let client = reqwest::Client::builder()
        .timeout_compat(Duration::from_secs(30))
        .build()?;

    let mut builder = client.post(&url);
    builder = builder.header("Content-Type", "application/json");
    builder = apply_auth(actor_config, builder)?;

    let mut body = serde_json::Map::new();
    if let Some(val) = inputs.get("etag") {
        body.insert("etag".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("allowMissing") {
        body.insert("allowMissing".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("immediate") {
        body.insert("immediate".to_string(), val.clone().into());
    }
    if let Some(val) = inputs.get("validateOnly") {
        body.insert("validateOnly".to_string(), val.clone().into());
    }
    if !body.is_empty() {
        builder = builder.json(&serde_json::Value::Object(body));
    }

    let mut output = HashMap::new();
    match builder.send().await {
        Ok(resp) => {
            let status = resp.status().as_u16();
            let headers: HashMap<String, String> = resp
                .headers()
                .iter()
                .filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
                .collect();
            let body_text = resp.text().await.unwrap_or_default();
            let body_value: Value =
                serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
            output.insert(
                "response".to_string(),
                Message::object(EncodableValue::from(json!({
                    "status": status,
                    "headers": headers,
                    "body": body_value,
                }))),
            );
        }
        Err(e) => {
            output.insert(
                "error".to_string(),
                Message::Error(format!("POST /v1beta1/{{name}}:remove failed: {}", e).into()),
            );
        }
    }

    Ok(output)
}