haveapi-client 0.9.0 → 0.10.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
  SHA1:
3
- metadata.gz: 3ba1c7ae5a2334ed6d530c44443334b36024154e
4
- data.tar.gz: e1467467e046d68d8d615628bae42ae4071bd05a
3
+ metadata.gz: d38285efbe924232434c9d4bdf0ece969eb8c36f
4
+ data.tar.gz: 185865048fd39008b57baa63a67f5a105de3ad24
5
5
  SHA512:
6
- metadata.gz: a3691d90ceb3e86b50747e6d53611a23992fd6d7c5a8c973d49c9949e09296f6874d4e353c29fdafd5b76ede2d50f7dc2725e9f7964176452f4920cdd0ee6045
7
- data.tar.gz: 4dbffe7e183ceb67ef494e51b46068f9e3e169b34a5088206e86e64c45f26d49033c4055fa10a59b4fe5fdd04a91d808d594630ae3d84ad62f43c54514f004a5
6
+ metadata.gz: 8124895cf8f6387235cee2f4c11ec6e539d14cdaf0519fd3fcce7981bf7b9e83720b93d2b242dde66d5b4191c33ea52c2b97cd60a2c005aab3591f0e21126165
7
+ data.tar.gz: a6653cabef8e918dcafe4216e7aa2482014a1ecd569fead986d994ad28d97206e2b09de3a62a8997b8370b01d1e2cd07a05388c781da799254e08688bff36738
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ * Tue Sep 12 2017 - version 0.10.0
2
+ - Client: accessor to communicator object
3
+ - Basic authentication: add accessors to credentials
4
+ - Token authentication: support for token renewal and revoking
5
+ - Compatibility with Elixir server API
6
+ - Relax dependency version requirements
7
+
1
8
  * Sat Apr 22 2017 - version 0.9.0
2
9
  - Resource.setup_from_clone: set also @description
3
10
 
@@ -6,7 +6,7 @@ require 'haveapi/client/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'haveapi-client'
8
8
  spec.version = HaveAPI::Client::VERSION
9
- spec.date = '2017-04-22'
9
+ spec.date = '2017-09-12'
10
10
  spec.authors = ['Jakub Skokan']
11
11
  spec.email = ['jakub.skokan@vpsfree.cz']
12
12
  spec.summary =
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'bundler', '~> 1.6'
23
23
  spec.add_development_dependency 'rake'
24
24
 
25
- spec.add_runtime_dependency 'activesupport', '~> 4.1.14'
26
- spec.add_runtime_dependency 'require_all', '~> 1.3.3'
25
+ spec.add_runtime_dependency 'activesupport', '>= 4.0'
26
+ spec.add_runtime_dependency 'require_all'
27
27
  spec.add_runtime_dependency 'rest-client', '~> 1.8.0'
28
28
  spec.add_runtime_dependency 'json'
29
29
  spec.add_runtime_dependency 'highline', '~> 1.7.8'
@@ -307,15 +307,17 @@ module HaveAPI::CLI
307
307
  @action_opt = OptionParser.new do |opts|
308
308
  opts.banner = ''
309
309
 
310
- action.input[:parameters].each do |name, p|
311
- opts.on(param_option(name, p), p[:description] || p[:label] || '') do |*args|
312
- arg = args.first
310
+ if action.input
311
+ action.input[:parameters].each do |name, p|
312
+ opts.on(param_option(name, p), p[:description] || p[:label] || ' ') do |*args|
313
+ arg = args.first
313
314
 
314
- if arg.nil?
315
- options[name] = read_param(name, p)
315
+ if arg.nil?
316
+ options[name] = read_param(name, p)
316
317
 
317
- else
318
- options[name] = args.first
318
+ else
319
+ options[name] = args.first
320
+ end
319
321
  end
320
322
  end
321
323
  end
@@ -510,7 +512,7 @@ module HaveAPI::CLI
510
512
  return
511
513
  end
512
514
 
513
- return if response.empty?
515
+ return if response.empty? || action.output.nil?
514
516
 
515
517
  namespace = action.namespace(:output).to_sym
516
518
 
@@ -13,13 +13,19 @@ module HaveAPI::Client
13
13
  end
14
14
 
15
15
  def execute(data, *_)
16
- params = Params.new(self, data)
16
+ args = [self]
17
17
 
