Created
December 31, 2018 08:14
-
-
Save Songmu/0a03d58ae0a19601c15c167b9365064b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use HTTP::Tiny; | |
use Encode qw/decode_utf8/; | |
use JSON::PP qw/encode_json decode_json/; | |
my $access_token = $ENV{PUSHBULLET_TOKEN}; | |
my $endpoint = "https://api.pushbullet.com/v2/pushes"; | |
my $title = $ARGV[0]; | |
my $body = decode_utf8(do { | |
local $/; | |
<STDIN> | |
}); | |
my $json_data = { | |
title => $title, | |
body => $body, | |
type => "note", | |
}; | |
my $headers = { | |
'Access-Token' => $access_token, | |
'Content-Type' => 'application/json', | |
}; | |
my $ua = HTTP::Tiny->new; | |
my $response = $ua->post( $endpoint, { | |
'headers' => \%$headers, | |
'content' => encode_json( $json_data ), | |
} ); | |
unless ( $response->{success} ) { | |
print STDERR Dumper $response; | |
exit 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment