bixby-common 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.document +5 -0
  2. data/Gemfile +40 -0
  3. data/Gemfile.lock +147 -0
  4. data/Rakefile +58 -0
  5. data/VERSION +1 -0
  6. data/bixby-common.gemspec +135 -0
  7. data/lib/bixby-common.rb +1 -0
  8. data/lib/bixby_common/api/json_request.rb +36 -0
  9. data/lib/bixby_common/api/json_response.rb +83 -0
  10. data/lib/bixby_common/bixby.rb +23 -0
  11. data/lib/bixby_common/command_response.rb +80 -0
  12. data/lib/bixby_common/command_spec.rb +138 -0
  13. data/lib/bixby_common/exception/bundle_not_found.rb +5 -0
  14. data/lib/bixby_common/exception/command_exception.rb +13 -0
  15. data/lib/bixby_common/exception/command_not_found.rb +5 -0
  16. data/lib/bixby_common/exception/encryption_error.rb +5 -0
  17. data/lib/bixby_common/util/crypto_util.rb +130 -0
  18. data/lib/bixby_common/util/debug.rb +19 -0
  19. data/lib/bixby_common/util/hashify.rb +16 -0
  20. data/lib/bixby_common/util/http_client.rb +64 -0
  21. data/lib/bixby_common/util/jsonify.rb +27 -0
  22. data/lib/bixby_common/util/log.rb +50 -0
  23. data/lib/bixby_common.rb +24 -0
  24. data/test/bixby_common_test.rb +18 -0
  25. data/test/command_response_test.rb +48 -0
  26. data/test/command_spec_test.rb +98 -0
  27. data/test/helper.rb +34 -0
  28. data/test/support/repo/vendor/test_bundle/bin/cat +2 -0
  29. data/test/support/repo/vendor/test_bundle/bin/cat.json +3 -0
  30. data/test/support/repo/vendor/test_bundle/bin/echo +2 -0
  31. data/test/support/repo/vendor/test_bundle/digest +20 -0
  32. data/test/support/repo/vendor/test_bundle/manifest.json +0 -0
  33. data/test/util/http_client_test.rb +58 -0
  34. data/test/util/jsonify_test.rb +36 -0
  35. data/test/util/log_test.rb +26 -0
  36. metadata +450 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,40 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "multi_json"