18
- unless params.valid?
19
- raise ValidationError.new(self, params.errors)
18
+ if input
19
+ params = Params.new(self, data)
20
+
21
+ unless params.valid?
22
+ raise ValidationError.new(self, params.errors)
23
+ end
24
+
25
+ args << params.to_api << {}
20
26
  end
21
27
 
22
- ret = @api.call(self, params.to_api)
28
+ ret = @api.call(*args)
23
29
  reset
24
30
  ret
25
31
  end
@@ -5,5 +5,8 @@ module HaveAPI::Client::Authentication
5
5
  def resource
6
6
  RestClient::Resource.new(@communicator.url, @opts[:user], @opts[:password])
7
7
  end
8
+
9
+ def user ; @opts[:user] ; end
10
+ def password ; @opts[:password] ; end
8
11
  end
9
12
  end
@@ -34,6 +34,33 @@ module HaveAPI::Client::Authentication
34
34
  @valid_to = hash[:valid_to]
35
35
  end
36
36
 
37
+ def renew
38
+ a = HaveAPI::Client::Action.new(
39
+ nil,
40
+ @communicator,
41
+ :renew,
42
+ @desc[:resources][:token][:actions][:renew],
43
+ []
44
+ )
45
+ ret = HaveAPI::Client::Response.new(a, a.execute({}))
46
+ raise HaveAPI::Client::ActionFailed.new(ret) unless ret.ok?
47
+
48
+ @valid_to = ret[:valid_to]
49
+ @valid_to = @valid_to && DateTime.iso8601(@valid_to).to_time
50
+ end
51
+
52
+ def revoke
53
+ a = HaveAPI::Client::Action.new(
54
+ nil,
55
+ @communicator,
56
+ :revoke,
57
+ @desc[:resources][:token][:actions][:revoke],
58
+ []
59
+ )
60
+ ret = HaveAPI::Client::Response.new(a, a.execute({}))
61
+ raise HaveAPI::Client::ActionFailed.new(ret) unless ret.ok?
62
+ end
63
+
37
64
  protected
38
65
  def request_token
39
66
  a = HaveAPI::Client::Action.new(
@@ -81,6 +81,11 @@ class HaveAPI::Client::Client
81
81
  keys.empty? ? @opts.clone : @opts.select { |k, _| keys.include?(k) }
82
82
  end
83
83
 
84
+ # @return [HaveAPI::Client::Communicator]
85
+ def communicator
86
+ @api
87
+ end
88
+
84
89
  # Initialize the client if it is not yet initialized and call the resource
85
90
  # if it exists.
86
91
  def method_missing(symbol, *args)
@@ -105,9 +105,9 @@ module HaveAPI::Client
105
105
  end
106
106
  end
107
107
 
108
- def call(action, params, raw: false)
108
+ def call(action, params = {}, raw: false)
109
109
  args = []
110
- input_namespace = action.namespace(:input)
110
+ input_namespace = action.input && action.namespace(:input)
111
111
  meta = nil
112
112
 
113
113
  if params.is_a?(Hash) && params[:meta]
@@ -116,7 +116,8 @@ module HaveAPI::Client
116
116
  end
117
117
 
118
118
  if %w(POST PUT).include?(action.http_method)
119
- ns = {input_namespace => params}
119
+ ns = {}
120
+ ns[input_namespace] = params if input_namespace
120
121
  ns[:_meta] = meta if meta
121
122
  ns.update(@auth.request_payload)
122
123
 
@@ -114,7 +114,7 @@ module HaveAPI::Client
114
114
 
115
115
  raise ActionFailed.new(ret) unless ret.ok?
116
116
 
117
- return_value = case action.output_layout
117
+ return_value = case action.output && action.output_layout
118
118
  when :object
119
119
  ResourceInstance.new(@client, @api, self, action: action, response: ret)
120
120
 
@@ -44,7 +44,7 @@ class HaveAPI::Client::Response
44
44
 
45
45
  # Access namespaced params directly.
46
46
  def [](key)
47
- return unless %i(object hash).include?(@action.layout.to_sym)
47
+ return unless %i(object hash).include?(@action.output_layout.to_sym)
48
48
 
49
49
  @response[:response][@action.namespace(:output).to_sym][key]
50
50
  end
@@ -1,6 +1,6 @@
1
1
  module HaveAPI
2
2
  module Client
3
3
  PROTOCOL_VERSION = '1.2'
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.1.14
47
+ version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 4.1.14
54
+ version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: require_all
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.3
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.3
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement