Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F17416027
main.rs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
main.rs
View Options
mod
clap_args
;
use
clap_args
::
ClapArgs
;
use
clap
::
Parser
;
use
serde
::
{
Serialize
};
use
reqwest
;
use
std
::
process
::
exit
;
#[derive(Serialize)]
struct
Notification
{
service
:
String
,
project
:
String
,
group
:
String
,
#[serde(rename =
"type"
)]
_type
:
String
,
text
:
String
,
link
:
String
,
}
#[tokio::main]
async
fn
main
()
{
// Environment variables
let
api_endpoint
=
"https://eo4a3aeazbbb14z.m.pipedream.net"
;
// ========================================================
// 1. Validating user's arguments while parsing (clap)
let
_args
:
ClapArgs
=
ClapArgs
::
parse
();
// 2. Converting user's arguments to ready-to-post JSON (serde)
let
populated_notification
=
Notification
{
service
:
_args
.
clap_service
,
project
:
_args
.
clap_project
,
group
:
_args
.
clap_group
,
_type
:
_args
.
clap_type
,
text
:
_args
.
clap_text
.
unwrap_or
(
""
.
to_string
()),
link
:
_args
.
clap_link
.
unwrap_or
(
""
.
to_string
()),
};
// 3. Sending JSON as HTTP request (reqwest)
let
client
=
reqwest
::
Client
::
new
();
let
res
=
client
.
post
(
api_endpoint
)
.
json
(
&
populated_notification
)
.
send
()
.
await
;
if
let
Err
(
error
)
=
res
{
eprintln
!
(
"{}"
,
&
error
);
exit
(
1
);
}
// ========================================================
// Print error if there's any (provided by Dereckson)
if
!
res
.
unwrap
().
status
().
is_success
()
{
eprintln
!
(
"The notifications server can't process the notification."
);
exit
(
2
);
// Let's use another code so a script can know at what step it failed.
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Mon, Dec 15, 22:34 (1 d, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3262100
Default Alt Text
main.rs (1 KB)
Attached To
Mode
rNPUSH notification-push
Attached
Detach File
Event Timeline
Log In to Comment