Class: Pushbullet_CLI::Push

Inherits:
Thor
  • Object
show all
Defined in:
lib/pb/cli/push.rb

Instance Method Summary collapse

Instance Method Details

#create(message = "") ⇒ Object

method_option :person, :aliases => “-p”, :desc => “Delete the file after parsing it”



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pb/cli/push.rb', line 16

def create( message = "" )
  if "help" == message
    invoke( :help, [ "create" ] );
    exit 0
  end

  if File.pipe?( STDIN ) || File.select( [STDIN], [], [], 0 ) != nil then
    message = STDIN.readlines().join( "" )
  end

  url = "https://api.pushbullet.com/v2/pushes"
  token = Utils::get_token( options )

  unless message.empty?
    args = Utils::get_push_args( options )
    args['body'] = message
    Utils::send( url, token, "post", args )
  else
    puts "Nothing to do."
  end
end

#list(help = "") ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pb/cli/push.rb', line 41

def list( help = "" )
  unless help.empty?
    if "help" == help
      invoke( :help, [ "list" ] );
      exit 0
    else
      self.class.handle_argument_error
      exit 1
    end
  end

  url = "https://api.pushbullet.com/v2/pushes?active=true"
  token = Utils::get_token( options )
  cols = [ 'iden', 'type', 'title', 'created' ]

  unless options[:fields].nil?
    unless options[:fields].empty?
      cols = options[:fields].split( /\s*,\s*/ )
    end
  end

  result = Utils::send( url, token, "get" )
  Utils::print( {
    :format => options[:format],
    :cols => cols,
    :rows => result['pushes'],
  } )
end