haveapi-client 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9bcb523f6bbbc83aed043d934bed405204f944da508ce27bbbc187789ad2592
4
- data.tar.gz: 577821fa05de46f248506925c8d2b50a2da7a6d21dd16f463b0cb6d4873f4c5b
3
+ metadata.gz: 4ab49346d0209df996a1832992ad1f11bf7bb2f7de6f1f7cd49fb92e4bbc62c0
4
+ data.tar.gz: a49dc688a464d90e4188d93abcda7d27f252f0c4d44ce7769fb773b68b08e11b
5
5
  SHA512:
6
- metadata.gz: 9985388b53763b4ce873c02b113c9e3b3577ebf7328993acca91cdbdaee0025a865fb4b7feb65dd55b774c98c5f88d475a8c532c2c94b0d1dfccb72862ef0526
7
- data.tar.gz: '0835beabb9c0212930238f502c4f2d2c314321dc1ba080c13e2bcd68261a05053ad74cdd4a9a29d2c4b3707b907610a9f4a517e5458d8ee2f77e5692ec2d0134'
6
+ metadata.gz: b39a2abebdc41d1480c2cba71ff4440ac320532c1d22885d92aba8d383f3e9e4d2a055114821c76322f90d1c0d135c5233b80f95a3ac366483a8ee6fa6577756
7
+ data.tar.gz: 768c5ec61c25e4dcfbc99f79f0a788d2237789e8316065fecc766fe60b832852609954ee1bf2c21256aa80116f901aef55314825e4fb42df23c69cbf84dab7d0
@@ -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)
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, **{})
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.15.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.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan