haveapi-client 0.9.0 → 0.10.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 +4 -4
- data/CHANGELOG +7 -0
- data/haveapi-client.gemspec +3 -3
- data/lib/haveapi/cli/cli.rb +10 -8
- data/lib/haveapi/client/action.rb +10 -4
- data/lib/haveapi/client/authentication/basic.rb +3 -0
- data/lib/haveapi/client/authentication/token.rb +27 -0
- data/lib/haveapi/client/client.rb +5 -0
- data/lib/haveapi/client/communicator.rb +4 -3
- data/lib/haveapi/client/resource.rb +1 -1
- data/lib/haveapi/client/response.rb +1 -1
- data/lib/haveapi/client/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d38285efbe924232434c9d4bdf0ece969eb8c36f
|
4
|
+
data.tar.gz: 185865048fd39008b57baa63a67f5a105de3ad24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/haveapi-client.gemspec
CHANGED
@@ -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-
|
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', '
|
26
|
-
spec.add_runtime_dependency 'require_all'
|
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'
|
data/lib/haveapi/cli/cli.rb
CHANGED
@@ -307,15 +307,17 @@ module HaveAPI::CLI
|
|
307
307
|
@action_opt = OptionParser.new do |opts|
|
308
308
|
opts.banner = ''
|
309
309
|
|
310
|
-
action.input
|
311
|
-
|
312
|
-
|
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
|
-
|
315
|
-
|
315
|
+
if arg.nil?
|
316
|
+
options[name] = read_param(name, p)
|
316
317
|
|
317
|
-
|
318
|
-
|
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
|
-
|
16
|
+
args = [self]
|
17
17
|
|
18
|
-
|
19
|
-
|
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(
|
28
|
+
ret = @api.call(*args)
|
23
29
|
reset
|
24
30
|
ret
|
25
31
|
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 = {
|
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.
|
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
|
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.
|
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-
|
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.
|
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.
|
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:
|
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:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rest-client
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|