flood-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e72418d756556488155045fb0842076fae0e8e81
4
+ data.tar.gz: 1c02416940be62c6bc5f51f8dd198cc49c34e6de
5
+ SHA512:
6
+ metadata.gz: f062f8ee5695d7c60c934bb900056ae2b496248bdcf0011fe6c295e10ceea624f7c9d3f07786293d743c5e3cdb32b6ca84c4902415aca719946d27da4d6d448e
7
+ data.tar.gz: ec9dac0e80a69b945a591b77bf8960f558962895b5a68e09e9d8a18a74116408ff35800583d05d8daa44717d4685374095f473715a03297556df2dbaa2fad966
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flood-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Tim Koopmans
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Flood::Cli
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flood-cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install flood-cli
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/flood-cli/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/fio ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flood-cli'
4
+
5
+ FloodCli::Cli::Console.start(ARGV)
data/flood-cli.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flood-cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'flood-cli'
8
+ spec.version = Flood::Cli::VERSION
9
+ spec.authors = ['Tim Koopmans']
10
+ spec.email = ['tim.koops@gmail.com']
11
+ spec.summary = 'Flood IO CLI'
12
+ spec.description = 'This is the command line interface to Flood IO'
13
+ spec.homepage = 'https://flood.io'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'pry'
24
+
25
+ spec.add_dependency 'rest-client'
26
+ spec.add_dependency 'thor'
27
+ spec.add_dependency 'awesome_print'
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'thor'
2
+
3
+ class FloodCli
4
+ module Cli
5
+ class Console < Thor
6
+ desc 'login', 'Login to Flood IO'
7
+ def login
8
+ say('Enter your Flood IO credentials.', :yellow)
9
+ email = ask('Email: ')
10
+ password = ask('Password: ', echo: false)
11
+ puts
12
+ config = ask('Config: ', default: "#{Dir.home}/.fio")
13
+ endpoint = ask('Endpoint: ', default: 'https://api.flood.io')
14
+ proxy = ask('HTTP Proxy: ')
15
+
16
+ cli = FloodCli.new(endpoint: endpoint, proxy: proxy, config: config)
17
+ cli.login(email: email, password: password)
18
+ end
19
+
20
+ desc 'floods', 'Manage Floods'
21
+ subcommand 'floods', Floods
22
+
23
+ desc 'grids', 'Manage Grids'
24
+ subcommand 'grids', Grids
25
+ end
26
+ end
27
+ end
data/lib/cli/floods.rb ADDED
@@ -0,0 +1,12 @@
1
+ class FloodCli
2
+ module Cli
3
+ class Floods < Thor
4
+ desc 'list', 'List floods'
5
+ option :verbose, default: false
6
+ def list
7
+ cli = FloodCli.new(verbose: options[:verbose])
8
+ cli.floods_index
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/cli/grids.rb ADDED
@@ -0,0 +1,12 @@
1
+ class FloodCli
2
+ module Cli
3
+ class Grids < Thor
4
+ desc 'list', 'List grids'
5
+ option :verbose, default: false
6
+ def list
7
+ cli = FloodCli.new(verbose: options[:verbose])
8
+ cli.grids_index
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,106 @@
1
+ class FloodCli
2
+ def initialize(endpoint: nil, proxy: nil, config: nil, verbose: nil)
3
+ @endpoint = endpoint
4
+ @verbose = verbose
5
+ load_configuration(config: config)
6
+ configure_rest_client(proxy: proxy)
7
+ end
8
+
9
+ def login(email:, password:)
10
+ response = post '/api/auth',
11
+ {
12
+ email: email,
13
+ password: password
14
+ }
15
+
16
+ if response && response.code == 200
17
+ logger.info 'Logged in to Flood IO.'
18
+ config = {
19
+ endpoint: endpoint,
20
+ proxy: @proxy,
21
+ token: JSON.parse(response)['token']
22
+ }
23
+ File.open(@config_file, 'w') { |file| file.write(config.to_yaml) }
24
+ end
25
+ end
26
+
27
+ def floods_index
28
+ get 'floods'
29
+ end
30
+
31
+ private
32
+
33
+ def load_configuration(config:)
34
+ config ||= "#{Dir.home}/.fio"
35
+ if File.file?(config)
36
+ @config_file = config
37
+ @config = YAML::load_file(config)
38
+ end
39
+ end
40
+
41
+ def configure_rest_client(proxy:)
42
+ @proxy = proxy if proxy
43
+ RestClient.proxy = @proxy if @proxy
44
+ RestClient.log = STDOUT if @verbose
45
+ end
46
+
47
+ def get(url)
48
+ response = RestClient.get [endpoint, url].join('/'), headers_with_token
49
+ parse(response)
50
+ response
51
+ rescue => e
52
+ logger.fatal error(e.response)
53
+ response
54
+ end
55
+
56
+ def post(url, params={})
57
+ response = RestClient.post [endpoint, url].join('/'), params, headers
58
+ parse(response)
59
+ response
60
+ rescue => e
61
+ logger.fatal error(e.response)
62
+ response
63
+ end
64
+
65
+ def error(response)
66
+ "HTTP #{response.code.to_s} #{JSON.parse(response)['error']}"
67
+ end
68
+
69
+ def parse(response)
70
+ if response.code == 200
71
+ if @verbose
72
+ logger.ap JSON.parse(response)
73
+ else
74
+ puts JSON.pretty_unparse(JSON.parse(response))
75
+ end
76
+ end
77
+ end
78
+
79
+ def token
80
+ @config && @config[:token]
81
+ end
82
+
83
+ def endpoint
84
+ @endpoint ||= @config && @config[:endpoint]
85
+ end
86
+
87
+ def headers
88
+ {
89
+ content_type: :json,
90
+ accept: 'application/vnd.flood.v2'
91
+ }
92
+ end
93
+
94
+ def headers_with_token
95
+ headers.merge(authorization: token)
96
+ end
97
+
98
+ def logger
99
+ @log ||= Logger.new(STDOUT)
100
+ @log.level = @verbose ? Logger::DEBUG : Logger::INFO
101
+ @log.formatter = proc do |severity, datetime, progname, msg|
102
+ "#{datetime}: #{msg}\n"
103
+ end
104
+ @log
105
+ end
106
+ end
@@ -0,0 +1,46 @@
1
+ class Logger
2
+ module Colors
3
+ VERSION = '1.0.0'
4
+
5
+ NOTHING = '0;0'
6
+ BLACK = '0;30'
7
+ RED = '0;31'
8
+ GREEN = '0;32'
9
+ BROWN = '0;33'
10
+ BLUE = '0;34'
11
+ PURPLE = '0;35'
12
+ CYAN = '0;36'
13
+ LIGHT_GRAY = '0;37'
14
+ DARK_GRAY = '1;30'
15
+ LIGHT_RED = '1;31'
16
+ LIGHT_GREEN = '1;32'
17
+ YELLOW = '1;33'
18
+ LIGHT_BLUE = '1;34'
19
+ LIGHT_PURPLE = '1;35'
20
+ LIGHT_CYAN = '1;36'
21
+ WHITE = '1;37'
22
+
23
+ SCHEMA = {
24
+ STDOUT => %w[nothing green brown red purple cyan],
25
+ STDERR => %w[nothing green yellow light_red light_purple light_cyan],
26
+ }
27
+ end
28
+ end
29
+
30
+ class Logger
31
+ alias format_message_colorless format_message
32
+
33
+ def format_message(level, *args)
34
+ if Logger::Colors::SCHEMA[@logdev.dev]
35
+ color = begin
36
+ Logger::Colors.const_get \
37
+ Logger::Colors::SCHEMA[@logdev.dev][Logger.const_get(level.sub "ANY","UNKNOWN")].to_s.upcase
38
+ rescue NameError
39
+ "0;0"
40
+ end
41
+ "\e[#{ color }m#{ format_message_colorless(level, *args) }\e[0;0m"
42
+ else
43
+ format_message_colorless(level, *args)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Flood
2
+ module Cli
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
data/lib/flood-cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'cgi'
5
+ require 'open3'
6
+ require 'thor'
7
+ require 'fileutils'
8
+ require 'awesome_print'
9
+ require 'logger'
10
+ require 'awesome_print/core_ext/logger'
11
+
12
+ require 'flood-cli/version'
13
+ require 'flood-cli/flood-cli'
14
+ require 'flood-cli/logger'
15
+
16
+ require 'cli/floods'
17
+ require 'cli/grids'
18
+ require 'cli/console'
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flood-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tim Koopmans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This is the command line interface to Flood IO
98
+ email:
99
+ - tim.koops@gmail.com
100
+ executables:
101
+ - fio
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/fio
111
+ - flood-cli.gemspec
112
+ - lib/cli/console.rb
113
+ - lib/cli/floods.rb
114
+ - lib/cli/grids.rb
115
+ - lib/flood-cli.rb
116
+ - lib/flood-cli/flood-cli.rb
117
+ - lib/flood-cli/logger.rb
118
+ - lib/flood-cli/version.rb
119
+ homepage: https://flood.io
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Flood IO CLI
143
+ test_files: []