pb-cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cf14545e96206baca46c7f609151005d0a363f4
4
- data.tar.gz: 4527730687bac7a82ef6f916240ed1f5ec1378ce
3
+ metadata.gz: d4ab9448679cc2513803963262826eb4f89b21cd
4
+ data.tar.gz: 4ff7a84e6f415bb073d249463bb6d0ab9572bc15
5
5
  SHA512:
6
- metadata.gz: 14cf88750591bd8c6ae8fe1d223d134f0a6778eaad5db462b94d93e17ed18b3ca506b547e1bad0b348eda293ce039ddbd578901efb4c64c00c958b6d76558251
7
- data.tar.gz: 5e9e59dba592122513cfd88c515ef680b6653f94611b69e96d27ac2ef22c2f758c4997c4a233b54d760ad75a8a7638175e4867e7feefc645ae2cbaae7b0839e7
6
+ metadata.gz: eeac3fca3367df6a7914c015ef016d22b66e227c1c71d3193877035936b118ab3032e9e2dea36191051aded66d25e5d13e2548bd4d81410089fd103b5a8bfdb2
7
+ data.tar.gz: 36a53918acfc698eaf4f4ad2cc9f015a22a111020851b52227ee23a68ddafcb8fba3fe10fd71d03e45fcd0d2801c460862deabea1a5ea380ec47d5a500d10f29
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in pb-cli.gemspec
4
4
  gemspec
5
5
 
6
+ gem "bundler"
7
+ gem "rake"
6
8
  gem "rspec"
7
9
  gem "thor"
8
10
  gem "rest-client"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pb-cli (0.3.0)
4
+ pb-cli (0.3.1)
5
5
  rest-client (~> 1.8)
6
6
  terminal-table (~> 1.5)
7
7
  thor (~> 0.19)
@@ -44,9 +44,9 @@ PLATFORMS
44
44
  ruby
45
45
 
46
46
  DEPENDENCIES
47
- bundler (~> 1.10)
47
+ bundler
48
48
  pb-cli!
49
- rake (~> 10.0)
49
+ rake
50
50
  rest-client
51
51
  rspec
52
52
  terminal-table
data/lib/pb/cli/device.rb CHANGED
@@ -8,18 +8,26 @@ module Pushbullet_CLI
8
8
  class_option :token, :desc => "Access token"
9
9
 
10
10
  desc "list", "Get a list of devices belonging to the current user."
11
+ method_option :format, :desc => "Accepted values: table, json. Default: table"
12
+ method_option :fields, :desc => "Limit the output to specific object fields."
11
13
  def list
12
14
  url = "https://api.pushbullet.com/v2/devices?active=true"
13
15
  token = Utils::get_token( options )
16
+ cols = [ 'iden', 'nickname', 'created' ]
17
+
18
+ unless options[:fields].nil?
19
+ unless options[:fields].empty?
20
+ cols = options[:fields].split( /\s*,\s*/ )
21
+ end
22
+ end
14
23
 
15
24
  result = Utils::send( url, token, "get" )
16
- row = result['devices'].map.with_index{ | device | [
17
- device['iden'],
18
- device['nickname'],
19
- device['model'],
20
- ] }
25
+ Utils::print( {
26
+ :format => options[:format],
27
+ :cols => cols,
28
+ :rows => result['devices'],
29
+ } )
30
+ end # end list
21
31
 
22
- Utils:: print_table( [ "Iden", "Nickname", "Model" ], row )
23
- end
24
32
  end
25
33
  end
data/lib/pb/cli/push.rb CHANGED
@@ -10,6 +10,7 @@ module Pushbullet_CLI
10
10
  desc "create <MESSAGE>", "Send a push to devices or another persons."
11
11
  method_option :title, :desc => "Title of the notification."
12
12
  method_option :device, :desc => "Iden of the target device to push."
13
+ method_option :url, :desc => "The url to open."
13
14
  # method_option :person, :aliases => "-p", :desc => "Delete the file after parsing it"
14
15
  def create( message = "" )
15
16
  if File.pipe?( STDIN ) || File.select( [STDIN], [], [], 0 ) != nil then
@@ -20,23 +21,40 @@ module Pushbullet_CLI
20
21
  token = Utils::get_token( options )
21
22
 
22
23
  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
-
24
+ args = Utils::get_push_args( options )
25
+ args['body'] = message
35
26
  Utils::send( url, token, "post", args )
36
27
  else
37
28
  puts "Nothing to do."
38
29
  end
