heroku_rs/endpoints/logs/post.rs
1//Anything related to POST requests for heroku logs and it's properties goes here.
2use super::{LogDrain, LogSession};
3
4use crate::framework::endpoint::{HerokuEndpoint, Method};
5
6/// Log Drain Create
7///
8/// Create a new log drain.
9///
10/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#log-drain-create)
11///
12/// # Example:
13///
14/// LogDrainCreate takes two required parameters, app_id and url, and returns the new [`LogDrain`][response].
15/// ```rust
16/// use heroku_rs::prelude::*;
17///# let api_client = HttpApiClient::create("API_KEY").unwrap();
18///
19/// let url = "https://mycoolherokuappname.herokuapp.com/";
20/// let response = api_client.request(&LogDrainCreate::new("APP_ID", url));
21///
22///match response {
23/// Ok(success) => println!("Success: {:#?}", success),
24/// Err(e) => println!("Error: {}", e),
25///}
26///
27/// ```
28/// See how to create the Heroku [`api_client`][httpApiClientConfig].
29///
30/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
31/// [response]: ../struct.LogDrain.html
32pub struct LogDrainCreate<'a> {
33 /// unique app identifier, either app name, or app id
34 pub app_id: &'a str,
35 /// The parameters to pass to the Heroku API
36 pub params: LogDrainCreateParams<'a>,
37}
38
39#[cfg(feature = "builder")]
40impl<'a> LogDrainCreate<'a> {
41 pub fn new(app_id: &'a str, url: &'a str) -> LogDrainCreate<'a> {
42 LogDrainCreate {
43 app_id,
44 params: LogDrainCreateParams { url },
45 }
46 }
47}
48
49/// Create a new log drain with parameters.
50///
51/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#log-drain-create-required-parameters)
52#[derive(Serialize, Clone, Debug)]
53pub struct LogDrainCreateParams<'a> {
54 /// url associated with the log drain
55 pub url: &'a str,
56}
57
58impl<'a> HerokuEndpoint<LogDrain, (), LogDrainCreateParams<'a>> for LogDrainCreate<'a> {
59 fn method(&self) -> Method {
60 Method::Post
61 }
62 fn path(&self) -> String {
63 format!("apps/{}/log-drains", self.app_id)
64 }
65 fn body(&self) -> Option<LogDrainCreateParams<'a>> {
66 Some(self.params.clone())
67 }
68}
69
70/// Log Session Create
71///
72/// Create a new log session.
73///
74/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/articles/platform-api-reference#log-session-create)
75///
76/// # Example:
77///
78/// LogSessionCreate takes one required parameter, app_id, and returns the new [`LogSession`][response].
79/// ```rust
80/// use heroku_rs::prelude::*;
81///# let api_client = HttpApiClient::create("API_KEY").unwrap();
82///
83/// let response = api_client.request(
84/// &LogSessionCreate::new("APP_ID")
85/// .dyno("web.1")
86/// .source("app")
87/// .lines(10)
88/// .tail(false)
89/// .build(),
90/// );
91///
92///match response {
93/// Ok(success) => println!("Success: {:#?}", success),
94/// Err(e) => println!("Error: {}", e),
95///}
96///
97/// ```
98/// See how to create the Heroku [`api_client`][httpApiClientConfig].
99///
100/// [httpApiClientConfig]: ../../../framework/struct.HttpApiClient.html
101/// [response]: ../struct.LogSession.html
102pub struct LogSessionCreate<'a> {
103 /// unique app identifier, either app name, or app id
104 pub app_id: &'a str,
105 /// The parameters to pass to the Heroku API
106 pub params: LogSessionCreateParams<'a>,
107}
108
109#[cfg(feature = "builder")]
110impl<'a> LogSessionCreate<'a> {
111 /// Create a new log session with required parameters
112 pub fn new(app_id: &'a str) -> LogSessionCreate<'a> {
113 LogSessionCreate {
114 app_id,
115 params: LogSessionCreateParams {
116 dyno: None,
117 lines: None,
118 source: None,
119 tail: None,
120 },
121 }
122 }
123
124 /// # dyno: dyno to limit results to
125 pub fn dyno(&mut self, dyno: &'a str) -> &mut Self {
126 self.params.dyno = Some(dyno);
127 self
128 }
129 /// # lines: number of log lines to stream at once
130 pub fn lines(&mut self, lines: i64) -> &mut Self {
131 self.params.lines = Some(lines);
132 self
133 }
134 /// # source: log source to limit results to
135 pub fn source(&mut self, source: &'a str) -> &mut Self {
136 self.params.source = Some(source);
137 self
138 }
139 /// # tail: whether to stream ongoing logs
140 pub fn tail(&mut self, tail: bool) -> &mut Self {
141 self.params.tail = Some(tail);
142 self
143 }
144
145 pub fn build(&self) -> LogSessionCreate<'a> {
146 LogSessionCreate {
147 app_id: self.app_id,
148 params: LogSessionCreateParams {
149 dyno: self.params.dyno,
150 lines: self.params.lines,
151 source: self.params.source,
152 tail: self.params.tail,
153 },
154 }
155 }
156}
157
158/// Create a new log drain with parameters.
159///
160/// [See Heroku documentation for more information about these paramters](https://devcenter.heroku.com/articles/platform-api-reference#log-session-create-optional-parameters)
161#[derive(Serialize, Clone, Debug)]
162pub struct LogSessionCreateParams<'a> {
163 /// dyno to limit results to
164 pub dyno: Option<&'a str>,
165 /// number of log lines to stream at once
166 pub lines: Option<i64>,
167 /// log source to limit results to
168 pub source: Option<&'a str>,
169 /// whether to stream ongoing logswhether to stream ongoing logs
170 pub tail: Option<bool>,
171}
172
173impl<'a> HerokuEndpoint<LogSession, (), LogSessionCreateParams<'a>> for LogSessionCreate<'a> {
174 fn method(&self) -> Method {
175 Method::Post
176 }
177 fn path(&self) -> String {
178 format!("apps/{}/log-sessions", self.app_id)
179 }
180 fn body(&self) -> Option<LogSessionCreateParams<'a>> {
181 Some(self.params.clone())
182 }
183}