4
+ gem "httpi", :git => "https://github.com/chetan/httpi.git",
5
+ :branch => "chunked_responses"
6
+
7
+ gem "logging"
8
+
9
+ group :development do
10
+ gem "yard", "~> 0.8"
11
+ gem "bundler", "~> 1.1"
12
+ gem "jeweler", :git => "https://github.com/chetan/jeweler.git", :branch => "bixby"
13
+ gem "pry"
14
+
15
+ gem "simplecov", :platforms => [:mri_19, :rbx], :git => "https://github.com/chetan/simplecov.git", :branch => "inline_nocov"
16
+ gem "rcov", :platforms => :mri_18
17
+
18
+ gem "minitest", :platforms => [:mri_19, :rbx]
19
+ gem "test-unit", :platforms => :mri_18
20
+ gem "webmock", :require => false
21
+ gem "mocha", :require => false
22
+
23
+ gem "turn"
24
+
25
+ gem "test_guard", :git => "https://github.com/chetan/test_guard.git"
26
+ gem 'rb-inotify', :require => false
27
+ gem 'rb-fsevent', :require => false
28
+ gem 'rb-fchange', :require => false
29
+
30
+ # platform specific gemms
31
+ # not sure we need to include these at all
32
+ gem "json", :platforms => [:jruby]
33
+ gem "oj", :platforms => [:mri, :rbx]
34
+
35
+ gem "httpclient", :platforms => [:jruby]
36
+ gem "curb", :platforms => [:mri, :rbx]
37
+
38
+ gem "jruby-openssl", :platforms => [:jruby]
39
+ end
40
+
data/Gemfile.lock ADDED
@@ -0,0 +1,147 @@
1
+ GIT
2
+ remote: https://github.com/chetan/httpi.git
3
+ revision: f6e49303fee6778c714bcc556fa5f9247bc3a3f3
4
+ branch: chunked_responses
5
+ specs:
6
+ httpi (2.0.0)
7
+ rack
8
+
9
+ GIT
10
+ remote: https://github.com/chetan/jeweler.git
11
+ revision: 41062abfc55dc1f5775d6419c796fd1c8756fc7b
12
+ branch: bixby
13
+ specs:
14
+ jeweler (1.8.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ rdoc
19
+
20
+ GIT
21
+ remote: https://github.com/chetan/simplecov.git
22
+ revision: 308449b2193700f7a9a4291821a323110838fbc0
23
+ branch: inline_nocov
24
+ specs:
25
+ simplecov (0.7.1)
26
+ multi_json (~> 1.0)
27
+ simplecov-html (~> 0.7.1)
28
+
29
+ GIT
30
+ remote: https://github.com/chetan/test_guard.git
31
+ revision: dc2f30da10945323a3e8f377311b6df54f46ad4c
32
+ specs:
33
+ test_guard (0.1.2)
34
+ awesome_print
35
+ growl
36
+ guard
37
+ simplecov
38
+ simplecov-console
39
+ single_test
40
+ turn
41
+
42
+ GEM
43
+ remote: https://rubygems.org/
44
+ specs:
45
+ addressable (2.3.2)
46
+ ansi (1.4.3)
47
+ awesome_print (1.1.0)
48
+ bouncy-castle-java (1.5.0146.1)
49
+ coderay (1.0.8)
50
+ colorize (0.5.8)
51
+ crack (0.3.2)
52
+ curb (0.8.3)
53
+ ffi (1.3.1)
54
+ ffi (1.3.1-java)
55
+ git (1.2.5)
56
+ growl (1.0.3)
57
+ guard (1.6.2)
58
+ listen (>= 0.6.0)
59
+ lumberjack (>= 1.0.2)
60
+ pry (>= 0.9.10)
61
+ terminal-table (>= 1.4.3)
62
+ thor (>= 0.14.6)
63
+ hirb (0.7.1)
64
+ httpclient (2.3.2)
65
+ jruby-openssl (0.8.2)
66
+ bouncy-castle-java (>= 1.5.0146.1)
67
+ json (1.7.7)
68
+ json (1.7.7-java)
69
+ listen (0.7.2)
70
+ little-plugger (1.1.3)
71
+ logging (1.8.1)
72
+ little-plugger (>= 1.1.3)
73
+ multi_json (>= 1.3.6)
74
+ lumberjack (1.0.2)
75
+ metaclass (0.0.1)
76
+ method_source (0.8.1)
77
+ minitest (4.6.0)
78
+ mocha (0.13.2)
79
+ metaclass (~> 0.0.1)
80
+ multi_json (1.5.1)
81
+ oj (2.0.4)
82
+ pry (0.9.11.4)
83
+ coderay (~> 1.0.5)
84
+ method_source (~> 0.8)
85
+ slop (~> 3.4)
86
+ pry (0.9.11.4-java)
87
+ coderay (~> 1.0.5)
88
+ method_source (~> 0.8)
89
+ slop (~> 3.4)
90
+ spoon (~> 0.0)
91
+ rack (1.5.2)
92
+ rake (10.0.3)
93
+ rb-fchange (0.0.6)
94
+ ffi
95
+ rb-fsevent (0.9.3)
96
+ rb-inotify (0.9.0)
97
+ ffi (>= 0.5.0)
98
+ rcov (1.0.0)
99
+ rdoc (3.12.1)
100
+ json (~> 1.4)
101
+ simplecov-console (0.1.1)
102
+ colorize
103
+ hirb
104
+ simplecov
105
+ simplecov-html (0.7.1)
106
+ single_test (0.5.2)
107
+ rake (> 0.9)
108
+ slop (3.4.3)
109
+ spoon (0.0.1)
110
+ terminal-table (1.4.5)
111
+ test-unit (2.5.4)
112
+ thor (0.17.0)
113
+ turn (0.9.6)
114
+ ansi
115
+ webmock (1.9.0)
116
+ addressable (>= 2.2.7)
117
+ crack (>= 0.1.7)
118
+ yard (0.8.4.1)
119
+
120
+ PLATFORMS
121
+ java
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ bundler (~> 1.1)
126
+ curb
127
+ httpclient
128
+ httpi!
129
+ jeweler!
130
+ jruby-openssl
131
+ json
132
+ logging
133
+ minitest
134
+ mocha
135
+ multi_json
136
+ oj
137
+ pry
138
+ rb-fchange
139
+ rb-fsevent
140
+ rb-inotify
141
+ rcov
142
+ simplecov!
143
+ test-unit
144
+ test_guard!
145
+ turn
146
+ webmock
147
+ yard (~> 0.8)
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require 'jeweler'
14
+
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "bixby-common"
17
+ gemspec.summary = "Bixby Common"
18
+ gemspec.description = "Bixby Common files/libs"
19
+ gemspec.email = "chetan@pixelcop.net"
20
+ gemspec.homepage = "http://github.com/chetan/bixby-common"
21
+ gemspec.authors = ["Chetan Sarva"]
22
+ end
23
+ Jeweler::RubygemsDotOrgTasks.new
24
+
25
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ if Module.const_defined? :Rcov then
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/*_test.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ rescue Exception => ex
44
+ end
45
+ end
46
+
47
+ task :default => :test
48
+
49
+ begin
50
+ require 'single_test'
51
+ SingleTest.load_tasks
52
+
53
+ rescue LoadError
54
+ warn "single_test not available"
55
+ end
56
+
57
+ require 'yard'
58
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.8
@@ -0,0 +1,135 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "bixby-common"
8
+ s.version = "0.3.8"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chetan Sarva"]
12
+ s.date = "2013-03-23"
13
+ s.description = "Bixby Common files/libs"
14
+ s.email = "chetan@pixelcop.net"
15
+ s.files = [
16
+ ".document",
17
+ "Gemfile",
18
+ "Gemfile.lock",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "bixby-common.gemspec",
22
+ "lib/bixby-common.rb",
23
+ "lib/bixby_common.rb",
24
+ "lib/bixby_common/api/json_request.rb",
25
+ "lib/bixby_common/api/json_response.rb",
26
+ "lib/bixby_common/bixby.rb",
27
+ "lib/bixby_common/command_response.rb",
28
+ "lib/bixby_common/command_spec.rb",
29
+ "lib/bixby_common/exception/bundle_not_found.rb",
30
+ "lib/bixby_common/exception/command_exception.rb",
31
+ "lib/bixby_common/exception/command_not_found.rb",
32
+ "lib/bixby_common/exception/encryption_error.rb",
33
+ "lib/bixby_common/util/crypto_util.rb",
34
+ "lib/bixby_common/util/debug.rb",
35
+ "lib/bixby_common/util/hashify.rb",
36
+ "lib/bixby_common/util/http_client.rb",
37
+ "lib/bixby_common/util/jsonify.rb",
38
+ "lib/bixby_common/util/log.rb",
39
+ "test/bixby_common_test.rb",
40
+ "test/command_response_test.rb",
41
+ "test/command_spec_test.rb",
42
+ "test/helper.rb",
43
+ "test/support/repo/vendor/test_bundle/bin/cat",
44
+ "test/support/repo/vendor/test_bundle/bin/cat.json",
45
+ "test/support/repo/vendor/test_bundle/bin/echo",
46
+ "test/support/repo/vendor/test_bundle/digest",
47
+ "test/support/repo/vendor/test_bundle/manifest.json",
48
+ "test/util/http_client_test.rb",
49
+ "test/util/jsonify_test.rb",
50
+ "test/util/log_test.rb"
51
+ ]
52
+ s.homepage = "http://github.com/chetan/bixby-common"
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = "1.8.25"
55
+ s.summary = "Bixby Common"
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<multi_json>, [">= 0"])
62
+ s.add_runtime_dependency(%q<httpi>, [">= 0"])
63
+ s.add_runtime_dependency(%q<logging>, [">= 0"])
64
+ s.add_development_dependency(%q<yard>, ["~> 0.8"])
65
+ s.add_development_dependency(%q<bundler>, ["~> 1.1"])
66
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_development_dependency(%q<pry>, [">= 0"])
68
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
69
+ s.add_development_dependency(%q<rcov>, [">= 0"])
70
+ s.add_development_dependency(%q<minitest>, [">= 0"])
71
+ s.add_development_dependency(%q<test-unit>, [">= 0"])
72
+ s.add_development_dependency(%q<webmock>, [">= 0"])
73
+ s.add_development_dependency(%q<mocha>, [">= 0"])
74
+ s.add_development_dependency(%q<turn>, [">= 0"])
75
+ s.add_development_dependency(%q<test_guard>, [">= 0"])
76
+ s.add_development_dependency(%q<rb-inotify>, [">= 0"])
77
+ s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
78
+ s.add_development_dependency(%q<rb-fchange>, [">= 0"])
79
+ s.add_development_dependency(%q<json>, [">= 0"])
80
+ s.add_development_dependency(%q<oj>, [">= 0"])
81
+ s.add_development_dependency(%q<httpclient>, [">= 0"])
82
+ s.add_development_dependency(%q<curb>, [">= 0"])
83
+ s.add_development_dependency(%q<jruby-openssl>, [">= 0"])
84
+ else
85
+ s.add_dependency(%q<multi_json>, [">= 0"])
86
+ s.add_dependency(%q<httpi>, [">= 0"])
87
+ s.add_dependency(%q<logging>, [">= 0"])
88
+ s.add_dependency(%q<yard>, ["~> 0.8"])
89
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
90
+ s.add_dependency(%q<jeweler>, [">= 0"])
91
+ s.add_dependency(%q<pry>, [">= 0"])
92
+ s.add_dependency(%q<simplecov>, [">= 0"])
93
+ s.add_dependency(%q<rcov>, [">= 0"])
94
+ s.add_dependency(%q<minitest>, [">= 0"])
95
+ s.add_dependency(%q<test-unit>, [">= 0"])
96
+ s.add_dependency(%q<webmock>, [">= 0"])
97
+ s.add_dependency(%q<mocha>, [">= 0"])
98
+ s.add_dependency(%q<turn>, [">= 0"])
99
+ s.add_dependency(%q<test_guard>, [">= 0"])
100
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
101
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
102
+ s.add_dependency(%q<rb-fchange>, [">= 0"])
103
+ s.add_dependency(%q<json>, [">= 0"])
104
+ s.add_dependency(%q<oj>, [">= 0"])
105
+ s.add_dependency(%q<httpclient>, [">= 0"])
106
+ s.add_dependency(%q<curb>, [">= 0"])
107
+ s.add_dependency(%q<jruby-openssl>, [">= 0"])
108
+ end
109
+ else
110
+ s.add_dependency(%q<multi_json>, [">= 0"])
111
+ s.add_dependency(%q<httpi>, [">= 0"])
112
+ s.add_dependency(%q<logging>, [">= 0"])
113
+ s.add_dependency(%q<yard>, ["~> 0.8"])
114
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
115
+ s.add_dependency(%q<jeweler>, [">= 0"])
116
+ s.add_dependency(%q<pry>, [">= 0"])
117
+ s.add_dependency(%q<simplecov>, [">= 0"])
118
+ s.add_dependency(%q<rcov>, [">= 0"])
119
+ s.add_dependency(%q<minitest>, [">= 0"])
120
+ s.add_dependency(%q<test-unit>, [">= 0"])
121
+ s.add_dependency(%q<webmock>, [">= 0"])
122
+ s.add_dependency(%q<mocha>, [">= 0"])
123
+ s.add_dependency(%q<turn>, [">= 0"])
124
+ s.add_dependency(%q<test_guard>, [">= 0"])
125
+ s.add_dependency(%q<rb-inotify>, [">= 0"])
126
+ s.add_dependency(%q<rb-fsevent>, [">= 0"])
127
+ s.add_dependency(%q<rb-fchange>, [">= 0"])
128
+ s.add_dependency(%q<json>, [">= 0"])
129
+ s.add_dependency(%q<oj>, [">= 0"])
130
+ s.add_dependency(%q<httpclient>, [">= 0"])
131
+ s.add_dependency(%q<curb>, [">= 0"])
132
+ s.add_dependency(%q<jruby-openssl>, [">= 0"])
133
+ end
134
+ end
135
+
@@ -0,0 +1 @@
1
+ require "bixby_common"
@@ -0,0 +1,36 @@
1
+
2
+ module Bixby
3
+
4
+ # Wraps a JSON Request
5
+ #
6
+ # @attr [String] operation Name of operation
7
+ # @attr [Array] params Array of paramters; must be valid JSON types
8
+ class JsonRequest
9
+
10
+ include Jsonify
11
+ include HttpClient
12
+
13
+ attr_accessor :operation, :params
14
+
15
+ # Create a new JsonRequest
16
+ #
17
+ # @param [String] operation Name of operation
18
+ # @param [Array] params Array of parameters; must ve valid JSON types
19
+ def initialize(operation, params)
20
+ @operation = operation
21
+ @params = params
22
+ end
23
+
24
+ # Convert object to String, useful for debugging
25
+ #
26
+ # @return [String]
27
+ def to_s # :nocov:
28
+ s = []
29
+ s << "JsonRequest:#{self.object_id}"
30
+ s << " operation: #{self.operation}"
31
+ s << " params: " + MultiJson.dump(self.params)
32
+ s.join("\n")
33
+ end # :nocov:
34
+
35
+ end # JsonRequest
36
+ end # Bixby
@@ -0,0 +1,83 @@
1
+
2
+ module Bixby
3
+
4
+ # Wraps a JSON Response
5
+ #
6
+ # @attr [String] status Status of operaiton ("success" or "fail")
7
+ # @attr [String] message Response message
8
+ # @attr [Hash] data Response data as key/value pairs
9
+ # @attr [FixNum] code Response code
10
+ class JsonResponse
11
+
12
+ include Jsonify
13
+
14
+ attr_accessor :status, :message, :data, :code
15
+
16
+ SUCCESS = "success"
17
+ FAIL = "fail"
18
+
19
+ # Create a new JsonResponse
20
+ #
21
+ # @param [String] status Status of operaiton ("success" or "fail")
22
+ # @param [String] message Response message
23
+ # @param [Hash] data Response data as key/value pairs
24
+ # @param [FixNum] code Response code
25
+ def initialize(status = nil, message = nil, data = nil, code = nil)
26
+ @status = status
27
+ @message = message
28
+ @data = data
29
+ @code = code
30
+ end
31
+
32
+ # Was operation successful?
33
+ #
34
+ # @return [Boolean] True if @status == "success"
35
+ def success?
36
+ @status && @status == SUCCESS
37
+ end
38
+
39
+ # Was operation unsuccessful?
40
+ #
41
+ # @return [Boolean] True if @status != "success"
42
+ def fail?
43
+ @status && @status == FAIL
44
+ end
45
+ alias_method :error?, :fail?
46
+
47
+ # Create a JsonResponse representing an invalid request
48
+ #
49
+ # @param [String] msg Optional message (default: "invalid request")
50
+ def self.invalid_request(msg = nil) # :nocov:
51
+ new("fail", (msg || "invalid request"), nil, 400)
52
+ end # :nocov:
53
+
54
+ # Create a JsonResponse indicating "bundle not found"
55
+ #
56
+ # @param [String] bundle Name of bundle
57
+ def self.bundle_not_found(bundle) # :nocov:
58
+ new("fail", "bundle not found: #{bundle}", nil, 404)
59
+ end # :nocov:
60
+
61
+ # Create a JsonResponse indicating "command not found"
62
+ #
63
+ # @param [String] command Name of command
64
+ def self.command_not_found(command) # :nocov:
65
+ new("fail", "command not found: #{command}", nil, 404)
66
+ end # :nocov:
67
+
68
+ # Convert object to String, useful for debugging
69
+ #
70
+ # @return [String]
71
+ def to_s # :nocov:
72
+ s = []
73
+ s << "JsonResponse:#{self.object_id}"
74
+ s << " status: #{self.status}"
75
+ s << " code: #{self.code}"
76
+ s << " message: #{self.message}"
77
+ s << " data: " + MultiJson.dump(self.data)
78
+ s.join("\n")
79
+ end # :nocov:
80
+
81
+ end # JsonResponse
82
+
83
+ end # Bixby
@@ -0,0 +1,23 @@
1
+
2
+ module Bixby
3
+ class << self
4
+ attr_accessor :manager_uri
5
+
6
+ def repo_path
7
+ path("repo")
8
+ end
9
+
10
+ # Path to BIXBY_HOME
11
+ def root
12
+ ENV["BIXBY_HOME"]
13
+ end
14
+ alias_method :home, :root
15
+
16
+ # Helper for creating absolute paths inside BIXBY_HOME
17
+ def path(*args)
18
+ File.expand_path(File.join(root, *args))
19
+ end
20
+
21
+
22
+ end
23
+ end
@@ -0,0 +1,80 @@
1
+
2
+ module Bixby
3
+ class CommandResponse
4
+
5
+ include Jsonify
6
+
7
+ attr_accessor :status, :stdout, :stderr
8
+
9
+ # Create a new CommandResponse from the given from_json_response
10
+ #
11
+ # @param [JsonResponse] res
12
+ #
13
+ # @return [CommandResponse]
14
+ def self.from_json_response(res)
15
+ cr = CommandResponse.new(res.data)
16
+ if res.message then
17
+ cr.status ||= 255
18
+ cr.stderr ||= res.message
19
+ end
20
+ return cr
21
+ end
22
+
23
+ # Create a JsonResponse from this CommandResponse
24
+ #
25
+ # @return [JsonResponse]
26
+ def to_json_response
27
+ return JsonResponse.new((status == 0 ? "success" : "fail"), nil, self)
28
+ end
29
+
30
+ def initialize(params = nil)
31
+ if params.kind_of? Hash then
32
+ params.each{ |k,v| self.send("#{k}=", v) if self.respond_to? "#{k}=" }
33
+
34
+ elsif params.class.to_s == "Mixlib::ShellOut" then
35
+ @status = params.exitstatus
36
+ @stdout = params.stdout
37
+ @stderr = params.stderr
38
+ end
39
+ end
40
+
41
+ def success?
42
+ @status.to_i == 0
43
+ end
44
+
45
+ def fail?
46
+ not success?
47
+ end
48
+ alias_method :error?, :fail?
49
+
50
+ def raise!
51
+ if fail? then
52
+ msg = stdout || ""
53
+ msg += "\n" if !(stdout.nil? or stdout.empty?)
54
+ msg += stderr || ""
55
+ raise CommandException.new(msg, msg)
56
+ end
57
+ end
58
+
59
+ def decode # :nocov:
60
+ MultiJson.load(@stdout)
61
+ end # :nocov:
62
+
63
+ def decode_stderr # :nocov:
64
+ MultiJson.load(@stderr)
65
+ end # :nocov:
66
+
67
+ # Convert object to String, useful for debugging
68
+ #
69
+ # @return [String]
70
+ def to_s # :nocov:
71
+ s = []
72
+ s << "CommandResponse:#{self.object_id}"
73
+ s << " status: #{self.status}"
74
+ s << " stdout: " + Debug.pretty_str(stdout)
75
+ s << " stderr: " + Debug.pretty_str(stderr)
76
+ s.join("\n")
77
+ end # :nocov:
78
+
79
+ end # CommandResponse
80
+ end # Bixby