Class: Pushbullet_CLI::Command

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

Instance Method Summary collapse

Instance Method Details

#init(access_token) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/pb/cli.rb', line 45

def init( access_token )
  unless Dir.exist? File.join( ENV["HOME"], '.pb-cli' )
    FileUtils.mkdir( File.join( ENV["HOME"], '.pb-cli' ) );
  end
  File.open( File.join( ENV["HOME"], '.pb-cli', 'config.yml' ), "w" ) do | file |
      file.write( "access_token: " + access_token )
  end
  FileUtils.chmod( 0600, File.join( ENV["HOME"], '.pb-cli', 'config.yml' ) )
end

#push(message = "") ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pb/cli.rb', line 19

def push( message = "" )
  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 )

  if message
    args = {
      "type" => "note",
      "body" => message,
      "title" => ( options[:title] ? options[:title] : "" )
    }

    if options[:device]
      args['device_iden'] = options[:device]
    end

    Utils::send( url, token, "post", args )
  else
    puts "Nothing to do."
  end
end