39
- end
30
+ end # end create
31
+
32
+ desc "list", "Request push history."
33
+ method_option :format, :desc => "Accepted values: table, json. Default: table"
34
+ method_option :fields, :desc => "Limit the output to specific object fields."
35
+ def list
36
+ url = "https://api.pushbullet.com/v2/pushes?active=true"
37
+ token = Utils::get_token( options )
38
+ cols = [ 'iden', 'type', 'title', 'created' ]
39
+
40
+ unless options[:fields].nil?
41
+ unless options[:fields].empty?
42
+ cols = options[:fields].split( /\s*,\s*/ )
43
+ end
44
+ end
45
+
46
+ result = Utils::send( url, token, "get" )
47
+ Utils::print( {
48
+ :format => options[:format],
49
+ :cols => cols,
50
+ :rows => result['pushes'],
51
+ } )
52
+ end # end list
40
53
 
41
54
  end
42
55
  end
56
+
57
+ # curl --header 'Access-Token: VeoW8P4oMACU46KXMYAA4f1ahIpRvB4E' \
58
+ # --data active=true \
59
+ # --get \
60
+ # https://api.pushbullet.com/v2/pushes
data/lib/pb/cli/utils.rb CHANGED
@@ -3,24 +3,76 @@
3
3
 
4
4
  require "yaml"
5
5
  require "terminal-table"
6
+ require "date"
6
7
 
7
8
  module Pushbullet_CLI
8
9
  class Utils
9
10
  class << self
10
11
 
12
+ def parse_row( cols, row )
13
+ table = []
14
+ cols.each{ |col|
15
+ if "created" == col || "modified" == col
16
+ val = Time.at( row[col] )
17
+ else
18
+ val = row[col]
19
+ end
20
+ table.push( val )
21
+ }
22
+ return table
23
+ end
24
+
25
+ def print( args )
26
+ if "json" == args[:format]
27
+ puts JSON.generate( args[:rows] )
28
+ else
29
+ table = args[:rows].map.with_index{ | row | parse_row( args[:cols], row ) }
30
+ Utils:: print_table( args[:cols], table )
31
+ end
32
+ end # end print
33
+
34
+ def get_push_args( options )
35
+ args = {}
36
+
37
+ unless options[:title].nil?
38
+ unless options[:title].empty?
39
+ args["title"] = options[:title]
40
+ end
41
+ end
42
+
43
+ unless options[:device].nil?
44
+ unless options[:device].empty?
45
+ args["device_iden"] = options[:device]
46
+ end
47
+ end
48
+
49
+ unless options[:url].nil?
50
+ unless options[:url].empty?
51
+ args["url"] = options[:url]
52
+ args["type"] = "link"
53
+ end
54
+ end
55
+
56
+ if args["type"].nil?
57
+ args["type"] = "note"
58
+ end
59
+
60
+ return args
61
+ end # end get_push_args
62
+
11
63
  def get_config
12
64
  conf = {}
13
65
  if File.exists?( File.join( ENV["HOME"], '.pb-cli/config.yml' ) )
14
- _custom = YAML.load(
66
+ config = YAML.load(
15
67
  File.open(
16
68
  File.join( ENV["HOME"], '.pb-cli/config.yml' ),
17
69
  File::RDONLY
18
70
  ).read
19
71
  )
20
- conf.merge!(_custom) if _custom.is_a?(Hash)
72
+ conf.merge!( config ) if config.is_a?(Hash)
21
73
  end
22
74
  return conf
23
- end
75
+ end # end get_config
24
76
 
25
77
  def get_token( options )
26
78
  token = ""
@@ -39,7 +91,7 @@ module Pushbullet_CLI
39
91
  $stderr.puts "Please initialize an Access Token with `pb init <ACCESS-TOKEN>` or run command with `--token=<ACCESS-TOKEN>`."
40
92
  exit 1
41
93
  end
42
- end
94
+ end # end get_token
43
95
 
44
96
  def send( url, access_token, method = "post", args = {} )
45
97
  begin
@@ -63,11 +115,11 @@ module Pushbullet_CLI
63
115
  $stderr.puts e.message
64
116
  exit 1
65
117
  end
66
- end
118
+ end # end send
67
119
 
68
120
  def print_table( headers, rows )
69
121
  puts Terminal::Table.new :headings => headers, :rows => rows
70
- end
122
+ end # end print_table
71
123
 
72
124
  end # end self
73
125
  end # end Utils
@@ -2,5 +2,5 @@
2
2
  # vim: ft=ruby expandtab shiftwidth=2 tabstop=2
3
3
 
4
4
  module Pushbullet_CLI
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.1"
6
6
  end
data/pb-cli.gemspec CHANGED
@@ -28,6 +28,7 @@ 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
+ spec.add_development_dependency "rspec", "~> 3.3"
31
32
 
32
33
  spec.add_dependency 'thor', '~> 0.19'
33
34
  spec.add_dependency 'rest-client', '~> 1.8'
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.3.0
4
+ version: 0.3.1
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-03 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: thor
43
57
  requirement: !ruby/object:Gem::Requirement