rimu 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODY3ZWYzM2U4MTA2ZjcxMDM2MWEwYTMzYWEzZjgzOTYxZjg4Mjg2MQ==
4
+ ZDA2NzcxYWMzNzEyZmMxZmM1MzBmZWUxN2VjY2MzNzI3NmZmM2I5Nw==
5
5
  data.tar.gz: !binary |-
6
- NTk0MTNkMDRkYjU2NDgxODlmZmQ4YWFjOGY3N2FjYjY4MjA2ZWQwMQ==
6
+ ODY2MmE3N2JkNDE1YjVkZWYxNjg5ZTRkNzc3ODhmNDRlNTg0MDhmMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmQ3OTVlNzRiMTM2NTgwZDIyMmFmYTJhY2VhZDFiODg1NGQ0OWMwOGI4MzQ5
10
- ODlkZWViNDFkMzRjMTdlOWNlMTQyNDk5M2MxZGRkZjlmMjliYWQ5NDI2NTgx
11
- ZTlhZGJiNWY5Y2JiNjhmYTIxODI2MzVkYjViM2I2YTJhMzZiYmM=
9
+ YWEzNTEzMDBkZDBhYzU1YjNmYzE4ZThlMDQwOTc1ZDJjZjVjODMzZjM2MTgx
10
+ NzJlMTIwMWU4OWUwZjgxZmYyYzU3NTUyZDFjMTNhMmM4ZGRiZTU1YWRjYTk4
11
+ OTU2NzkzZDgwM2YxMjYzODU2YThkZjdhNDExZmRjMDhhMjg2YTc=
12
12
  data.tar.gz: !binary |-
13
- MWVmNTQwZjZkM2I3YjFiMGU4OTNkMTFmOGYxYWJjMWM4ZDVlYmU4MzNjODQ3
14
- NmExNjc1NThmNTQ2OTBiYTU1OGEwOGRkZTdmNTYwYzQwMDg0YjE1OGNjMGM3
15
- ZGVkMzgzMjQ3MjY0MDNiYjJiOTQ0ZDIxODY4ZDdiNzkyOGQ0YTY=
13
+ YTA3OWI1Yjk1NDVmMzE5NjBlZjQyNmI3NWFhNmJhYTUyYmZjY2IzNDdkZDgx
14
+ Njc4NzQzNDhkNmU4M2ZhMDc2NDg5OWIyZTA0NDMxZTIwYTkxOGY0NzhjYjVi
15
+ ZWY1MGUyNjE3ZTMxMGNhYTkxMjdhYWIyNjExNTA5ZDdkZjBmZmI=
data/.rubocop.yml CHANGED
@@ -475,7 +475,6 @@ Style/ParallelAssignment:
475
475
  matches on both sides of the assignment.
476
476
  This also provides performance benefits
477
477
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment'
478
- Reference: 'https://github.com/JuanitoFatas/fast-ruby#parallel-assignment-vs-sequential-assignment-code'
479
478
  Enabled: false
480
479
 
481
480
  Style/ParenthesesAroundCondition:
data/lib/rimu/servers.rb CHANGED
@@ -56,7 +56,7 @@ class Rimu::Servers < Rimu
56
56
 
57
57
  def info(oid)
58
58
  raise ArgumentError, "oid should be an Integer" unless oid.is_a?(Integer)
59
- send_request("/r/orders/order-#{oid}-dn/vps", "about_order")
59
+ send_request("/r/orders/order-#{oid}-dn", "about_order")
60
60
  end
61
61
 
62
62
  def cancel(oid)
data/lib/rimu.rb CHANGED
@@ -13,6 +13,8 @@ class Rimu
13
13
  else
14
14
  raise ArgumentError, "The :api_key is required."
15
15
  end
16
+ @read_timeout = args[:read_timeout] if args[:read_timeout]
17
+ raise ArgumentError, "The :read_timeout must be an Integer." if ! @read_timeout.nil? && ! @read_timeout.is_a?(Integer)
16
18
  end
17
19
 
18
20
  def api_url
