Skip to content

Commit 815f805

Browse files
Checkpoint before follow-up message
Co-authored-by: daniel.szoke <daniel.szoke@sentry.io>
1 parent dbcf127 commit 815f805

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/api/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub enum Method {
102102
Post,
103103
Put,
104104
Delete,
105+
Patch,
105106
}
106107

107108
impl fmt::Display for Method {
@@ -111,6 +112,7 @@ impl fmt::Display for Method {
111112
Method::Post => write!(f, "POST"),
112113
Method::Put => write!(f, "PUT"),
113114
Method::Delete => write!(f, "DELETE"),
115+
Method::Patch => write!(f, "PATCH"),
114116
}
115117
}
116118
}
@@ -1747,6 +1749,7 @@ impl ApiRequest {
17471749
Method::Post => handle.custom_request("POST")?,
17481750
Method::Put => handle.custom_request("PUT")?,
17491751
Method::Delete => handle.custom_request("DELETE")?,
1752+
Method::Patch => handle.custom_request("PATCH")?,
17501753
}
17511754

17521755
handle.url(url)?;

src/commands/api.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use anyhow::Result;
2+
use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint};
3+
4+
use crate::api::{Api, Method};
5+
6+
pub fn make_command(command: Command) -> Command {
7+
command
8+
.about("Make a raw API request to the Sentry API.")
9+
.arg(
10+
Arg::new("endpoint")
11+
.value_name("ENDPOINT")
12+
.required(true)
13+
.value_hint(ValueHint::Url)
14+
.help(
15+
"The API endpoint to request (e.g., 'organizations/' or '/projects/my-org/my-project/releases/').{n}\
16+
The endpoint will be prefixed with '/api/0/' automatically.",
17+
),
18+
)
19+
.arg(
20+
Arg::new("method")
21+
.short('m')
22+
.long("method")
23+
.value_name("METHOD")
24+
.value_parser(["GET", "POST", "PUT", "DELETE", "PATCH"])
25+
.default_value("GET")
26+
.action(ArgAction::Set)
27+
.help("The HTTP method to use for the request."),
28+
)
29+
}
30+
31+
pub fn execute(matches: &ArgMatches) -> Result<()> {
32+
let endpoint = matches.get_one::<String>("endpoint").unwrap();
33+
let method_str = matches.get_one::<String>("method").unwrap();
34+
35+
let method = match method_str.as_str() {
36+
"GET" => Method::Get,
37+
"POST" => Method::Post,
38+
"PUT" => Method::Put,
39+
"DELETE" => Method::Delete,
40+
"PATCH" => Method::Patch,
41+
_ => unreachable!("Invalid method value"),
42+
};
43+
44+
let api = Api::current();
45+
let resp = api.request(method, endpoint, None)?.send()?;
46+
47+
// Print the response body as-is to stdout
48+
if let Some(body) = resp.body {
49+
let body_str = String::from_utf8_lossy(&body);
50+
println!("{}", body_str);
51+
}
52+
53+
Ok(())
54+
}

0 commit comments

Comments
 (0)