Skip to content

Instantly share code, notes, and snippets.

@Songmu
Created December 31, 2018 08:14
Show Gist options
  • Save Songmu/0a03d58ae0a19601c15c167b9365064b to your computer and use it in GitHub Desktop.
Save Songmu/0a03d58ae0a19601c15c167b9365064b to your computer and use it in GitHub Desktop.
#!/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