stcloud/apis/
logs_usage_api_controller_api.rs1#![allow(unused_imports)]
11use std::sync::Arc;
12use std::borrow::Borrow;
13use std::borrow::Cow;
14use std::collections::HashMap;
15
16use hyper;
17use serde_json;
18use serde_json::Value;
19use tokio::runtime::Runtime;
20use futures;
21use futures::{Future, Stream};
22use bigdecimal::BigDecimal;
23
24use hyper::Body;
25use hyper::body::Bytes;
26use hyper::body::HttpBody;
27use std::str::FromStr;
28use chrono::{Date, NaiveDateTime, DateTime, FixedOffset, Utc, SecondsFormat};
29use crate::{OutlinePrint};
30use crate::models::*;
31use super::{Error, configuration};
32use headers::{Authorization, Header};
33use headers::authorization::Credentials;
34
35pub struct LogsUsageApiControllerApiClient<C: hyper::client::connect::Connect + Clone + Send + Sync> {
36 configuration: Arc<configuration::Configuration<C>>,
37}
38
39impl<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static> LogsUsageApiControllerApiClient<C> {
40 pub fn new(configuration: Arc<configuration::Configuration<C>>) -> LogsUsageApiControllerApiClient<C> {
41 LogsUsageApiControllerApiClient {
42 configuration: configuration,
43 }
44 }
45}
46
47#[async_trait::async_trait]
48pub trait LogsUsageApiControllerApi {
49 async fn get_for_range_using_get(&self, app_id: i64, from: i64, to: i64) -> Result<UsageResponse, Error<serde_json::Value>>;
50}
51
52#[async_trait::async_trait]
53impl<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static>LogsUsageApiControllerApi for LogsUsageApiControllerApiClient<C> {
54 async fn get_for_range_using_get(&self, app_id: i64, from: i64, to: i64) -> Result<UsageResponse, Error<serde_json::Value>> {
71 let configuration: &configuration::Configuration<C> = self.configuration.borrow();
72
73 let mut auth_headers = HashMap::<String, String>::new();
74 let mut auth_query = HashMap::<String, String>::new();
75 if let Some(ref apikey) = configuration.api_key {
76 let key = apikey.key.clone();
77 let val = match apikey.prefix {
78 Some(ref prefix) => format!("{} {}", prefix, key),
79 None => key,
80 };
81 auth_headers.insert("Authorization".to_owned(), val);
82 };
83 let method = hyper::Method::GET;
84
85 let query_string = {
86 let mut query = ::url::form_urlencoded::Serializer::new(String::new());
87 let has_query_params = false;
88 for (key, val) in &auth_query {
89 query.append_pair(key, val);
90 }
91 if has_query_params || auth_query.len()>0 {
92 format!("/?{}", query.finish())
93 } else {
94 "".to_string()
95 }
96 };
97 let uri_str = format!("{}logsene-reports/api/v3/apps/{appId}/usage/{from}/{to}{}", configuration.base_path, query_string, appId=app_id, from=from, to=to);
98
99 let uri: hyper::Uri = uri_str.parse().unwrap();
106
107 let mut req =
108 hyper::Request::builder()
109 .method(method)
110 .uri(uri);
111
112 let headers = req.headers_mut().unwrap();
113
114 if let Some(ref user_agent) = configuration.user_agent {
115 headers.insert(hyper::header::USER_AGENT, user_agent.parse().unwrap());
116 }
117
118
119 for (key, val) in auth_headers {
120 headers.insert(
121 hyper::header::HeaderName::from_str(key.as_ref()).unwrap(),
122 val.parse().unwrap(),
123 );
124 }
125
126 let somebody = Body::empty();
127
128 let req = req.body(somebody).unwrap();
129
130 let res = configuration
131 .client.request(req)
132 .await
133 .map_err(|e| -> Error<serde_json::Value> { Error::from(e) });
134
135 let mut res = res?;
136
137 let status = res.status();
138 let mut res_body: Vec<u8> = vec![];
139
140 while let Some(chunk) = res.body_mut().data().await {
141 let mut chunk_vec = chunk.unwrap().to_vec();
142 res_body.append(chunk_vec.as_mut());
143 }
144
145 let res_body =
158 if status.is_success() {
159 Ok(res_body)
160 } else {
161 Err(Error::from((status, res_body.borrow())))
162 };
163
164 let mut res_body = res_body?;
165
166 let res_body =
167 serde_json::from_slice(res_body.borrow())
168 .map_err(|e| -> Error<serde_json::Value> { Error::from(e) });
169
170 res_body
171 }
172
173}