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
pub use graphql::GraphQLMultipart;
pub use graphql::GraphQLRequest;
use reqwest::Method;
pub use rest::{RestMultipart, RestRequest};
use serde::Serialize;

use crate::errors::PrimaBridgeResult;
use crate::request::GraphQLBody;
use crate::BridgeClient;
use crate::BridgeImpl;

use super::DeliverableRequest;

mod graphql;
mod rest;

/// A utility type to construct requests more easily.
pub struct Request;

impl Request {
    /// Create a new GraphQL request
    pub fn graphql<S: Serialize, Client: BridgeClient>(
        bridge: &BridgeImpl<Client>,
        graphql_body: impl Into<GraphQLBody<S>>,
    ) -> PrimaBridgeResult<GraphQLRequest<Client>> {
        GraphQLRequest::new(bridge, graphql_body)
    }

    /// Create a new REST request
    pub fn rest<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        Self::get(bridge)
    }

    /// Create a new GET REST request
    pub fn get<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        RestRequest::new(bridge)
    }

    /// Create a new POST REST request
    pub fn post<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        RestRequest::new(bridge).method(Method::POST)
    }

    /// Create a new PATCH REST request
    pub fn patch<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        RestRequest::new(bridge).method(Method::PATCH)
    }

    /// Create a new DELETE REST request
    pub fn delete<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        RestRequest::new(bridge).method(Method::DELETE)
    }

    /// Create a new PUT REST request
    pub fn put<Client: BridgeClient>(bridge: &BridgeImpl<Client>) -> RestRequest<Client> {
        RestRequest::new(bridge).method(Method::PUT)
    }
}