gaddygaddy 0.1.91 → 0.1.92

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
  SHA1:
3
- metadata.gz: 6599fc52c3742b6cc72e5c065d711c393fdde981
4
- data.tar.gz: c6bd8701483ce61903442a341e1474889679ba71
3
+ metadata.gz: 7e6782e2bf303d99fae32b38e8db4d562551e5cc
4
+ data.tar.gz: 704427a3b6d16fd477a715b96e75dd70e46095aa
5
5
  SHA512:
6
- metadata.gz: b534d188dc6ddd668fd9953c473c6e8a7abfb98d10f57b1c719cf7c93d46f00d39a31ed601d77065e2bfe8bb62992acf9f1d676a1dfa59c9dcaa3d0655372d00
7
- data.tar.gz: 5e7527bf8c2330e314d039a74e89ed513ee19d7e4e3a3b393605e06b7e409ed08579004a365045acf9e655b1b7e9ee00126357dce2140e54ae5a40aec118e9b4
6
+ metadata.gz: 46d81cef9ed49f4b342160a24ac3e51dc606bd11243688f35355e518bd94935f5b446a8fd31125aebafb7b1074a2e354e5fbb1d9d63af1d5d759010e4f351fbf
7
+ data.tar.gz: 6ab4d3f7305f6ddf06a84785d65b634207a04103b1931fdb40d021da87e7c64487ef5089b66ea0e479eda7aea8b6e4228b557de054e41a1cdfa3211b852a75b4
@@ -292,6 +292,21 @@ class GaddyGaddy_Client
292
292
  conf_content
293
293
  end
294
294
 
295
+ # Create a new user
296
+ def create_user(user_name, password)
297
+ url = Request.get_base_url(get_host) + "/user/1"
298
+ params = {
299
+ :model =>
300
+ {
301
+ :user_email => URI.encode(user_name),
302
+ :user_password => password
303
+ }
304
+ }.to_json
305
+ response = Request.client_service_post url, params
306
+ logger.debug "The response for the request is #{response} #{response.class}"
307
+ raise JCouldNotPostClientDataException.new({:message=> "Could not post data to the gaddygaddy service, error code is #{response.body}"}) unless response[:status].to_i == 0
308
+ end
309
+
295
310
  def create_gaddy(gaddy_name, user_name, password)
296
311
  url = Request.get_base_url(get_host) + "/installation/device/1"
297
312
  params = {:device_name => gaddy_name,
@@ -303,10 +318,10 @@ class GaddyGaddy_Client
303
318
  raise JCouldNotPostClientDataException.new({:message=> "Could not post data to the gaddygaddy service, error code is #{response.body}"}) unless response[:status].to_i == 0
304
319
  end
305
320
 
306
- def create_new(name)
321
+ def create_new?(name, type)
307
322
  inp = ''
308
323
  unless @options[:create]
309
- puts "Gaddy #{name} doesn't exist, would you like to create it (Y/N)"
324
+ puts "#{type} #{name} doesn't exist, would you like to create it (Y/N)"
310
325
  answer = nil
311
326
  while answer.nil?
312
327
  inp = gets.chomp.upcase
@@ -314,7 +329,7 @@ class GaddyGaddy_Client
314
329
  answer = ['Y','N'].index(inp[0]) ? inp : nil
315
330
  else
316
331
  puts
317
- puts "Gaddy #{name} doesn't exist, would you like to create it (Y/N)"
332
+ puts "#{type} #{name} doesn't exist, would you like to create it (Y/N)"
318
333
  end
319
334
  end
320
335
  end
@@ -329,8 +344,18 @@ class GaddyGaddy_Client
329
344
  rescue Exception => e
330
345
  raise e.inspect
331
346
  end
332
- if get_conf_file['status'] == 12
333
- if create_new(gaddy_name)
347
+ puts "1"
348
+ begin
349
+ status_gaddy = get_conf_file['status']
350
+ rescue RestClient::Unauthorized => e
351
+ if create_new?(user_name, 'User')
352
+ logger.info "Will create a new user #{user_name}"
353
+ create_user(user_name, password)
354
+ end
355
+ status_gaddy = get_conf_file['status']
356
+ end
357
+ if status_gaddy == 12 || status_gaddy == 4
358
+ if create_new?(gaddy_name, 'Gaddy')
334
359
  logger.info "Will create a new gaddy named #{gaddy_name}"
335
360
  create_gaddy(gaddy_name, user_name, password)
336
361
  if get_conf_file['status'] == 12
@@ -341,7 +366,6 @@ class GaddyGaddy_Client
341
366
  puts 'If you would like to create it add parameter --create to the command'
342
367
  end
343
368
  end
344
-
345
369
  end
346
370
 
347
371
  # Check that the config file exist and has valid content, this will also be validated toward the server
data/lib/utils/request.rb CHANGED
@@ -34,18 +34,18 @@ class Request
34
34
  # path will be evaluated so there could be parameters in that one and then use '' for the string
35
35
  # to have the parameters evaluated in this function
36
36
  #
37
- def self.client_service_get(host, path)
37
+ def self.client_service_get(host, path, retries = 1)
38
38
  url = get_base_url(host) + path
39
39
  logger.debug "Will request url #{url}"
40
- result = with_retries(:limit => 10, :sleep=> 5) { RestClient.get url }
40
+ result = with_retries(:limit => retries, :sleep=> 5) { RestClient.get url }
41
41
  result_json = JSON.parse(result)
42
42
  logger.debug "The result of the request is #{result.inspect}"
43
43
  result_json
44
44
  end
45
45
 
46
- def self.client_service_post(url, param)
46
+ def self.client_service_post(url, param, retries = 1)
47
47
  logger.debug "Will request url #{url}"
48
- result = with_retries(:limit => 10, :sleep=> 5) { RestClient.post url, param }
48
+ result = with_retries(:limit => retries, :sleep=> 5) { RestClient.post url, param }
49
49
  JSON.parse(result)
50
50
  end
51
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaddygaddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.91
4
+ version: 0.1.92
5
5
  platform: ruby
6
6
  authors:
7
7
  - GaddyGaddy