nimbu 0.11.9 → 0.12.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea744b90abeb08a41b2b3e1b9e5dbf71e2cc608bcf245cafbf528b351676fcd8
4
- data.tar.gz: e12d6a2a32d6b64c28a713accdcbbd5d9d077286bb09daf68b2a772689ba85a0
3
+ metadata.gz: 89810923de0892b2e89ec5a67e73b09504b6b5e3ca55feb3796e687d0aeaac9d
4
+ data.tar.gz: 234965e37cfe0a548d6d4af6f2f45b5de88ffe4364fb07b1620565d7a200e1e1
5
5
  SHA512:
6
- metadata.gz: 98f3aafe810fd60838c04a0ddb60138ee4ed3d864fce6db48fdbeb8aed6ad1bb2c06ee4443812636d1f7f7ffe6cb76a14365bc15442ed783c7d3df34a06a8a15
7
- data.tar.gz: 328c8393b654b1539578a45f3cb52ab6eb1d938fe1beb557a696053a42891617eeda0a1ac7ecf6545ff92eace5c1eaa6e834d40f7242b3cec49113c71302d20f
6
+ metadata.gz: e3f047d1f0971d7931984e5081b156029b531d01c02151d0df83ee32a957e2b893c8c6c7f8db23d0866427d39c051e2de54e5c763d29968d569d9109dba6d3d7
7
+ data.tar.gz: 7b97b0d9371a70579bee1c89f9a6664ef24989ab2317ffae5095c5e349e708dfe5e6b598aa21a2230349ed07f8df42bc81b62dce2f02d3bf9d7815813754ed90
@@ -1,6 +1,4 @@
1
- # -*- encoding : utf-8 -*-
2
- require "nimbu/version"
3
- require "nimbu-api"
1
+ require 'nimbu-api'
4
2
 
5
3
  module Nimbu
6
4
  def self.debug=(value)
@@ -1,26 +1,24 @@
1
- # -*- encoding : utf-8 -*-
2
- require "yaml"
3
- require "nimbu"
4
- require "nimbu/helpers"
1
+ require 'yaml'
2
+ require 'nimbu'
3
+ require 'nimbu/helpers'
5
4
  require 'term/ansicolor'
5
+ require 'netrc'
6
6
 
7
7
  class Nimbu::Auth
8
8
  class << self
9
-
10
9
  include Nimbu::Helpers
11
- attr_accessor :credentials
12
- attr_accessor :configuration
10
+ attr_accessor :credentials, :configuration
13
11
 
14
12
  def simulator_id
15
13
  return @simulator_id if defined? @simulator_id
16
14
 
17
- ranges = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
18
- @simulator_id ||= (1..40).map{ ranges[rand(ranges.length)] }.join
15
+ ranges = [('a'..'z'), ('A'..'Z'), (0..9)].map { |i| i.to_a }.flatten
16
+ @simulator_id ||= (1..40).map { ranges[rand(ranges.length)] }.join
19
17
  end
20
18
 
21
19
  def client
22
20
  @client ||= begin
23
- Nimbu::Client.new(:oauth_token => token, :endpoint => host, :user_agent => self.user_agent, :auto_pagination => true)
21
+ Nimbu::Client.new(oauth_token: token, endpoint: host, user_agent: user_agent, auto_pagination: true)
24
22
  end
25
23
  end
26
24
 
@@ -47,15 +45,19 @@ class Nimbu::Auth
47
45
  end
48
46
 
49
47
  def host
50
- ENV['NIMBU_HOST'] || "https://api.nimbu.io"
48
+ ENV['NIMBU_HOST'] || 'https://api.nimbu.io'
51
49
  end
52
50
 
53
51
  def default_host
54
- "https://api.nimbu.io"
52
+ 'https://api.nimbu.io'
55
53
  end
56
54
 
57
55
  def admin_host
