Class: Pushbullet_CLI::Utils
- Inherits:
-
Object
- Object
- Pushbullet_CLI::Utils
- Defined in:
- lib/pb/cli/util.rb
Class Method Summary collapse
- .get_config ⇒ Object
- .get_token(options) ⇒ Object
- .print_table(headers, rows) ⇒ Object
- .send(url, access_token, method = "post", args = {}) ⇒ Object
Class Method Details
.get_config ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pb/cli/util.rb', line 11 def get_config conf = {} if File.exists?( File.join( ENV["HOME"], '.pb-cli/config.yml' ) ) _custom = YAML.load( File.open( File.join( ENV["HOME"], '.pb-cli/config.yml' ), File::RDONLY ).read ) conf.merge!(_custom) if _custom.is_a?(Hash) end return conf end |
.get_token(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pb/cli/util.rb', line 25 def get_token( ) token = "" unless [:token].nil? token = [:token] else config = Utils::get_config unless config["access_token"].nil? token = config["access_token"] end end unless token.empty? return token else puts "Please initialize an Access Token with `pb init <ACCESS-TOKEN>`." exit 1 end end |
.print_table(headers, rows) ⇒ Object
68 69 70 |
# File 'lib/pb/cli/util.rb', line 68 def print_table( headers, rows ) puts Terminal::Table.new :headings => headers, :rows => rows end |
.send(url, access_token, method = "post", args = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pb/cli/util.rb', line 44 def send( url, access_token, method = "post", args = {} ) begin if "post" == method return JSON.parse( RestClient.post( url, args.to_json, :content_type => :json, :accept => :json, "Access-Token" => access_token ) ) elsif "get" == method return JSON.parse( RestClient.get( url, :content_type => :json, :accept => :json, "Access-Token" => access_token ) ) end rescue => e $stderr.puts e. exit 1 end end |