@@ -23,21 +25,31 @@ class Rimu
23
25
  @api_key
24
26
  end
25
27
 
28
+ def read_timeout
29
+ @read_timeout || 3600
30
+ end
31
+
26
32
  def set_headers
27
33
  {
28
34
  'Content-Type' =>'application/json',
29
35
  'Accept' =>'application/json',
30
36
  'User-Agent' => 'RimuAPI-Ruby',
31
- 'Authorization' => 'rimuhosting apikey=#{api_key}',
37
+ 'Authorization' => "rimuhosting apikey=#{api_key}",
32
38
  }
33
39
  end
34
40
 
35
41
  def post(path, data)
36
42
  logger.info "POST #{api_url}#{path} body:#{data.inspect}" if logger
37
- options = {headers: set_headers, body: data}
43
+ options = {headers: set_headers, body: data.to_json}
38
44
  HTTParty.post(api_url + path, options).parsed_response
39
45
  end
40
46
 
47
+ def put(path, data)
48
+ logger.info "PUT #{api_url}#{path} body:#{data.inspect}" if logger
49
+ options = {headers: set_headers, body: data.to_json, read_timeout: read_timeout}
50
+ HTTParty.put(api_url + path, options).parsed_response
51
+ end
52
+
41
53
  def get(path)
42
54
  logger.info "GET #{api_url}#{path}" if logger
43
55
  options = {headers: set_headers}
@@ -51,13 +63,30 @@ class Rimu
51
63
  end
52
64
 
53
65
  def error?(response)
54
- response and response["jaxrs_response"] and \
55
- response["jaxrs_response"]["response_type"] and \
56
- response["jaxrs_response"]["response_type"] == "ERROR"
66
+ if response.nil?
67
+ return true
68
+ else
69
+ if response.is_a?(Hash)
70
+ ! response.empty? and response[response.keys[0]] and \
71
+ response[response.keys[0]].has_key?("response_type") and \
72
+ response[response.keys[0]]["response_type"] == "ERROR"
73
+ else
74
+ return true
75
+ end
76
+ end
57
77
  end
58
78
 
59
79
  def error_message(response)
60
- " - Error: #{response["jaxrs_response"]["human_readable_message"]}"
80
+ if response.nil? || ! response.is_a?(Hash) || (response.is_a?(Hash) && response.empty?)
81
+ " - Error: Unknown error occured"
82
+ else
83
+ if response[response.keys[0]].has_key?("human_readable_message")
84
+ error = response[response.keys[0]]["human_readable_message"]
85
+ " - Error: #{error}"
86
+ else
87
+ " - Error: Unknown error occured"
88
+ end
89
+ end
61
90
  end
62
91
 
63
92
  def format_response(response, field)
@@ -89,6 +118,7 @@ class Rimu
89
118
  response = get(path)
90
119
  end
91
120
  raise "Errors completing request [#{path}] @ [#{api_url}] with data [#{data.inspect}]:\n#{error_message(response)}" if error?(response)
121
+ logger.info "Response: => #{response}" if logger
92
122
  format_response(response, field)
93
123
  end
94
124
 
@@ -122,7 +152,11 @@ class Rimu
122
152
  define_method(namespace.to_sym) do ||
123
153
  lookup = instance_variable_get("@#{namespace}")
124
154
  return lookup if lookup
125
- subclass = self.class.const_get(namespace.to_s.capitalize).new(:api_key => api_key, :api_url => api_url)
155
+ subclass = self.class.const_get(namespace.to_s.capitalize).new(
156
+ :api_key => api_key,
157
+ :api_url => api_url,
158
+ :logger => logger,
159
+ )
126
160
  instance_variable_set("@#{namespace}", subclass)
127
161
  subclass
128
162
  end
data/rimu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rimu"
5
- spec.version = "0.0.2"
5
+ spec.version = "0.0.3"
6
6
  spec.authors = ["Andrew Colin Kissa"]
7
7
  spec.email = ["andrew@topdog.za.net"]
8
8
  spec.license = "MPL-2.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rimu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Colin Kissa