rimu 0.0.2 → 0.0.3
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 +8 -8
- data/.rubocop.yml +0 -1
- data/lib/rimu/servers.rb +1 -1
- data/lib/rimu.rb +41 -7
- data/rimu.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDA2NzcxYWMzNzEyZmMxZmM1MzBmZWUxN2VjY2MzNzI3NmZmM2I5Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODY2MmE3N2JkNDE1YjVkZWYxNjg5ZTRkNzc3ODhmNDRlNTg0MDhmMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWEzNTEzMDBkZDBhYzU1YjNmYzE4ZThlMDQwOTc1ZDJjZjVjODMzZjM2MTgx
|
10
|
+
NzJlMTIwMWU4OWUwZjgxZmYyYzU3NTUyZDFjMTNhMmM4ZGRiZTU1YWRjYTk4
|
11
|
+
OTU2NzkzZDgwM2YxMjYzODU2YThkZjdhNDExZmRjMDhhMjg2YTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
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' =>
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
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(
|
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