linodeapi 2.0.0 → 2.0.1
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/linodeapi.rb +1 -0
- data/lib/linodeapi/helpers.rb +42 -0
- data/lib/linodeapi/raw.rb +16 -43
- data/linodeapi.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774a92f57a045e5df6250bd6654fc773b7e7c33f
|
4
|
+
data.tar.gz: efb03272ff013266e9a43ed270eeafa03fb5b2a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cced09324ac708e26276287c6a3e93fd4afd95d95dc289e33ba0e0b26941544bca779fe5118f403e5a9d6226dab9c108cdafa59a3cc2df92deb6167b089ad6a0
|
7
|
+
data.tar.gz: 81546c62f9d6e28601dd3e6526affffc7bbe276f2cbab82ed6a96c5d1bd53a4187b3529fea67690c45797af68552e14a3209c5300c704b91e0c34169a0d4371f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 2.0.1 / 2017-10-03
|
2
|
+
|
3
|
+
* [ENHANCEMENT] Broke out some of the parsing code into linodeapi/helpers to make it easier to read
|
4
|
+
* [FEATURE] Support using multiple LinodeAPI::Raw instances with different endpoint URIs at the same time
|
5
|
+
|
6
|
+
# 2.0.0 / 2017-10-03
|
7
|
+
|
8
|
+
* [FEATURE] LinodeAPI::Retryable class that automatically retries supported errors
|
9
|
+
* [ENHANCEMENT] Cleaned up LinodeAPI::Raw's parameter handling
|
10
|
+
* [FEATURE] Added unique error codes to lib/linodeapi/errors.rb for API/HTTP errors
|
11
|
+
|
1
12
|
# 1.0.1 / 2016-07-01
|
2
13
|
|
3
14
|
* [FEATURE] Expose LinodeAPI.spec_version
|
data/lib/linodeapi.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module LinodeAPI
|
2
|
+
##
|
3
|
+
# HTTP / API parsing helpers
|
4
|
+
module Helpers
|
5
|
+
def error_check(resp)
|
6
|
+
error = create_http_error(resp)
|
7
|
+
raise(error) if error
|
8
|
+
data = resp.parsed_response
|
9
|
+
raise('Invalid API response received') if data.nil?
|
10
|
+
parse data
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_http_error(resp)
|
14
|
+
code = resp.code
|
15
|
+
return nil if code == 200
|
16
|
+
delay = resp.headers['Retry-After']
|
17
|
+
return RetryableHTTPError.new(code, delay) if delay
|
18
|
+
HTTPError.new(code)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse(resp)
|
22
|
+
resp['ERRORARRAY'].reject! { |x| x['ERRORCODE'].zero? }
|
23
|
+
raise(APIError, resp) unless resp['ERRORARRAY'].empty?
|
24
|
+
data = resp['DATA']
|
25
|
+
data.is_a?(Hash) ? clean(data) : data.map { |x| clean x }
|
26
|
+
end
|
27
|
+
|
28
|
+
def clean(object)
|
29
|
+
OpenStruct.new(Hash[object.map { |k, v| [k.downcase.to_sym, v] }])
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate(method, mspec, given)
|
33
|
+
mspec.each_with_object({}) do |(param, info), options|
|
34
|
+
if given.include? param
|
35
|
+
options[param] = VALIDATION_METHODS[info[:type]].call given[param]
|
36
|
+
elsif info[:required]
|
37
|
+
raise ArgumentError, "#{method} requires #{param}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/linodeapi/raw.rb
CHANGED
@@ -8,10 +8,11 @@ module LinodeAPI
|
|
8
8
|
# Raw API object
|
9
9
|
class Raw
|
10
10
|
include HTTParty
|
11
|
+
extend Helpers
|
11
12
|
|
12
13
|
def initialize(params = {})
|
13
14
|
@options = params
|
14
|
-
|
15
|
+
@options[:endpoint] ||= DEFAULT_ENDPOINT
|
15
16
|
@options[:names] ||= []
|
16
17
|
@options[:spec] ||= LinodeAPI.spec
|
17
18
|
@options[:apikey] ||= authenticate(params)
|
@@ -38,6 +39,10 @@ module LinodeAPI
|
|
38
39
|
@apikey ||= @options[:apikey]
|
39
40
|
end
|
40
41
|
|
42
|
+
def endpoint
|
43
|
+
@endpoint ||= @options[:endpoint]
|
44
|
+
end
|
45
|
+
|
41
46
|
private
|
42
47
|
|
43
48
|
def authenticate(params = {})
|
@@ -75,51 +80,19 @@ module LinodeAPI
|
|
75
80
|
end
|
76
81
|
|
77
82
|
def call(method, params = {})
|
83
|
+
options = build_call_body(method, params)
|
84
|
+
self.class.error_check self.class.post(
|
85
|
+
'', body: options, base_uri: endpoint
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_call_body(method, params)
|
78
90
|
mspec = spec[:subs][method]
|
79
|
-
|
91
|
+
mname = (names + [method.to_s]).join '.'
|
80
92
|
options = self.class.validate method, mspec[:params], params
|
81
93
|
options[:api_key] = apikey
|
82
|
-
options[:api_action] =
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def error_check(resp)
|
87
|
-
error = create_http_error(resp)
|
88
|
-
raise(error) if error
|
89
|
-
data = resp.parsed_response
|
90
|
-
raise('Invalid API response received') if data.nil?
|
91
|
-
self.class.parse data
|
92
|
-
end
|
93
|
-
|
94
|
-
def create_http_error(resp)
|
95
|
-
code = resp.code
|
96
|
-
return nil if code == 200
|
97
|
-
delay = resp.headers['Retry-After']
|
98
|
-
return RetryableHTTPError.new(code, delay) if delay
|
99
|
-
HTTPError.new(code)
|
100
|
-
end
|
101
|
-
|
102
|
-
class << self
|
103
|
-
def parse(resp)
|
104
|
-
resp['ERRORARRAY'].reject! { |x| x['ERRORCODE'].zero? }
|
105
|
-
raise(APIError, resp) unless resp['ERRORARRAY'].empty?
|
106
|
-
data = resp['DATA']
|
107
|
-
data.is_a?(Hash) ? clean(data) : data.map { |x| clean x }
|
108
|
-
end
|
109
|
-
|
110
|
-
def clean(object)
|
111
|
-
OpenStruct.new(Hash[object.map { |k, v| [k.downcase.to_sym, v] }])
|
112
|
-
end
|
113
|
-
|
114
|
-
def validate(method, mspec, given)
|
115
|
-
mspec.each_with_object({}) do |(param, info), options|
|
116
|
-
if given.include? param
|
117
|
-
options[param] = VALIDATION_METHODS[info[:type]].call given[param]
|
118
|
-
elsif info[:required]
|
119
|
-
raise ArgumentError, "#{method} requires #{param}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
94
|
+
options[:api_action] = mname
|
95
|
+
options
|
123
96
|
end
|
124
97
|
end
|
125
98
|
|
data/linodeapi.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linodeapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- dev/version
|
159
159
|
- lib/linodeapi.rb
|
160
160
|
- lib/linodeapi/errors.rb
|
161
|
+
- lib/linodeapi/helpers.rb
|
161
162
|
- lib/linodeapi/raw.rb
|
162
163
|
- lib/linodeapi/retryable.rb
|
163
164
|
- linodeapi.gemspec
|
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
191
|
version: '0'
|
191
192
|
requirements: []
|
192
193
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.6.
|
194
|
+
rubygems_version: 2.6.11
|
194
195
|
signing_key:
|
195
196
|
specification_version: 4
|
196
197
|
summary: Linode API wrapper
|