lm_rest 1.0.1 → 1.0.2
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/api.json +8 -8
- data/lib/lm_rest/api_client.rb +53 -62
- data/lib/lm_rest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f137a994d6ddab31ee6c1a76ccae930bc24f12cecd4c730b1ca0c01976e5b664
|
4
|
+
data.tar.gz: 1e0a0244811c50863ff54b4595bf3ad3405c7ec9b3507b8a53416526eb042b09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d54b5b7596fad51d9b380b2ddf65ba1783b9976fa30b2b1f1089c9874ef23e2aa3c5d20c85081cd4bcdd7d960821d034160d6178e9322e06f0d4eadd8fa6216e
|
7
|
+
data.tar.gz: 01db43bbf4e101b91b27253920bfb80437953bb23819c2d0b0b47612b61455d63e0f3d3ee49f3a4deebfc457ccd887c65827aeac47cc35c20226212c1536ab0c
|
data/api.json
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
]
|
24
24
|
},
|
25
25
|
"Collector": {
|
26
|
-
"url": "/setting/collectors",
|
26
|
+
"url": "/setting/collector/collectors",
|
27
27
|
"method_names": {
|
28
28
|
"singular": "collector",
|
29
29
|
"plural": "collectors"
|
@@ -126,11 +126,11 @@
|
|
126
126
|
"delete"
|
127
127
|
]
|
128
128
|
},
|
129
|
-
"
|
130
|
-
"url": "/
|
129
|
+
"Website": {
|
130
|
+
"url": "/website/websites",
|
131
131
|
"method_names": {
|
132
|
-
"singular": "
|
133
|
-
"plural": "
|
132
|
+
"singular": "website",
|
133
|
+
"plural": "websites"
|
134
134
|
},
|
135
135
|
"actions": [
|
136
136
|
"get",
|
@@ -143,7 +143,7 @@
|
|
143
143
|
]
|
144
144
|
},
|
145
145
|
"SiteMonitorCheckpoint": {
|
146
|
-
"url": "/
|
146
|
+
"url": "/website/smcheckpoints",
|
147
147
|
"method_names": {
|
148
148
|
"singular": "smcheckpoint",
|
149
149
|
"plural": "smcheckpoints"
|
@@ -153,7 +153,7 @@
|
|
153
153
|
]
|
154
154
|
},
|
155
155
|
"ServiceGroup": {
|
156
|
-
"url": "/
|
156
|
+
"url": "/website/groups",
|
157
157
|
"method_names": {
|
158
158
|
"singular": "service_group",
|
159
159
|
"plural": "service_groups"
|
@@ -195,7 +195,7 @@
|
|
195
195
|
]
|
196
196
|
},
|
197
197
|
"APIToken": {
|
198
|
-
"url": "/setting/
|
198
|
+
"url": "/setting/admin/apitokens",
|
199
199
|
"method_names": {
|
200
200
|
"singular": "api_token",
|
201
201
|
"plural": "api_tokens"
|
data/lib/lm_rest/api_client.rb
CHANGED
@@ -38,14 +38,6 @@ module LMRest
|
|
38
38
|
uri.split("?")[0].split("/").join("/")
|
39
39
|
end
|
40
40
|
|
41
|
-
def snakerize(string)
|
42
|
-
string.gsub(/::/, '/').
|
43
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
44
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
45
|
-
tr("-", "_").
|
46
|
-
downcase
|
47
|
-
end
|
48
|
-
|
49
41
|
def sign(method, uri, data = nil)
|
50
42
|
|
51
43
|
resource_uri = uri_to_resource_uri(uri)
|
@@ -180,76 +172,75 @@ module LMRest
|
|
180
172
|
end
|
181
173
|
end
|
182
174
|
|
183
|
-
def self.
|
175
|
+
def self.define_action_methods(resource_type, attributes)
|
176
|
+
singular = attributes['method_names']['singular']
|
177
|
+
plural = attributes['method_names']['plural']
|
184
178
|
resource_uri = attributes['url']
|
185
|
-
@@api_json[paths].keys.each do |path|
|
186
179
|
|
187
|
-
|
188
|
-
|
189
|
-
|
180
|
+
attributes['actions'].each do |action|
|
181
|
+
case action
|
182
|
+
when 'get'
|
190
183
|
|
191
|
-
|
192
|
-
method_name = snakerize(@@api_json['paths'][path][action][operationId])
|
184
|
+
uri = lambda { |params| "#{resource_uri}#{RequestParams.parameterize(params)}"}
|
193
185
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
186
|
+
unless plural.nil?
|
187
|
+
# Define a method to fetch multiple resources with optional params
|
188
|
+
define_method("get_#{plural}") do |params = {}|
|
189
|
+
Resource.parse paginate(uri, params)
|
199
190
|
end
|
191
|
+
end
|
200
192
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
193
|
+
# Define a method to get one resource by it's id number, with optional
|
194
|
+
# params, thought now that I think about it I'm not sure why you'd pass
|
195
|
+
# params when grabbing just one resource.
|
196
|
+
|
197
|
+
# Some resources are Singletons
|
198
|
+
unless singular.nil?
|
199
|
+
define_method("get_#{singular}") do |*args|
|
200
|
+
case args.size
|
201
|
+
when 0
|
202
|
+
Resource.parse request(:get, "#{resource_uri}", nil)
|
203
|
+
when 1
|
204
|
+
Resource.parse request(:get, "#{resource_uri}/#{args[0]}", nil)
|
205
|
+
when 2
|
206
|
+
Resource.parse request(:get, "#{resource_uri}/#{args[0]}#{RequestParams.parameterize(args[1])}", nil)
|
207
|
+
else
|
208
|
+
raise ArgumentError.new("wrong number for arguments (#{args.count} for 1..2)")
|
218
209
|
end
|
219
210
|
end
|
211
|
+
end
|
220
212
|
|
221
|
-
|
213
|
+
when 'add'
|
222
214
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
end
|
215
|
+
# Define a method to add a new resource to the account
|
216
|
+
define_method("add_#{singular}") do |properties|
|
217
|
+
if properties.class == LMRest::Resource
|
218
|
+
Resource.parse request(:post, "#{resource_uri}", properties.to_h)
|
219
|
+
else
|
220
|
+
Resource.parse request(:post, "#{resource_uri}", properties)
|
230
221
|
end
|
222
|
+
end
|
231
223
|
|
232
|
-
|
224
|
+
when 'update'
|
233
225
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
end
|
226
|
+
# Define a method to update a resource
|
227
|
+
define_method("update_#{singular}") do |id, properties = {}|
|
228
|
+
if id.class == LMRest::Resource
|
229
|
+
Resource.parse request(:put, "#{resource_uri}/#{id.id}", id.to_h)
|
230
|
+
else
|
231
|
+
Resource.parse request(:put, "#{resource_uri}/#{id}", properties)
|
241
232
|
end
|
233
|
+
end
|
242
234
|
|
243
|
-
|
235
|
+
when 'delete'
|
244
236
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
end
|
237
|
+
# Define a method to delete the resource
|
238
|
+
define_method("delete_#{singular}") do |id|
|
239
|
+
if id.class == LMRest::Resource
|
240
|
+
id = id.id
|
241
|
+
Resource.parse request(:delete, "#{resource_uri}/#{id}", nil)
|
242
|
+
else
|
243
|
+
Resource.parse request(:delete, "#{resource_uri}/#{id}", nil)
|
253
244
|
end
|
254
245
|
end
|
255
246
|
end
|
data/lib/lm_rest/version.rb
CHANGED