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
//! Client Library: Client Functions, Structs, Traits
/// gRPC object traits to provide wrappers for grpc functions
#[tonic::async_trait]
pub trait Client<T>
where
    Self: Sized + lib_common::grpc::Client<T> + lib_common::grpc::ClientConnect<T>,
    T: Send + Clone,
{
    /// The type expected for ReadyRequest structs.
    type ReadyRequest;
    /// The type expected for ReadyResponse structs.
    type ReadyResponse;
    /// The type expected for PricingRequests structs.
    type PricingRequests;
    /// The type expected for PricingResponse structs.
    type PricingResponse;

    /// Returns a [`tonic::Response`] containing a [`ReadyResponse`](Self::ReadyResponse)
    /// Takes an [`ReadyRequest`](Self::ReadyRequest).
    ///
    /// # Errors
    ///
    /// Returns [`tonic::Status`] with [`Code::Unknown`](tonic::Code::Unknown) if
    /// the server is not ready.
    ///
    /// # Examples
    /// ```
    /// use lib_common::grpc::get_endpoint_from_env;
    /// use svc_pricing_client_grpc::client::{ReadyRequest, RpcServiceClient};
    /// use svc_pricing_client_grpc::{Client, GrpcClient};
    /// use svc_pricing_client_grpc::service::Client as ServiceClient;
    /// use tonic::transport::Channel;
    ///
    /// async fn example () -> Result<(), Box<dyn std::error::Error>> {
    ///     let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    ///     let connection = GrpcClient::<RpcServiceClient<Channel>>::new_client(&host, port, "pricing");
    ///     let response = connection
    ///         .is_ready(ReadyRequest {})
    ///         .await?;
    ///     println!("RESPONSE={:?}", response.into_inner());
    ///     Ok(())
    /// }
    /// ```
    async fn is_ready(
        &self,
        request: Self::ReadyRequest,
    ) -> Result<tonic::Response<Self::ReadyResponse>, tonic::Status>;

    /// Returns a [`tonic::Response`] containing a [`PricingResponse`](Self::PricingResponse)
    /// Takes an [`PricingRequests`](Self::PricingRequests).
    ///
    /// # Errors
    ///
    /// Returns [`tonic::Status`] with [`Code::Internal`](tonic::Code::Internal) if
    /// no pricing could be determined.
    ///
    /// # Examples
    /// ```
    /// use lib_common::grpc::get_endpoint_from_env;
    /// use svc_pricing_client_grpc::client::{PricingRequests, PricingRequest, RpcServiceClient};
    /// use svc_pricing_client_grpc::{Client, GrpcClient};
    /// use svc_pricing_client_grpc::service::Client as ServiceClient;
    /// use tonic::transport::Channel;
    ///
    /// async fn example () -> Result<(), Box<dyn std::error::Error>> {
    ///     let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    ///     let connection = GrpcClient::<RpcServiceClient<Channel>>::new_client(&host, port, "pricing");
    ///     let query = PricingRequests {
    ///         requests: vec![PricingRequest {
    ///             service_type: 0,
    ///             weight_kg: 100.0,
    ///             distance_km: 100.0,
    ///         }]
    ///     };
    ///     let response = connection.get_pricing(query).await?;
    ///     println!("RESPONSE={:?}", response.into_inner());
    ///     Ok(())
    /// }
    /// ```
    async fn get_pricing(
        &self,
        request: Self::PricingRequests,
    ) -> Result<tonic::Response<Self::PricingResponse>, tonic::Status>;
}