pb-cli 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8be764f8eb69bb8e9a2c17043a3243e23fd893a
4
- data.tar.gz: 5839590a5423c6a7ca814873385ca13a37e1db3a
3
+ metadata.gz: fd953098ed7f1914d212fd03f90b2777466d53c1
4
+ data.tar.gz: 4c3732232b90d0cd7c5e0d3fcf676b91e35a4e78
5
5
  SHA512:
6
- metadata.gz: e9d55e545367bea51a0a965765790a914854582b00bf972ae7d42115282c564a845c912e00bf2353497282c6de727811db7774bd4ed1b3ba00d7486872febdef
7
- data.tar.gz: 3ea9a5542d44701fc3ae4f09d820bb510d6dbc0f4e33f3eec02a1487d40a33fd2b96aeb3ea98000dc9757f6fac34780eed5eb388202b9d4b06f906387f586a51
6
+ metadata.gz: 85aa6d0fc1cc40ea4d281246a5b4002a03cee5e2f5a25dc834dd2d03c4086a2dbd2d83d3d241edecb3396873240b3601eed93abcaefab01a7c4aad7da2ee8a0f
7
+ data.tar.gz: 7c044fb66bfb8d7668eb091a24c2e01dfe88b4956f624485ea2c8f9656180f07b07469e4ecc1207ec5da8a0ebf430af9cdfb87e8e8aeb6d349790a38b230e923
data/.travis.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.1.6
4
- before_install: gem install bundler -v 1.10.6
4
+ - 2.0.0
5
+ - 2.1.7
6
+ - 2.2.3
7
+
8
+ before_install:
9
+ - gem install bundler
10
+ - bundle install --path vendor/bundle
11
+
12
+ script:
13
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
 
6
6
  gem "rspec"
7
7
  gem "thor"
8
- gem "json"
9
8
  gem "rest-client"
9
+ gem "terminal-table"
data/Gemfile.lock CHANGED
@@ -1,7 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pb-cli (0.1.0)
4
+ pb-cli (0.2.1)
5
+ rest-client (~> 1.8)
6
+ terminal-table (~> 1.5)
7
+ thor (~> 0.19)
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
@@ -11,7 +14,6 @@ GEM
11
14
  unf (>= 0.0.5, < 1.0.0)
12
15
  http-cookie (1.0.2)
13
16
  domain_name (~> 0.5)
14
- json (1.8.3)
15
17
  mime-types (2.6.2)
16
18
  netrc (0.10.3)
17
19
  rake (10.4.2)
@@ -32,6 +34,7 @@ GEM
32
34
  diff-lcs (>= 1.2.0, < 2.0)
33
35
  rspec-support (~> 3.3.0)
34
36
  rspec-support (3.3.0)
37
+ terminal-table (1.5.2)
35
38
  thor (0.19.1)
36
39
  unf (0.1.4)
37
40
  unf_ext
@@ -42,11 +45,11 @@ PLATFORMS
42
45
 
43
46
  DEPENDENCIES
44
47
  bundler (~> 1.10)
45
- json
46
48
  pb-cli!
47
49
  rake (~> 10.0)
48
50
  rest-client
49
51
  rspec
52
+ terminal-table
50
53
  thor
51
54
 
52
55
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # pb-cli
2
2
 
