Skip to content

Commit

Permalink
Changes for release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthebert committed Oct 28, 2014
1 parent ef6a693 commit a7807b5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for WWW-PushBullet Distribution

1.4.0 2014-10-28 22:30

* Many changes to handle new PushBullet API


1.2.4 2014-10-12 22:30

* Improving distribution Kwalitee
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can get your API key in your [PushBullet account settings](https://www.pushb

You also need this Perl modules:

* [Data::Dump](https://metacpan.org/pod/Data::Dump)
* [Data::Dump](https://metacpan.org/release/Data-Dump)
* [File::Slurp](https://metacpan.org/release/File-Slurp)
* [FindBin](https://metacpan.org/pod/FindBin)
* [Getopt::Long](https://metacpan.org/release/Getopt-Long)
Expand Down Expand Up @@ -59,7 +59,8 @@ The easiest way to install WWW::PushBullet is [CPAN Minus](https://github.com/mi

pushbullet devices [ -k <pushbullet_apikey> ]

pushbullet file [ -k <pushbullet_apikey> ] [ -d <device_iden> ] -f filename
pushbullet file [ -k <pushbullet_apikey> ] [ -d <device_iden> ]
--file filename [ --body 'file description' ]

pushbullet link [ -k <pushbullet_apikey> ] [ -d <device_iden> ]
--title 'your title' --url 'http://address'
Expand Down
15 changes: 9 additions & 6 deletions bin/pushbullet
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Program giving easy access to PushBullet features
pushbullet devices [ -k <pushbullet_apikey> ]
pushbullet file [ -k <pushbullet_apikey> ] [ -d <device_iden> ]
--file filename [ --body 'description' ]
--file filename [ --body 'file description' ]
pushbullet link [ -k <pushbullet_apikey> ] [ -d <device_iden> ]
--title 'your title' --url 'http://address'
Expand Down Expand Up @@ -110,9 +110,9 @@ my @opt_items = ();

=head1 SUBROUTINES/METHODS
=head2 DEBUG
=head2 DEBUG($line)
Prints Debug message when debug mode is enabled (with -D/--debug)
Prints message '[DEBUG] $line' if debug mode is enabled (with -D/--debug)
=cut

Expand All @@ -127,7 +127,7 @@ sub DEBUG

=head2 Read_File_Config($file_config)
Reads configuration file
Reads configuration file '$file_config'
=cut

Expand Down Expand Up @@ -200,7 +200,10 @@ my $title = $opt{title} || $conf->{default_title};
my $proxy = $opt{proxy} || $conf->{proxy};
my $url = $opt{url} || $conf->{default_url};

my $pb = WWW::PushBullet->new({apikey => $apikey, proxy => $proxy, debug => $opt{debug}});
my $pb = WWW::PushBullet->new({
apikey => $apikey,
proxy => $proxy,
debug => $opt{debug}});

if ((!scalar @devices) && ($opt{action} ne 'devices'))
{
Expand Down Expand Up @@ -260,7 +263,7 @@ elsif ($opt{action} eq 'file')
}
else
{
printf "pushbullet file --file filename\n";
printf "pushbullet file --file filename --body 'file description'\n";
}
}
elsif ($opt{action} eq 'link')
Expand Down
40 changes: 19 additions & 21 deletions lib/WWW/PushBullet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ sub new
return (undef) if (!defined $params->{apikey});
my $ua = LWP::UserAgent->new;
$ua->agent("WWW::PushBullet/$VERSION");
$ua->proxy('https', $params->{proxy}) if (defined $params->{proxy});
$ua->credentials($PUSHBULLET{SERVER}, $PUSHBULLET{REALM}, $params->{apikey},
'');
$ua->proxy('https', $params->{proxy}) if (defined $params->{proxy});
$ua->credentials($PUSHBULLET{SERVER}, $PUSHBULLET{REALM},
$params->{apikey}, '');

my $self = {
_ua => $ua,
_apikey => $params->{apikey},
Expand All @@ -94,7 +94,7 @@ sub DEBUG
{
my $str = sprintf '[DEBUG] %s', $line;
printf "$str\n";

return ($str);
}

Expand Down Expand Up @@ -151,7 +151,7 @@ sub contacts
my $self = shift;

my $res = $self->{_ua}->get("$PUSHBULLET{URL_APIV2}/contacts");

if ($res->is_success)
{
my $data = JSON->new->decode($res->content);
Expand Down Expand Up @@ -209,7 +209,7 @@ sub _pushes
my $res = $self->{_ua}->post(
"$PUSHBULLET{URL_APIV2}/pushes",
Content_Type => 'application/json',
Content => JSON->new->encode($content)
Content => JSON->new->encode($content)
);

if ($res->is_success)
Expand Down Expand Up @@ -237,22 +237,19 @@ sub _upload_request
my $res = $self->{_ua}->post(
"$PUSHBULLET{URL_APIV2}/upload-request",
Content_Type => undef,
Content => [
'file_name', $file_name,
'file_type', $file_type
]
Content => ['file_name', $file_name, 'file_type', $file_type]
);

if ($res->is_success)
{
my $data = JSON->new->decode($res->content);
my $data = JSON->new->decode($res->content);
my @array_data = %{$data->{data}};
push @array_data, 'file', [ $file_name ];
push @array_data, 'file', [$file_name];
my $res = $self->{_ua}->post(
$data->{upload_url},
Content_Type => 'form-data',
Content => \@array_data
);
Content_Type => 'form-data',
Content => \@array_data
);
if ($res->is_success)
{
return ($data->{file_url});
Expand Down Expand Up @@ -313,20 +310,20 @@ sub push_file
{
my ($self, $params) = @_;

my $mt = MIME::Types->new();
my $mt = MIME::Types->new();
my $type = $mt->mimeTypeOf($params->{file_name});
$self->DEBUG(sprintf('push_file: %s', dump($params)));
my $file_url = $self->_upload_request($params->{file_name}, $type->type());
if (defined $file_url)
{
$params->{type} = 'file';
$params->{type} = 'file';
$params->{file_type} = $type->type();
$params->{file_url} = $file_url;
$params->{file_url} = $file_url;
my $result = $self->_pushes($params);

return ($result);
}

return (undef);
}

Expand Down Expand Up @@ -374,6 +371,7 @@ sub push_list
my ($self, $params) = @_;

$params->{type} = 'list';

#$params->{items} = join(',', @{$params->{items}});
$self->DEBUG(sprintf('push_list: %s', dump($params)));
my $result = $self->_pushes($params);
Expand Down
9 changes: 6 additions & 3 deletions t/00_requirements.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use strict;
use warnings;
use Test::More tests => 7;

use Test::More;

use_ok 'Data::Dump';
use_ok 'File::Slurp';
use_ok 'FindBin';
use_ok 'Getopt::Long';
use_ok 'Getopt::Long';
use_ok 'JSON';
use_ok 'LWP';
use_ok 'MIME::Types';
use_ok 'Pod::Usage';

done_testing(8);
21 changes: 13 additions & 8 deletions t/01_WWW-PushBullet.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;

use FindBin;
use FindBin;
use Test::More;

use lib "$FindBin::Bin/../lib/";
Expand All @@ -26,11 +26,13 @@ my $INVALID_API_KEY = '1234567890';
# checks new() function
#
my $pb = WWW::PushBullet->new();
ok(! defined $pb, "WWW::PushBullet->new() => undef");
ok(!defined $pb, "WWW::PushBullet->new() => undef");

my $pb2 = WWW::PushBullet->new({apikey => $INVALID_API_KEY});
ok((defined $pb2) && (ref $pb2 eq 'WWW::PushBullet'),
"WWW::PushBullet->new({apikey => '$INVALID_API_KEY'}) => WWW::PushBullet object");
ok(
(defined $pb2) && (ref $pb2 eq 'WWW::PushBullet'),
"WWW::PushBullet->new({apikey => '$INVALID_API_KEY'}) => WWW::PushBullet object"
);

#
# checks api_key() function
Expand All @@ -39,15 +41,18 @@ my $api_key = $pb2->api_key();
ok($api_key eq $INVALID_API_KEY, 'WWW::PushBullet->api_key() => api_key');

my $debug_mode = $pb2->debug_mode(1);
my $debug_str = $pb2->DEBUG('test');
my $debug_str = $pb2->DEBUG('test');
ok($debug_mode && ($debug_str eq '[DEBUG] test'), 'debug_mode on');

$debug_mode = $pb2->debug_mode(0);
$debug_str = $pb2->DEBUG('test');
$debug_str = $pb2->DEBUG('test');
ok(!$debug_mode && !defined $debug_str, 'debug_mode off');

my $version = $pb2->version();
ok(defined $version && $version =~ /^\d+.*/, 'WWW::PushBullet->version() => version');
ok(
defined $version && $version =~ /^\d+.*/,
'WWW::PushBullet->version() => version'
);

foreach my $func (@pb_functions)
{
Expand All @@ -60,4 +65,4 @@ done_testing(4 + 2 + 1 + scalar @pb_functions);
Sebastien Thebert <[email protected]>
=cut
=cut

0 comments on commit a7807b5

Please sign in to comment.