haveapi-client 0.1.0 → 0.1.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/lib/haveapi/cli/cli.rb +48 -9
- data/lib/haveapi/client/communicator.rb +13 -0
- data/lib/haveapi/client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2450bb773a086b4732b000238a127e2b86bb3123
|
4
|
+
data.tar.gz: 5749b665304e4a2d40f4104189404a31a666c000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2ce5925416ee00884e332ef48b75a72830b09df905c3d32afabf811913bde41db355baf23faeb4061f63dd2ce006cc869a43081c3493bef1c39867ba103155
|
7
|
+
data.tar.gz: a703d0faed80a693d95906aae8d17030b7f135d41cbc16f9a0212d7c2db8c148968114d57ea1eeaa5e903497d6a20b68275ce8109da5b377eaa57521138751e4
|
data/lib/haveapi/cli/cli.rb
CHANGED
@@ -19,12 +19,20 @@ module HaveAPI
|
|
19
19
|
exit
|
20
20
|
end
|
21
21
|
|
22
|
-
if @opts[:help] || args.empty?
|
22
|
+
if (@opts[:help] && args.empty?) || args.empty?
|
23
23
|
puts @global_opt.help
|
24
|
+
puts "\nAvailable resources:"
|
25
|
+
list_resources
|
24
26
|
exit(true)
|
25
27
|
end
|
26
28
|
|
27
29
|
resources = args[0].split('.')
|
30
|
+
|
31
|
+
if args.count == 1
|
32
|
+
describe_resource(resources)
|
33
|
+
exit(true)
|
34
|
+
end
|
35
|
+
|
28
36
|
action = translate_action(args[1].to_sym)
|
29
37
|
|
30
38
|
action = @api.get_action(resources, action, args[2..-1])
|
@@ -78,12 +86,12 @@ module HaveAPI
|
|
78
86
|
@action = [:list_versions]
|
79
87
|
end
|
80
88
|
|
81
|
-
opts.on('--list-resources VERSION', 'List all resource in API version') do |v|
|
82
|
-
@action = [:list_resources, v.sub(/^v/, '')]
|
89
|
+
opts.on('--list-resources [VERSION]', 'List all resource in API version') do |v|
|
90
|
+
@action = [:list_resources, v && v.sub(/^v/, '')]
|
83
91
|
end
|
84
92
|
|
85
|
-
opts.on('--list-actions VERSION', 'List all resources and actions in API version') do |v|
|
86
|
-
@action = [:list_actions, v.sub(/^v/, '')]
|
93
|
+
opts.on('--list-actions [VERSION]', 'List all resources and actions in API version') do |v|
|
94
|
+
@action = [:list_actions, v && v.sub(/^v/, '')]
|
87
95
|
end
|
88
96
|
|
89
97
|
opts.on('-r', '--raw', 'Print raw response as is') do
|
@@ -198,18 +206,49 @@ module HaveAPI
|
|
198
206
|
end
|
199
207
|
end
|
200
208
|
|
201
|
-
def list_resources(v)
|
202
|
-
@api.describe_api
|
209
|
+
def list_resources(v=nil)
|
210
|
+
desc = @api.describe_api
|
211
|
+
|
212
|
+
desc[:versions][v || desc[:default_version].to_s.to_sym][:resources].each do |resource, children|
|
203
213
|
nested_resource(resource, children, false)
|
204
214
|
end
|
205
215
|
end
|
206
216
|
|
207
|
-
def list_actions(v)
|
208
|
-
@api.describe_api
|
217
|
+
def list_actions(v=nil)
|
218
|
+
desc = @api.describe_api
|
219
|
+
|
220
|
+
desc[:versions][v || desc[:default_version].to_s.to_sym][:resources].each do |resource, children|
|
209
221
|
nested_resource(resource, children, true)
|
210
222
|
end
|
211
223
|
end
|
212
224
|
|
225
|
+
def describe_resource(path)
|
226
|
+
desc = @api.describe_resource(path)
|
227
|
+
|
228
|
+
unless desc
|
229
|
+
warn "Resource #{path.join('.')} does not exist"
|
230
|
+
exit(false)
|
231
|
+
end
|
232
|
+
|
233
|
+
unless desc[:resources].empty?
|
234
|
+
puts 'Resources:'
|
235
|
+
|
236
|
+
desc[:resources].each_key do |r|
|
237
|
+
puts " #{r}"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
puts '' if !desc[:resources].empty? && !desc[:actions].empty?
|
242
|
+
|
243
|
+
unless desc[:actions].empty?
|
244
|
+
puts 'Actions:'
|
245
|
+
|
246
|
+
desc[:actions].each_key do |a|
|
247
|
+
puts " #{a}"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
213
252
|
def nested_resource(prefix, children, actions=false)
|
214
253
|
if actions
|
215
254
|
children[:actions].each do |action, _|
|
@@ -21,6 +21,19 @@ module HaveAPI
|
|
21
21
|
description_for(path_for(v))
|
22
22
|
end
|
23
23
|
|
24
|
+
def describe_resource(path)
|
25
|
+
api = describe_api
|
26
|
+
tmp = describe_api[:versions][ describe_api[:default_version].to_s.to_sym ]
|
27
|
+
|
28
|
+
path.each do |r|
|
29
|
+
tmp = tmp[:resources][r.to_sym]
|
30
|
+
|
31
|
+
return false unless tmp
|
32
|
+
end
|
33
|
+
|
34
|
+
tmp
|
35
|
+
end
|
36
|
+
|
24
37
|
def describe_action(v, r)
|
25
38
|
|
26
39
|
end
|