3
+ [![Build Status](https://travis-ci.org/miya0001/pb-cli.svg?branch=master)](https://travis-ci.org/miya0001/pb-cli)
4
+
3
5
  A command line interface for Pushbullet.
4
6
 
5
7
  https://www.pushbullet.com/
@@ -28,6 +30,12 @@ Send notification.
28
30
  $ pb push <MESSAGE> [--title <TITLE>]
29
31
  ```
30
32
 
33
+ Or send notification from STDIN.
34
+
35
+ ```
36
+ $ ls -al | pb push
37
+ ```
38
+
31
39
  See also `pb help`.
32
40
 
33
41
  ## Development
@@ -38,7 +46,7 @@ $ cd pb-cli
38
46
  $ bundle install --path vendor/bundle
39
47
  ```
40
48
 
41
- ### Running automated testing
49
+ ### Running automated tests
42
50
 
43
51
  ```
44
52
  $ bundle exec rspec
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ # vim: ft=ruby expandtab shiftwidth=2 tabstop=2
3
+
4
+ require "thor"
5
+
6
+ module Pushbullet_CLI
7
+ class Device < Thor
8
+ class_option :token, :desc => "Access token"
9
+
10
+ desc "list", "Get a list of devices belonging to the current user."
11
+ def list
12
+ url = "https://api.pushbullet.com/v2/devices?active=true"
13
+ token = Utils::get_token( options )
14
+
15
+ result = Utils::send( url, token, "get" )
16
+ row = result['devices'].map.with_index{ | device | [
17
+ device['iden'],
18
+ device['nickname'],
19
+ device['model'],
20
+ ] }
21
+
22
+ Utils:: print_table( [ "Iden", "Nickname", "Model" ], row )
23
+ end
24
+ end
25
+ end
data/lib/pb/cli/util.rb CHANGED
@@ -2,10 +2,12 @@
2
2
  # vim: ft=ruby expandtab shiftwidth=2 tabstop=2
3
3
 
4
4
  require "yaml"
5
+ require "terminal-table"
5
6
 
6
7
  module Pushbullet_CLI
7
8
  class Utils
8
9
  class << self
10
+
9
11
  def get_config
10
12
  conf = {}
11
13
  if File.exists?( File.join( ENV["HOME"], '.pb-cli/config.yml' ) )
@@ -20,20 +22,53 @@ module Pushbullet_CLI
20
22
  return conf
21
23
  end
22
24
 
23
- def send( url, access_token, args )
25
+ def get_token( options )
26
+ token = ""
27
+ unless options[:token].nil?
28
+ token = options[:token]
29
+ else
30
+ config = Utils::get_config
31
+ unless config["access_token"].nil?
32
+ token = config["access_token"]
33
+ end
34
+ end
35
+
36
+ unless token.empty?
37
+ return token
38
+ else
39
+ puts "Please initialize an Access Token with `pb init <ACCESS-TOKEN>`."
40
+ exit 1
41
+ end
42
+ end
43
+
44
+ def send( url, access_token, method = "post", args = {} )
24
45
  begin
25
- RestClient.post(
26
- url,
27
- args.to_json,
28
- :content_type => :json,
29
- :accept => :json,
30
- "Access-Token" => access_token
31
- )
46
+ if "post" == method
47
+ return JSON.parse( RestClient.post(
48
+ url,
49
+ args.to_json,
50
+ :content_type => :json,
51
+ :accept => :json,
52
+ "Access-Token" => access_token
53
+ ) )
54
+ elsif "get" == method
55
+ return JSON.parse( RestClient.get(
56
+ url,
57
+ :content_type => :json,
58
+ :accept => :json,
59
+ "Access-Token" => access_token
60
+ ) )
61
+ end
32
62
  rescue => e
33
63
  $stderr.puts e.message
34
64
  exit 1
35
65
  end
36
66
  end
37
- end
38
- end
39
- end
67
+
68
+ def print_table( headers, rows )
69
+ puts Terminal::Table.new :headings => headers, :rows => rows
70
+ end
71
+
72
+ end # end self
73
+ end # end Utils
74
+ end # end Pushbullet_CLI
@@ -2,5 +2,5 @@
2
2
  # vim: ft=ruby expandtab shiftwidth=2 tabstop=2
3
3
 
4
4
  module Pushbullet_CLI
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.1"
6
6
  end
data/lib/pb/cli.rb CHANGED
@@ -3,38 +3,39 @@
3
3
 
4
4
  require "pb/cli/version"
5
5
  require "pb/cli/util"
6
+ require "pb/cli/device"
6
7
  require "thor"
7
8
  require "rest-client"
8
9
  require "yaml"
9
10
 
10
11
  module Pushbullet_CLI
11
12
  class Command < Thor
12
-
13
- def self.exit_on_failure?
14
- true
15
- end
13
+ class_option :token, :desc => "Access token"
16
14
 
17
15
  desc "push <MESSAGE>", "Send a push to devices or another persons."
18
- method_option :title, :aliases => "-t", :desc => "Title of the notification."
19
- # method_option :device, :aliases => "-d", :desc => "Target device to push."
16
+ method_option :title, :desc => "Title of the notification."
17
+ method_option :device, :desc => "Iden of the target device to push."
20
18
  # method_option :person, :aliases => "-p", :desc => "Delete the file after parsing it"
21
19
  def push( message = "" )
22
- if File.pipe?(STDIN) || File.select([STDIN], [], [], 0) != nil then
20
+ if File.pipe?( STDIN ) || File.select( [STDIN], [], [], 0 ) != nil then
23
21
  message = STDIN.readlines().join( "" )
24
22
  end
25
23
 
26
24
  url = "https://api.pushbullet.com/v2/pushes"
25
+ token = Utils::get_token( options )
27
26
 
28
27
  if message
29
- config = Utils::get_config
30
-
31
28
  args = {
32
29
  "type" => "note",
33
30
  "body" => message,
34
31
  "title" => ( options[:title] ? options[:title] : "" )
35
32
  }
36
33
 
37
- Utils::send( url, config['access_token'], args )
34
+ if options[:device]
35
+ args['device_iden'] = options[:device]
36
+ end
37
+
38
+ Utils::send( url, token, "post", args )
38
39
  else
39
40
  puts "Nothing to do."
40
41
  end
@@ -51,5 +52,7 @@ module Pushbullet_CLI
51
52
  FileUtils.chmod( 0600, File.join( ENV["HOME"], '.pb-cli', 'config.yml' ) )
52
53
  end
53
54
 
55
+ desc "device <SUBCOMMAND>", "Manage devices."
56
+ subcommand "device", Device
54
57
  end # end class Command
55
58
  end # end module Pushbullet_CLi
data/pb-cli.gemspec CHANGED
@@ -28,4 +28,8 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.10"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
+
32
+ spec.add_dependency 'thor', '~> 0.19'
33
+ spec.add_dependency 'rest-client', '~> 1.8'
34
+ spec.add_dependency 'terminal-table', '~> 1.5'
31
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - miya0001
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.19'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
41
83
  description: Use Pushbullet from cli.
42
84
  email:
43
85
  - miya@wpist.me
@@ -57,6 +99,7 @@ files:
57
99
  - bin/setup
58
100
  - exe/pb
59
101
  - lib/pb/cli.rb
102
+ - lib/pb/cli/device.rb
60
103
  - lib/pb/cli/util.rb
61
104
  - lib/pb/cli/version.rb
62
105
  - pb-cli.gemspec