haveapi-client 0.14.2 → 0.16.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9bcb523f6bbbc83aed043d934bed405204f944da508ce27bbbc187789ad2592
4
- data.tar.gz: 577821fa05de46f248506925c8d2b50a2da7a6d21dd16f463b0cb6d4873f4c5b
3
+ metadata.gz: d153eb905ee73a1f0764da87f536881490f9d590219269fca5f365c532d1d726
4
+ data.tar.gz: 970bc24468ff7dc99d77454bad8770006ef87f8fd91ecc910021833ac5c04e21
5
5
  SHA512:
6
- metadata.gz: 9985388b53763b4ce873c02b113c9e3b3577ebf7328993acca91cdbdaee0025a865fb4b7feb65dd55b774c98c5f88d475a8c532c2c94b0d1dfccb72862ef0526
7
- data.tar.gz: '0835beabb9c0212930238f502c4f2d2c314321dc1ba080c13e2bcd68261a05053ad74cdd4a9a29d2c4b3707b907610a9f4a517e5458d8ee2f77e5692ec2d0134'
6
+ metadata.gz: 74b9c5de5ad215533b1c1ceeed8044f19367eb06b18d67d9d9460901701e12525ec8c47d461d99cd593c8188c03c8598f7a72405d1de2818903fe35554d69af3
7
+ data.tar.gz: 1a907240d3323af2830b9b03586d7de2244e8bf695c6700905c8012dcaa107672aa4b65f0597abc35c03d3778d91e65f8a59660d9ebe5391e99fc01520b6b93f
@@ -395,7 +395,7 @@ module HaveAPI::CLI
395
395
  def list_resources(v=nil)
396
396
  desc = @api.describe_api(v)
397
397
 
398
- desc[:resources].each do |resource, children|
398
+ sort_by_key(desc[:resources]).each do |resource, children|
399
399
  nested_resource(resource, children, false)
400
400
  end
401
401
  end
@@ -403,7 +403,7 @@ module HaveAPI::CLI
403
403
  def list_actions(v=nil)
404
404
  desc = @api.describe_api(v)
405
405
 
406
- desc[:resources].each do |resource, children|
406
+ sort_by_key(desc[:resources]).each do |resource, children|
407
407
  nested_resource(resource, children, true)
408
408
  end
409
409
  end
@@ -443,7 +443,7 @@ module HaveAPI::CLI
443
443
  unless desc[:resources].empty?
444
444
  puts 'Resources:'
445
445
 
446
- desc[:resources].each_key do |r|
446
+ desc[:resources].keys.sort.each do |r|
447
447
  puts " #{r}"
448
448
  end
449
449
  end
@@ -453,7 +453,7 @@ module HaveAPI::CLI
453
453
  unless desc[:actions].empty?
454
454
  puts 'Actions:'
455
455
 
456
- desc[:actions].each_key do |a|
456
+ desc[:actions].keys.sort.each do |a|
457
457
  puts " #{a}"
458
458
  end
459
459
  end
@@ -461,14 +461,14 @@ module HaveAPI::CLI
461
461
 
462
462
  def nested_resource(prefix, children, actions=false)
463
463
  if actions
464
- children[:actions].each do |action, _|
464
+ children[:actions].keys.sort.each do |action|
465
465
  puts "#{prefix}##{action}"
466
466
  end
467
467
  else
468
468
  puts prefix
469
469
  end
470
470
 
471
- children[:resources].each do |resource, children|
471
+ sort_by_key(children[:resources]).each do |resource, children|
472
472
  nested_resource("#{prefix}.#{resource}", children, actions)
473
473
  end
474
474
  end
@@ -743,5 +743,11 @@ module HaveAPI::CLI
743
743
 
744
744
  @opts[:date_format] ? ret.strftime(@opts[:date_format]) : ret
745
745
  end
746
+
747
+ def sort_by_key(hash)
748
+ hash.sort do |a, b|
749
+ a[0]<=> b[0]
750
+ end
751
+ end
746
752
  end
747
753
  end
@@ -12,7 +12,7 @@ module HaveAPI::Client
12
12
  apply_args(args)
13
13
  end
14
14
 
15
- def execute(data, *_)
15
+ def execute(data, raw: false)
16
16
  params_arg = {}
17
17
 
18
18
  if input
