flood-cli 0.0.1 → 0.0.2

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: e72418d756556488155045fb0842076fae0e8e81
4
- data.tar.gz: 1c02416940be62c6bc5f51f8dd198cc49c34e6de
3
+ metadata.gz: e736687a41e9fdd824ba23d5378a36a1ed7125c6
4
+ data.tar.gz: 17ff74365819278b842f0aeff24103d2285233f5
5
5
  SHA512:
6
- metadata.gz: f062f8ee5695d7c60c934bb900056ae2b496248bdcf0011fe6c295e10ceea624f7c9d3f07786293d743c5e3cdb32b6ca84c4902415aca719946d27da4d6d448e
7
- data.tar.gz: ec9dac0e80a69b945a591b77bf8960f558962895b5a68e09e9d8a18a74116408ff35800583d05d8daa44717d4685374095f473715a03297556df2dbaa2fad966
6
+ metadata.gz: 3d547701fd7f064dc8acb760056fa0cffba24f5f9339a8ba7c1763956de9c616dd8e2671d7fd0624a8a6a2ca20cbc1b864049b3090a9b97c98bf303d37f110c9
7
+ data.tar.gz: 852fa0a565a6bcf7d6aa594f32a0003006674627cbbfcec806011a70242a99d79a81b26995c7a69057030ef69c98c64e658e763140edc36e4f0826c9e71b67d0
data/lib/cli/console.rb CHANGED
@@ -4,6 +4,7 @@ class FloodCli
4
4
  module Cli
5
5
  class Console < Thor
6
6
  desc 'login', 'Login to Flood IO'
7
+ option :verbose, default: false
7
8
  def login
8
9
  say('Enter your Flood IO credentials.', :yellow)
9
10
  email = ask('Email: ')
@@ -13,7 +14,7 @@ class FloodCli
13
14
  endpoint = ask('Endpoint: ', default: 'https://api.flood.io')
14
15
  proxy = ask('HTTP Proxy: ')
15
16
 
16
- cli = FloodCli.new(endpoint: endpoint, proxy: proxy, config: config)
17
+ cli = FloodCli.new(endpoint: endpoint, proxy: proxy, config: config, verbose: options[:verbose])
17
18
  cli.login(email: email, password: password)
18
19
  end
19
20
 
data/lib/flood-cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rest_client'
2
+ require 'base64'
2
3
  require 'json'
3
4
  require 'yaml'
4
5
  require 'cgi'
@@ -64,6 +64,8 @@ class FloodCli
64
64
 
65
65
  def error(response)
66
66
  "HTTP #{response.code.to_s} #{JSON.parse(response)['error']}"
67
+ rescue JSON::ParserError
68
+ "HTTP #{response.code.to_s} #{response}"
67
69
  end
68
70
 
69
71
  def parse(response)
@@ -77,18 +79,34 @@ class FloodCli
77
79
  end
78
80
 
79
81
  def token
80
- @config && @config[:token]
82
+ raw_token = @config && @config[:token]
83
+ if version_i == 1
84
+ 'Basic ' + Base64.encode64("#{raw_token}:").chomp
85
+ else
86
+ raw_token
87
+ end
81
88
  end
82
89
 
83
90
  def endpoint
84
- @endpoint ||= @config && @config[:endpoint]
91
+ @endpoint ||= (@config && @config[:endpoint]) || 'https://api.flood.io'
92
+ @endpoint
93
+ end
94
+
95
+ def version
96
+ (@config && @config[:version].to_i) || 2
85
97
  end
86
98
 
87
99
  def headers
88
- {
89
- content_type: :json,
90
- accept: 'application/vnd.flood.v2'
91
- }
100
+ if version == 1
101
+ {
102
+ content_type: :json
103
+ }
104
+ else
105
+ {
106
+ content_type: :json,
107
+ accept: 'application/vnd.flood.v2'
108
+ }
109
+ end
92
110
  end
93
111
 
94
112
  def headers_with_token
@@ -1,5 +1,5 @@
1
1
  module Flood
2
2
  module Cli
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flood-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Koopmans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler