ubalo 0.9 → 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/ubalo CHANGED
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  def account
32
32
  unless @account.authorized?
33
- raise Ubalo::Error, "Could not find your credentials. Please run ubalo login."
33
+ raise Ubalo::Error, "Could not find your credentials. #{Ubalo::Util.login_suggestion}"
34
34
  end
35
35
  @account
36
36
  end
@@ -104,8 +104,17 @@ end
104
104
 
105
105
  desc 'Display tasks'
106
106
  command :tasks do |c|
107
+ c.desc 'show all tasks, not just those for the current pod'
108
+ c.switch :all
109
+
107
110
  c.action do |global_options,options,args|
108
- account.tasks.each do |task|
111
+ if options.all
112
+ tasks = account.tasks
113
+ else
114
+ tasks = pod.tasks
115
+ end
116
+
117
+ tasks.each do |task|
109
118
  puts "#{task.label} (#{task.state}) #{task.pod_name} #{Ubalo::Util.time_ago_in_words task.submitted_at}"
110
119
  end
111
120
  end
data/lib/ubalo/account.rb CHANGED
@@ -29,7 +29,7 @@ module Ubalo
29
29
  def refresh!
30
30
  update_attributes(request(:get, "/users/#{username}"))
31
31
  rescue RestClient::ResourceNotFound
32
- raise Ubalo::Error, "Your credentials for #{username} are invalid"
32
+ raise Ubalo::Error, "Your credentials for #{username} are invalid. #{Util.login_suggestion}"
33
33
  end
34
34
 
35
35
  def pod_from_json(pod_json)
data/lib/ubalo/task.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ubalo
2
2
  class Task
3
- attr_reader :label, :state, :pod_name, :arg, :output, :submitted_at, :elapsed_time
3
+ attr_reader :label, :state, :pod_name, :arg_error, :output_error, :submitted_at, :elapsed_time
4
4
 
5
5
  def self.create_with_json(account, json)
6
6
  new(account, json.fetch('label'), json)
@@ -43,9 +43,13 @@ module Ubalo
43
43
  s = ""
44
44
  s << " label: #{label}\n"
45
45
  s << " pod: #{pod_name}\n"
46
- if arg
47
- s << " arg:\n"
48
- s << Util.indent(arg.pretty_inspect)
46
+ if arg?
47
+ if @arg_error
48
+ s << "! Parse error in arg: #{@arg_error.message}"
49
+ else
50
+ s << " arg:\n"
51
+ s << Util.indent(arg.pretty_inspect)
52
+ end
49
53
  end
50
54
  s << " state: #{state}\n"
51
55
 
@@ -67,9 +71,13 @@ module Ubalo
67
71
  end
68
72
  end
69
73
 
70
- if output
71
- s << "output:\n"
72
- s << Util.indent(output.pretty_inspect)
74
+ if output?
75
+ if @output_error
76
+ s << "! Parse error in output: #{@output_error.message}"
77
+ else
78
+ s << "output:\n"
79
+ s << Util.indent(output.pretty_inspect)
80
+ end
73
81
  end
74
82
  s
75
83
  end
@@ -85,11 +93,42 @@ module Ubalo
85
93
  @submitted_at = attributes['submitted_at']
86
94
  @elapsed_time = attributes['elapsed_time']
87
95
 
88
- @arg = Util.decode_content(attributes['arg']) if attributes['arg']
89
- @output = Util.decode_content(attributes['outputs']) if attributes['outputs']
96
+ parse_arg(attributes['arg']) if attributes['arg']
97
+ parse_output(attributes['outputs']) if attributes['outputs']
90
98
  self
91
99
  end
92
100
 
101
+ def parse_arg(raw)
102
+ @arg = Util.decode_content(raw)
103
+ rescue
104
+ @arg_error = $!
105
+ end
106
+
107
+ def arg
108
+ raise "Error with arg: #{@arg_error}" if @arg_error
109
+ @arg
110
+ end
111
+
112
+ def arg?
113
+ @arg || @arg_error
114
+ end
115
+
116
+ def parse_output(raw)
117
+ @output = Util.decode_content(raw)
118
+ rescue
119
+ @output_error = $!
120
+ end
121
+
122
+ def output
123
+ raise "Error with output: #{@output_error}" if @output_error
124
+ @output
125
+ end
126
+
127
+ def output?
128
+ @output || @output_error
129
+ end
130
+
131
+
93
132
  def request method, path = nil, options = {}
94
133
  @account.request(method, "/tasks/#{label}#{path}", options)
95
134
  end
data/lib/ubalo/util.rb CHANGED
@@ -83,10 +83,19 @@ module Ubalo
83
83
  end
84
84
  end
85
85
 
86
+ def ubalo_headers
87
+ {
88
+ 'X-Ubalo-Version' => Ubalo.version,
89
+ 'User-Agent' => "ubalo-cli/#{Ubalo.version}",
90
+ 'X-Ruby-Version' => RUBY_VERSION,
91
+ 'X-Ruby-Platform' => RUBY_PLATFORM,
92
+ }
93
+ end
94
+
86
95
  def http_request(method, url, options)
87
96
  params = options.delete(:params) || {}
88
97
 
89
- headers = {:accept => :json, 'X-Ubalo-Version' => Ubalo.version}
98
+ headers = ubalo_headers.merge({:accept => :json})
90
99
 
91
100
  if authorization = options.delete(:authorization)
92
101
  headers.merge!(:authorization => authorization)
@@ -117,6 +126,8 @@ module Ubalo
117
126
  else
118
127
  JSON.load(response)
119
128
  end
129
+ rescue RestClient::Request::Unauthorized
130
+ raise Ubalo::Error, "Your credentials are invalid. #{login_suggestion}"
120
131
  rescue RestClient::BadRequest => e
121
132
  if message = JSON.load(e.response.to_s)["upgrade_message"]
122
133
  raise Ubalo::Error, message
@@ -125,6 +136,10 @@ module Ubalo
125
136
  end
126
137
  end
127
138
 
139
+ def login_suggestion
140
+ "Please run ubalo login."
141
+ end
142
+
128
143
  def pluralize count, word
129
144
  if count == 1
130
145
  "#{count} #{word}"
@@ -149,9 +164,9 @@ module Ubalo
149
164
 
150
165
  def indent str, amount=2
151
166
  if str
152
- str.each_line.map do |l|
167
+ str.chomp.each_line.map do |l|
153
168
  " "*amount + l
154
- end.join
169
+ end.join + "\n"
155
170
  else
156
171
  ""
157
172
  end
data/lib/ubalo/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ubalo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.9"
3
+ VERSION = "0.10"
4
4
  end
5
5
 
6
6
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubalo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: '0.10'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000Z
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &70214700595780 !ruby/object:Gem::Requirement
16
+ requirement: &70350445320100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70214700595780
24
+ version_requirements: *70350445320100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70214700594160 !ruby/object:Gem::Requirement
27
+ requirement: &70350445319680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70214700594160
35
+ version_requirements: *70350445319680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70214700592680 !ruby/object:Gem::Requirement
38
+ requirement: &70350445319260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70214700592680
46
+ version_requirements: *70350445319260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &70214700591800 !ruby/object:Gem::Requirement
49
+ requirement: &70350445318660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70214700591800
57
+ version_requirements: *70350445318660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: archive-tar-minitar
60
- requirement: &70214700591020 !ruby/object:Gem::Requirement
60
+ requirement: &70350445317500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70214700591020
68
+ version_requirements: *70350445317500
69
69
  description: CLI and API client for Ubalo
70
70
  email: dev@ubalo.com
71
71
  executables:
@@ -93,24 +93,18 @@ require_paths:
93
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
- - - ! '>='
96
+ - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: '0'
99
- segments:
100
- - 0
101
- hash: -2863097484302400668
98
+ version: 1.9.2
102
99
  required_rubygems_version: !ruby/object:Gem::Requirement
103
100
  none: false
104
101
  requirements:
105
102
  - - ! '>='
106
103
  - !ruby/object:Gem::Version
107
104
  version: '0'
108
- segments:
109
- - 0
110
- hash: -2863097484302400668
111
105
  requirements: []
112
106
  rubyforge_project:
113
- rubygems_version: 1.8.10
107
+ rubygems_version: 1.8.11
114
108
  signing_key:
115
109
  specification_version: 3
116
110
  summary: CLI and API client for Ubalo