58
- @admin_host ||= host.gsub(/https?\:\/\/api\./,'')
56
+ @admin_host ||= host.gsub(%r{https?://api\.}, '')
57
+ end
58
+
59
+ def api_host
60
+ @api_host ||= host.gsub(%r{https?://}, '')
59
61
  end
60
62
 
61
63
  def site
@@ -67,11 +69,11 @@ class Nimbu::Auth
67
69
  end
68
70
 
69
71
  def get_nimbu_site
70
- get_configuration["site"]
72
+ get_configuration['site']
71
73
  end
72
74
 
73
75
  def get_nimbu_theme
74
- get_configuration["theme"] || "default-theme"
76
+ get_configuration['theme'] || 'default-theme'
75
77
  end
76
78
 
77
79
  def get_configuration
@@ -94,192 +96,205 @@ class Nimbu::Auth
94
96
  end
95
97
 
96
98
  def ask_for_configuration
97
-
98
99
  subdomain = nil
99
100
  sites = client.sites.list
100
101
 
101
- unless sites.respond_to?(:any?) && sites.any?
102
- display "You don't have access to any Nimbu sites you can edit yet..."
103
- display ""
104
- display "Please visit http://nimbu.io, start your 30-day trial and discover our amazing platform!"
105
- exit(1)
106
- else
102
+ if sites.respond_to?(:any?) && sites.any?
107
103
  print_separator
108
104
  display "\nLet's first setup the configuration for this directory..."
109
105
  display "\nYou have access to following sites:\n"
110
- sites.each_with_index do |site,i|
111
- display " #{i+1}) #{site.name.white.bold} => http://#{site.domain}"
106
+ sites.each_with_index do |site, i|
107
+ display " #{i + 1}) #{site.name.white.bold} => http://#{site.domain}"
112
108
  end
113
109
  site_number = 0
114
110
  retry_site = false
115
111
  while site_number < 1 || site_number > sites.length
116
- unless retry_site
117
- print "\nOn which site would you like to work? "
118
- else
112
+ if retry_site
119
113
  print "\nPlease enter the number of your site (between 1-#{sites.length}): "
114
+ else
115
+ print "\nOn which site would you like to work? "
120
116
  end
121
117
  site_number_string = ask
122
- site_number = site_number_string.to_i rescue 0
118
+ site_number = begin
119
+ site_number_string.to_i
120
+ rescue StandardError
121
+ 0
122
+ end
123
123
  retry_site = true
124
124
  end
125
- puts ""
126
- site = sites[site_number-1]
125
+ puts ''
126
+ site = sites[site_number - 1]
127
127
  display "Site chosen => #{site.name.white.bold} (http://#{site.domain})"
128
128
  subdomain = site.subdomain
129
129
  @site = subdomain
130
+ else
131
+ display "You don't have access to any Nimbu sites you can edit yet..."
132
+ exit(1)
130
133
  end
131
134
 
132
- themes = client.themes(:subdomain => subdomain).list
135
+ themes = client.themes(subdomain: subdomain).list
133
136
  current_theme = if themes.length > 1
134
- theme_number = 0
135
- retry_theme = false
136
- while theme_number < 1 || theme_number > themes.length
137
- unless retry_theme
138
- print "\nOn which theme would you like to work in this directory? "
139
- else
140
- print "\nPlease enter the number of your theme (between 1-#{themes.length}): "
141
- end
142
- theme_number_string = ask
143
- theme_number = theme_number_string.to_i rescue 0
144
- retry_theme = true
145
- end
146
- puts ""
147
- display "Theme chosen => #{themes[theme_number-1].name}"
148
- themes[theme_number-1]
149
- else
150
- themes.first
151
- end
137
+ theme_number = 0
138
+ retry_theme = false
139
+ while theme_number < 1 || theme_number > themes.length
140
+ if retry_theme
141
+ print "\nPlease enter the number of your theme (between 1-#{themes.length}): "
142
+ else
143
+ print "\nOn which theme would you like to work in this directory? "
144
+ end
145
+ theme_number_string = ask
146
+ theme_number = begin
147
+ theme_number_string.to_i
148
+ rescue StandardError
149
+ 0
150
+ end
151
+ retry_theme = true
152
+ end
153
+ puts ''
154
+ display "Theme chosen => #{themes[theme_number - 1].name}"
155
+ themes[theme_number - 1]
156
+ else
157
+ themes.first
158
+ end
152
159
  @theme = current_theme.short
153
160
  print_separator
154
161
 
155
- { "site" => subdomain, "theme" => current_theme.short }
162
+ { 'site' => subdomain, 'theme' => current_theme.short }
156
163
  end
157
164
 
158
165
  def read_configuration
159
- existing_config = YAML::load(File.open( configuration_file )) if File.exists?(configuration_file)
160
- if existing_config && ! existing_config["site"].nil?
161
- existing_config
162
- else
163
- nil
164
- end
166
+ existing_config = YAML.load(File.open(configuration_file)) if File.exist?(configuration_file)
167
+ existing_config if existing_config && !existing_config['site'].nil?
165
168
  end
166
169
 
167
170
  def write_configuration
168
171
  FileUtils.mkdir_p(File.dirname(configuration_file))
169
- File.open(configuration_file, 'w') {|credentials| credentials.puts(YAML.dump(self.configuration))}
170
- FileUtils.chmod(0700, File.dirname(configuration_file))
171
- FileUtils.chmod(0600, configuration_file)
172
+ File.open(configuration_file, 'w') { |credentials| credentials.puts(YAML.dump(configuration)) }
173
+ FileUtils.chmod(0o700, File.dirname(configuration_file))
174
+ FileUtils.chmod(0o600, configuration_file)
172
175
  end
173
176
 
174
177
  def reauthorize
175
178
  @credentials = ask_for_and_save_credentials
176
179
  end
177
180
 
178
- def token # :nodoc:
181
+ def token # :nodoc:
179
182
  ENV['NIMBU_API_KEY'] || get_credentials
180
183
  end
181
184
 
182
- def credentials_file
183
- if host == default_host
184
- "#{home_directory}/.nimbu/credentials"
185
- else
186
- "#{home_directory}/.nimbu/credentials.#{CGI.escape(host.gsub(/https?\:\/\//,''))}"
187
- end
188
- end
189
-
190
- def get_credentials # :nodoc:
185
+ def get_credentials # :nodoc:
191
186
  @credentials ||= (read_credentials || ask_for_and_save_credentials)
187
+ @credentials[:token]
192
188
  end
193
189
 
194
190
  def delete_credentials
195
- FileUtils.rm_f(credentials_file)
196
- @client, @credentials = nil, nil
191
+ n = Netrc.read
192
+ n.delete(api_host)
193
+ n.save
194
+ @client = nil
195
+ @credentials = nil
197
196
  end
198
197
 
199
198
  def read_credentials
200
- credentials = File.read(credentials_file).force_encoding('UTF-8') if File.exists?(credentials_file)
201
- if credentials && credentials =~ /^(bearer|oauth2|token) ([\w]+)$/i
202
- $2
203
- else
204
- nil
205
- end
199
+ n = Netrc.read
200
+ user, token = n[api_host]
201
+ { user: user, token: token } if user && token
206
202
  end
207
203
 
208
204
  def write_credentials
209
- FileUtils.mkdir_p(File.dirname(credentials_file))
210
- File.open(credentials_file, 'w') {|credentials| credentials.print("token #{self.credentials}")}
211
- FileUtils.chmod(0700, File.dirname(credentials_file))
212
- FileUtils.chmod(0600, credentials_file)
205
+ n = Netrc.read
206
+ n[api_host] = @credentials[:user], @credentials[:token]
207
+ n.save
213
208
  end
214
209
 
215
210
  def echo_off
216
211
  with_tty do
217
- system "stty -echo"
212
+ system 'stty -echo'
218
213
  end
219
214
  end
220
215
 
221
216
  def echo_on
222
217
  with_tty do
223
- system "stty echo"
218
+ system 'stty echo'
224
219
  end
225
220
  end
226
221
 
227
- def ask_for_credentials
228
- print "Login: "
229
- user = ask
222
+ def ask_for_credentials(user = nil, password = nil, two_factor_code = nil)
223
+ unless user
224
+ print 'Login: '
225
+ user = ask
226
+ end
230
227
 
231
- print "Password: "
232
- password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
228
+ unless password
229
+ print 'Password: '
230
+ password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
231
+ end
233
232
 
234
233
  begin
234
+ request_headers = {}
235
+ request_headers['X-Nimbu-Two-Factor'] = two_factor_code.to_s.strip unless two_factor_code.nil?
236
+
235
237
  basic_client = Nimbu::Client.new(
236
- :basic_auth => "#{user}:#{password}",
237
- :endpoint => host,
238
- :user_agent => self.user_agent
238
+ basic_auth: "#{user}:#{password}",
239
+ endpoint: host,
240
+ user_agent: user_agent,
241
+ headers: request_headers
239
242
  )
240
- basic_client.authenticate.token
243
+ { user: user, token: basic_client.authenticate.token }
241
244
  rescue Exception => e
242
245
  if e.respond_to?(:http_status_code) && e.http_status_code == 401
243
- display " => could not login... please check your username and/or password!\n\n"
246
+ if e.message =~ /two factor authentication/
247
+ print '2FA Token: '
248
+ two_factor_code = ask
249
+ ask_for_credentials(user, password, two_factor_code)
250
+ else
251
+ display " => could not login... please check your username and/or password!\n\n"
252
+ nil
253
+ end
244
254
  else
245
255
  display " => hmmmm... an error occurred: #{e}. \n\n\nIf this continues to occur, please report \nthe error at https://github.com/nimbu/nimbu/issues.\n\n"
256
+ nil
246
257
  end
247
- nil
248
258
  end
249
259
  end
250
260
 
251
261
  def ask_for_password_on_windows
252
- require "Win32API"
262
+ require 'Win32API'
253
263
  char = nil
254
264
  password = ''
255
265
 
256
- while char = Win32API.new("msvcrt", "_getch", [ ], "L").Call do
257
- break if char == 10 || char == 13 # received carriage return or newline
258
- if char == 127 || char == 8 # backspace and delete
266
+ while char = Win32API.new('msvcrt', '_getch', [], 'L').Call
267
+ break if [10, 13].include?(char) # received carriage return or newline
268
+
269
+ if [10, 13, 10, 13, 127, 8].include?(char) # backspace and delete
259
270
  password.slice!(-1, 1)
260
271
  else
261
272
  # windows might throw a -1 at us so make sure to handle RangeError
262
- (password << char.chr) rescue RangeError
273
+ begin
274
+ (password << char.chr)
275
+ rescue StandardError
276
+ RangeError
277
+ end
263
278
  end
264
279
  end
265
280
  puts
266
- return password
281
+ password
267
282
  end
268
283
 
269
284
  def ask_for_password
270
285
  echo_off
271
- trap("INT") do
286
+ trap('INT') do
272
287
  echo_on
273
288
  exit
274
289
  end
275
290
  password = ask
276
291
  puts
277
292
  echo_on
278
- return password
293
+ password
279
294
  end
280
295
 
281
296
  def ask_for_and_save_credentials
282
- display "Please authenticate with Nimbu.io:"
297
+ display "Please authenticate with #{admin_host}:"
283
298
  begin
284
299
  @credentials = ask_for_credentials
285
300
  write_credentials
@@ -299,7 +314,7 @@ class Nimbu::Auth
299
314
 
300
315
  def print_separator
301
316
  print "\n"
302
- 60.times { print "#"}
317
+ 60.times { print '#' }
303
318
  print "\n"
304
319
  end
305
320
 
@@ -309,7 +324,7 @@ class Nimbu::Auth
309
324
 
310
325
  def invalid_access_message
311
326
  "Error! You do not have access to #{Nimbu::Auth.site}.#{Nimbu::Auth.admin_host}! " +
312
- "Please check your site id or request access to your site owner."
327
+ 'Please check your site id or request access to your site owner.'
313
328
  end
314
329
  end
315
330
  end
@@ -1,8 +1,7 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'nimbu/helpers'
3
2
  require 'nimbu/version'
4
3
  require 'term/ansicolor'
5
- require "optparse"
4
+ require 'optparse'
6
5
 
7
6
  class String
8
7
  include Term::ANSIColor
@@ -10,12 +9,12 @@ end
10
9
 
11
10
  module Nimbu
12
11
  module Command
13
- class CommandFailed < RuntimeError; end
12
+ class CommandFailed < RuntimeError; end
14
13
 
15
14
  extend Nimbu::Helpers
16
15
 
17
16
  def self.load
18
- Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
17
+ Dir[File.join(File.dirname(__FILE__), 'command', '*.rb')].sort.each do |file|
19
18
  require file
20
19
  end
21
20
  end
@@ -29,7 +28,7 @@ module Nimbu
29
28
  end
30
29
 
31
30
  def self.files
32
- @@files ||= Hash.new {|hash,key| hash[key] = File.readlines(key).map {|line| line.strip}}
31
+ @@files ||= Hash.new { |hash, key| hash[key] = File.readlines(key).map { |line| line.strip } }
33
32
  end
34
33
 
35
34
  def self.namespaces
@@ -65,7 +64,7 @@ module Nimbu
65
64
  end
66
65
 
67
66
  def self.global_option(name, *args, &blk)
68
- global_options << { :name => name.to_s, :args => args.sort.reverse, :proc => blk }
67
+ global_options << { name: name.to_s, args: args.sort.reverse, proc: blk }
69
68
  end
70
69
 
71
70
  def self.warnings
@@ -73,15 +72,13 @@ module Nimbu
73
72
  end
74
73
 
75
74
  def self.display_warnings
76
- unless warnings.empty?
77
- $stderr.puts(warnings.map {|warning| " ! #{warning}"}.join("\n"))
78
- end
75
+ warn(warnings.map { |warning| " ! #{warning}" }.join("\n")) unless warnings.empty?
79
76
  end
80
77
 
81
- global_option :help, "--help", "-h"
82
- global_option :debug, "--debug"
78
+ global_option :help, '--help', '-h'
79
+ global_option :debug, '--debug'
83
80
 
84
- def self.prepare_run(cmd, args=[])
81
+ def self.prepare_run(cmd, args = [])
85
82
  command = parse(cmd)
86
83
 
87
84
  if args.include?('-h') || args.include?('--help')
@@ -90,13 +87,14 @@ module Nimbu
90
87
  command = parse(cmd)
91
88
  end
92
89
 
93
- if cmd == '--version'
90
+ if ['--version', '-v'].include?(cmd)
94
91
  cmd = 'version'
95
92
  command = parse(cmd)
96
93
  end
97
94
 
98
95
  @current_command = cmd
99
- @anonymized_args, @normalized_args = [], []
96
+ @anonymized_args = []
97
+ @normalized_args = []
100
98
 
101
99
  opts = {}
102
100
  invalid_options = []
@@ -105,25 +103,25 @@ module Nimbu
105
103
  parser.base.long.delete('version')
106
104
  (global_options + (command && command[:options] || [])).each do |option|
107
105
  parser.on(*option[:args]) do |value|
108
- if option[:proc]
109
- option[:proc].call(value)
110
- end
106
+ option[:proc].call(value) if option[:proc]
111
107
  opts[option[:name].gsub('-', '_').to_sym] = value
112
- ARGV.join(' ') =~ /(#{option[:args].map {|arg| arg.split(' ', 2).first}.join('|')})/
113
- @anonymized_args << "#{$1} _"
108
+ ARGV.join(' ') =~ /(#{option[:args].map { |arg| arg.split(' ', 2).first }.join('|')})/
109
+ @anonymized_args << "#{Regexp.last_match(1)} _"
114
110
  @normalized_args << "#{option[:args].last.split(' ', 2).first} _"
115
111
  end
116
112
  end
117
113
  end
118
114
 
115
+ parser.version = Nimbu::VERSION
116
+
119
117
  begin
120
118
  parser.order!(args) do |nonopt|
121
119
  invalid_options << nonopt
122
120
  @anonymized_args << '!'
123
121
  @normalized_args << '!'
124
122
  end
125
- rescue OptionParser::InvalidOption => ex
126
- invalid_options << ex.args.first
123
+ rescue OptionParser::InvalidOption => e
124
+ invalid_options << e.args.first
127
125
  @anonymized_args << '!'
128
126
  @normalized_args << '!'
129
127
  retry
@@ -135,52 +133,54 @@ module Nimbu
135
133
  @current_options = opts
136
134
  @invalid_arguments = invalid_options
137
135
 
138
- if opts[:debug]
139
- Nimbu.debug = true
140
- end
136
+ Nimbu.debug = true if opts[:debug]
141
137
 
142
138
  @anonymous_command = [ARGV.first, *@anonymized_args].join(' ')
143
139
  begin
144
140
  usage_directory = "#{home_directory}/.nimbu/usage"
145
141
  FileUtils.mkdir_p(usage_directory)
146
142
  usage_file = usage_directory << "/#{Nimbu::VERSION}"
147
- usage = if File.exists?(usage_file)
148
- json_decode(File.read(usage_file).force_encoding('UTF-8'))
149
- else
150
- {}
151
- end
143
+ usage = if File.exist?(usage_file)
144
+ json_decode(File.read(usage_file).force_encoding('UTF-8'))
145
+ else
146
+ {}
147
+ end
152
148
  usage[@anonymous_command] ||= 0
153
149
  usage[@anonymous_command] += 1
154
150
  File.write(usage_file, json_encode(usage) + "\n")
155
- rescue
151
+ rescue StandardError
156
152
  # usage writing is not important, allow failures
157
153
  end
158
154
 
159
155
  if command
160
156
  command_instance = command[:klass].new(args.dup, opts.dup)
161
157
 
162
- if !@normalized_args.include?('--app _') && (implied_app = command_instance.app rescue nil)
158
+ if !@normalized_args.include?('--app _') && (implied_app = begin
159
+ command_instance.app
160
+ rescue StandardError
161
+ nil
162
+ end)
163
163
  @normalized_args << '--app _'
164
164
  end
165
- @normalized_command = [ARGV.first, @normalized_args.sort_by {|arg| arg.gsub('-', '')}].join(' ')
165
+ @normalized_command = [ARGV.first, @normalized_args.sort_by { |arg| arg.gsub('-', '') }].join(' ')
166
166
 
167
- [ command_instance, command[:method] ]
167
+ [command_instance, command[:method]]
168
168
  else
169
169
  error([
170
170
  "`#{cmd}` is not a Nimbu command.",
171
171
  suggestion(cmd, commands.keys + command_aliases.keys),
172
- "See `Nimbu help` for a list of available commands."
172
+ 'See `Nimbu help` for a list of available commands.'
173
173
  ].compact.join("\n"))
174
174
  end
175
175
  end
176
176
 
177
- def self.run(cmd, arguments=[])
177
+ def self.run(cmd, arguments = [])
178
178
  begin
179
179
  object, method = prepare_run(cmd, arguments.dup)
180
180
  object.send(method)
181
- rescue Interrupt, StandardError, SystemExit => error
181
+ rescue Interrupt, StandardError, SystemExit => e
182
182
  # load likely error classes, as they may not be loaded yet due to defered loads
183
- raise(error)
183
+ raise(e)
184
184
  end
185
185
  # rescue Nimbu::API::Errors::Unauthorized, RestClient::Unauthorized
186
186
  # puts "Authentication failure"
@@ -219,10 +219,10 @@ module Nimbu
219
219
  rescue CommandFailed => e
220
220
  error e.message
221
221
  rescue OptionParser::ParseError
222
- commands[cmd] ? run("help", [cmd]) : run("help")
222
+ commands[cmd] ? run('help', [cmd]) : run('help')
223
223
  rescue Excon::Errors::SocketError => e
224
224
  if e.message == 'getaddrinfo: nodename nor servname provided, or not known (SocketError)'
225
- error("Unable to connect to Nimbu API, please check internet connectivity and try again.")
225
+ error('Unable to connect to Nimbu API, please check internet connectivity and try again.')
226
226
  else
227
227
  raise(e)
228
228
  end
@@ -234,25 +234,30 @@ module Nimbu
234
234
  commands[cmd] || commands[command_aliases[cmd]]
235
235
  end
236
236
 
237
- def self.extract_error(body, options={})
237
+ def self.extract_error(body, _options = {})
238
238
  default_error = block_given? ? yield : "Internal server error.\nRun 'nimbu status' to check for known platform issues."
239
239
  parse_error_xml(body) || parse_error_json(body) || parse_error_plain(body) || default_error
240
240
  end
241
241
 
242
242
  def self.parse_error_xml(body)
243
- xml_errors = REXML::Document.new(body).elements.to_a("//errors/error")
244
- msg = xml_errors.map { |a| a.text }.join(" / ")
243
+ xml_errors = REXML::Document.new(body).elements.to_a('//errors/error')
244
+ msg = xml_errors.map { |a| a.text }.join(' / ')
245
245
  return msg unless msg.empty?
246
246
  rescue Exception
247
247
  end
248
248
 
249
249
  def self.parse_error_json(body)
250
- json = json_decode(body.to_s) rescue false
250
+ json = begin
251
+ json_decode(body.to_s)
252
+ rescue StandardError
253
+ false
254
+ end
251
255
  json ? json['error'] : nil
252
256
  end
253
257
 
254
258
  def self.parse_error_plain(body)
255
- return unless body.respond_to?(:headers) && body.headers[:content_type].to_s.include?("text/plain")
259
+ return unless body.respond_to?(:headers) && body.headers[:content_type].to_s.include?('text/plain')
260
+
256
261
  body.to_s
257
262
  end
258
263
  end
@@ -1,8 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require "nimbu/command/base"
3
- require "nimbu/server/base"
4
- require 'term/ansicolor'
5
- require 'thin'
6
3
 
7
4
  # running a local server to speed up designing Nimbu themes
8
5
  #
@@ -22,6 +19,13 @@ class Nimbu::Command::Server < Nimbu::Command::Base
22
19
  # --nocookies # disable session refresh cookie check
23
20
  #
24
21
  def index
22
+ require 'rubygems'
23
+ require "nimbu/server/base"
24
+ require 'term/ansicolor'
25
+ require 'thin'
26
+ require 'filewatcher'
27
+ require 'pathname'
28
+
25
29
  # Check if config file is present?
26
30
  if !Nimbu::Auth.read_configuration
27
31
  print red(bold("ERROR")), ": this directory does not seem to contain any Nimbu theme configuration. \n ==> Run \"", bold { "nimbu init"}, "\" to initialize this directory."
@@ -243,10 +247,6 @@ class Nimbu::Command::Server < Nimbu::Command::Base
243
247
  end
244
248
  end
245
249
 
246
- require 'rubygems'
247
- require 'filewatcher'
248
- require 'pathname'
249
-
250
250
  class HamlWatcher
251
251
  class << self
252
252
  include Term::ANSIColor
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Nimbu
4
- VERSION = '0.11.9'
2
+ VERSION = '0.12.0'.freeze
5
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimbu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.9
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zenjoy BVBA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: netrc
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: filewatcher
183
197
  requirement: !ruby/object:Gem::Requirement