pb-cli 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/lib/pb/cli/push.rb +42 -0
- data/lib/pb/cli/{util.rb → utils.rb} +1 -1
- data/lib/pb/cli/version.rb +1 -1
- data/lib/pb/cli.rb +8 -32
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf14545e96206baca46c7f609151005d0a363f4
|
4
|
+
data.tar.gz: 4527730687bac7a82ef6f916240ed1f5ec1378ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14cf88750591bd8c6ae8fe1d223d134f0a6778eaad5db462b94d93e17ed18b3ca506b547e1bad0b348eda293ce039ddbd578901efb4c64c00c958b6d76558251
|
7
|
+
data.tar.gz: 5e9e59dba592122513cfd88c515ef680b6653f94611b69e96d27ac2ef22c2f758c4997c4a233b54d760ad75a8a7638175e4867e7feefc645ae2cbaae7b0839e7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,13 +27,13 @@ To access the Pushbullet API you'll need an access token so the server knows who
|
|
27
27
|
Send notification.
|
28
28
|
|
29
29
|
```
|
30
|
-
$ pb push <MESSAGE> [--title <TITLE>]
|
30
|
+
$ pb push create <MESSAGE> [--title <TITLE>]
|
31
31
|
```
|
32
32
|
|
33
33
|
Or send notification from STDIN.
|
34
34
|
|
35
35
|
```
|
36
|
-
$ ls -al | pb push
|
36
|
+
$ ls -al | pb push create
|
37
37
|
```
|
38
38
|
|
39
39
|
See also `pb help`.
|
@@ -49,7 +49,7 @@ $ bundle install --path vendor/bundle
|
|
49
49
|
### Running automated tests
|
50
50
|
|
51
51
|
```
|
52
|
-
$ bundle exec rspec
|
52
|
+
$ access_token=<ACCESS_TOKEN> bundle exec rspec
|
53
53
|
```
|
54
54
|
|
55
55
|
## Contributing
|
data/lib/pb/cli/push.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# vim: ft=ruby expandtab shiftwidth=2 tabstop=2
|
3
|
+
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
module Pushbullet_CLI
|
7
|
+
class Push < Thor
|
8
|
+
class_option :token, :desc => "Access token"
|
9
|
+
|
10
|
+
desc "create <MESSAGE>", "Send a push to devices or another persons."
|
11
|
+
method_option :title, :desc => "Title of the notification."
|
12
|
+
method_option :device, :desc => "Iden of the target device to push."
|
13
|
+
# method_option :person, :aliases => "-p", :desc => "Delete the file after parsing it"
|
14
|
+
def create( message = "" )
|
15
|
+
if File.pipe?( STDIN ) || File.select( [STDIN], [], [], 0 ) != nil then
|
16
|
+
message = STDIN.readlines().join( "" )
|
17
|
+
end
|
18
|
+
|
19
|
+
url = "https://api.pushbullet.com/v2/pushes"
|
20
|
+
token = Utils::get_token( options )
|
21
|
+
|
22
|
+
unless message.empty?
|
23
|
+
args = {
|
24
|
+
"type" => "note",
|
25
|
+
"body" => message,
|
26
|
+
"title" => ( options[:title] ? options[:title] : "" )
|
27
|
+
}
|
28
|
+
|
29
|
+
unless options[:device].nil?
|
30
|
+
unless options[:device].empty?
|
31
|
+
args['device_iden'] = options[:device]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Utils::send( url, token, "post", args )
|
36
|
+
else
|
37
|
+
puts "Nothing to do."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -36,7 +36,7 @@ module Pushbullet_CLI
|
|
36
36
|
unless token.empty?
|
37
37
|
return token
|
38
38
|
else
|
39
|
-
puts "Please initialize an Access Token with `pb init <ACCESS-TOKEN>`."
|
39
|
+
$stderr.puts "Please initialize an Access Token with `pb init <ACCESS-TOKEN>` or run command with `--token=<ACCESS-TOKEN>`."
|
40
40
|
exit 1
|
41
41
|
end
|
42
42
|
end
|
data/lib/pb/cli/version.rb
CHANGED
data/lib/pb/cli.rb
CHANGED
@@ -2,46 +2,18 @@
|
|
2
2
|
# vim: ft=ruby expandtab shiftwidth=2 tabstop=2
|
3
3
|
|
4
4
|
require "pb/cli/version"
|
5
|
-
require "pb/cli/
|
5
|
+
require "pb/cli/utils"
|
6
6
|
require "pb/cli/device"
|
7
|
+
require "pb/cli/push"
|
7
8
|
require "thor"
|
8
9
|
require "rest-client"
|
9
10
|
require "yaml"
|
10
11
|
|
11
12
|
module Pushbullet_CLI
|
12
13
|
class Command < Thor
|
13
|
-
class_option :token, :desc => "
|
14
|
+
class_option :token, :desc => "Your access token for Pushbullet API."
|
14
15
|
|
15
|
-
desc "
|
16
|
-
method_option :title, :desc => "Title of the notification."
|
17
|
-
method_option :device, :desc => "Iden of the target device to push."
|
18
|
-
# method_option :person, :aliases => "-p", :desc => "Delete the file after parsing it"
|
19
|
-
def push( message = "" )
|
20
|
-
if File.pipe?( STDIN ) || File.select( [STDIN], [], [], 0 ) != nil then
|
21
|
-
message = STDIN.readlines().join( "" )
|
22
|
-
end
|
23
|
-
|
24
|
-
url = "https://api.pushbullet.com/v2/pushes"
|
25
|
-
token = Utils::get_token( options )
|
26
|
-
|
27
|
-
if message
|
28
|
-
args = {
|
29
|
-
"type" => "note",
|
30
|
-
"body" => message,
|
31
|
-
"title" => ( options[:title] ? options[:title] : "" )
|
32
|
-
}
|
33
|
-
|
34
|
-
if options[:device]
|
35
|
-
args['device_iden'] = options[:device]
|
36
|
-
end
|
37
|
-
|
38
|
-
Utils::send( url, token, "post", args )
|
39
|
-
else
|
40
|
-
puts "Nothing to do."
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
desc "init <ACCESS-TOKEN>", "Initialize pb-cli"
|
16
|
+
desc "init <ACCESS-TOKEN>", "Writes access token into your config file."
|
45
17
|
def init( access_token )
|
46
18
|
unless Dir.exist? File.join( ENV["HOME"], '.pb-cli' )
|
47
19
|
FileUtils.mkdir( File.join( ENV["HOME"], '.pb-cli' ) );
|
@@ -54,5 +26,9 @@ module Pushbullet_CLI
|
|
54
26
|
|
55
27
|
desc "device <SUBCOMMAND>", "Manage devices."
|
56
28
|
subcommand "device", Device
|
29
|
+
|
30
|
+
desc "push <SUBCOMMAND>", "Send or manage notifications."
|
31
|
+
subcommand "push", Push
|
32
|
+
|
57
33
|
end # end class Command
|
58
34
|
end # end module Pushbullet_CLi
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pb-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miya0001
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,7 +100,8 @@ files:
|
|
100
100
|
- exe/pb
|
101
101
|
- lib/pb/cli.rb
|
102
102
|
- lib/pb/cli/device.rb
|
103
|
-
- lib/pb/cli/
|
103
|
+
- lib/pb/cli/push.rb
|
104
|
+
- lib/pb/cli/utils.rb
|
104
105
|
- lib/pb/cli/version.rb
|
105
106
|
- pb-cli.gemspec
|
106
107
|
homepage: https://github.com/miya0001/pb-cli
|