@@ -25,7 +25,7 @@ module HaveAPI::Client
25
25
  params_arg = params.to_api
26
26
  end
27
27
 
28
- ret = @api.call(self, params_arg)
28
+ ret = @api.call(self, params_arg, raw: raw)
29
29
  reset
30
30
  ret
31
31
  end
@@ -49,8 +49,8 @@ class HaveAPI::Client::Client
49
49
  end
50
50
 
51
51
  # See Communicator#authenticate.
52
- def authenticate(*args, &block)
53
- @api.authenticate(*args, &block)
52
+ def authenticate(auth_method, **options, &block)
53
+ @api.authenticate(auth_method, options, &block)
54
54
  end
55
55
 
56
56
  # Get uthentication provider
@@ -76,7 +76,7 @@ module HaveAPI::Client
76
76
  action.aliases(true).each do |name|
77
77
  next unless define_method?(action, name)
78
78
 
79
- define_singleton_method(name) do |*args, &block|
79
+ define_singleton_method(name) do |*args, **kwargs, &block|
80
80
  client_opts = @client.opts(:block, :block_interval, :block_timeout)
81
81
  all_args = @prepared_args + args
82
82
 
@@ -89,28 +89,42 @@ module HaveAPI::Client
89
89
  end
90
90
 
91
91
  if action.unresolved_args?
92
- raise ArgumentError.new('One or more object ids missing')
92
+ raise ArgumentError, 'one or more object ids missing'
93
93
  end
94
94
  end
95
95
 
96
- if all_args.empty?
97
- all_args << default_action_input_params(action)
96
+ if all_args.length > 1 || (kwargs.any? && all_args.any?)
97
+ raise ArgumentError, "too many arguments for action #{@name}##{action.name}"
98
+ end
99
+
100
+ arg = all_args.shift
98
101
 
99
- elsif all_args.last.is_a?(Hash)
100
- last = all_args.pop
102
+ user_params =
103
+ if kwargs.any? && arg
104
+ raise ArgumentError,
105
+ 'pass the input parameters either as a hash or keyword arguments'
106
+ elsif kwargs.any?
107
+ kwargs
108
+ elsif arg
109
+ arg
110
+ end
101
111
 
102
- if last.has_key?(:meta)
103
- meta = last[:meta]
112
+ if user_params.nil?
113
+ input_params = default_action_input_params(action)
114
+
115
+ else
116
+ if user_params.has_key?(:meta)
117
+ meta = user_params[:meta]
104
118
 
105
119
  %i(block block_interval block_timeout).each do |p|
106
120
  client_opts[p] = meta.delete(p) if meta.has_key?(p)
107
121
  end
108
122
  end
109
123
 
110
- all_args << default_action_input_params(action).update(last)
124
+ input_params = default_action_input_params(action).update(user_params)
111
125
  end
112
126
 
113
- ret = Response.new(action, action.execute(*all_args))
127
+ ret = Response.new(action, action.execute(input_params))
114
128
 
115
129
  raise ActionFailed.new(ret) unless ret.ok?
116
130
 
@@ -137,8 +151,8 @@ module HaveAPI::Client
137
151
  }.each do |k, v|
138
152
  wait_opts[v] = client_opts[k] if client_opts.has_key?(k)
139
153
  end
140
-
141
- ret.wait_for_completion(wait_opts) do |state|
154
+
155
+ ret.wait_for_completion(**wait_opts) do |state|
142
156
  block.call(return_value, state) if block
143
157
  end
144
158
  end
@@ -61,10 +61,10 @@ class HaveAPI::Client::Response
61
61
  # it is regularly called with the action's state.
62
62
  #
63
63
  # @see HaveAPI::Client::Action#wait_for_completion
64
- def wait_for_completion(*args, &block)
64
+ def wait_for_completion(**kwargs, &block)
65
65
  id = meta[:action_state_id]
66
66
  return nil unless id
67
67
 
68
- HaveAPI::Client::Action.wait_for_completion(@action.client, id, *args, &block)
68
+ HaveAPI::Client::Action.wait_for_completion(@action.client, id, **kwargs, &block)
69
69
  end
70
70
  end
@@ -1,6 +1,6 @@
1
1
  module HaveAPI
2
2
  module Client
3
3
  PROTOCOL_VERSION = '2.0'
4
- VERSION = '0.14.2'
4
+ VERSION = '0.16.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan