haveapi 0.16.3 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/haveapi.gemspec +5 -5
- data/lib/haveapi/client_example.rb +23 -0
- data/lib/haveapi/client_examples/curl.rb +2 -2
- data/lib/haveapi/client_examples/http.rb +3 -1
- data/lib/haveapi/client_examples/js_client.rb +2 -3
- data/lib/haveapi/client_examples/php_client.rb +2 -2
- data/lib/haveapi/client_examples/ruby_cli.rb +3 -3
- data/lib/haveapi/client_examples/ruby_client.rb +2 -2
- data/lib/haveapi/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4799af18ce8de3147686153493e32210e780c650bdcec3e18f5ff714da50ee03
|
4
|
+
data.tar.gz: 4cfe8ff071d7d4ea6adcb28e25ab0d491008e9402058c34293bdf70881bf13e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936f0c86ff2b766339c3dbc08d49c2ae46868002733124dad9987ad932f9232807160a6a36777fc6fe45b952682e89bf9b0a5856939d6a7a1775e94e9d8ffe4c
|
7
|
+
data.tar.gz: 3527985845485151a532aa42ce235eed35827f8d9f6a2aa053b208e7621ce4d93f578cd531f06aec8bcc27ecd1079c8023b7fc63f29bf36d4b6e38807121f0f6
|
data/haveapi.gemspec
CHANGED
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_runtime_dependency 'require_all', '~> 2.0.0'
|
18
18
|
s.add_runtime_dependency 'json'
|
19
|
-
s.add_runtime_dependency 'activesupport', '>=
|
20
|
-
s.add_runtime_dependency 'sinatra', '~> 3.0
|
21
|
-
s.add_runtime_dependency 'tilt', '~> 2.0
|
22
|
-
s.add_runtime_dependency 'redcarpet', '~> 3.
|
19
|
+
s.add_runtime_dependency 'activesupport', '>= 7.0'
|
20
|
+
s.add_runtime_dependency 'sinatra', '~> 3.1.0'
|
21
|
+
s.add_runtime_dependency 'tilt', '~> 2.3.0'
|
22
|
+
s.add_runtime_dependency 'redcarpet', '~> 3.6'
|
23
23
|
s.add_runtime_dependency 'rake'
|
24
24
|
s.add_runtime_dependency 'github-markdown'
|
25
25
|
s.add_runtime_dependency 'nesty', '~> 1.0'
|
26
|
-
s.add_runtime_dependency 'haveapi-client', '~> 0.
|
26
|
+
s.add_runtime_dependency 'haveapi-client', '~> 0.17.0'
|
27
27
|
s.add_runtime_dependency 'mail'
|
28
28
|
end
|
@@ -79,5 +79,28 @@ module HaveAPI
|
|
79
79
|
def version_url
|
80
80
|
File.join(base_url, "v#{version}", '/')
|
81
81
|
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
# @param password [Boolean] include password parameter
|
85
|
+
# @return [Hash<String, String>] parameter => example value
|
86
|
+
def auth_token_credentials(desc, password: true)
|
87
|
+
passwords = %i(password pass passwd)
|
88
|
+
params = desc[:resources][:token][:actions]['request'][:input][:parameters].keys - %i(lifetime interval)
|
89
|
+
|
90
|
+
unless password
|
91
|
+
params.reject! { |param| passwords.include?(param) }
|
92
|
+
end
|
93
|
+
|
94
|
+
Hash[params.map do |param|
|
95
|
+
value =
|
96
|
+
if passwords.include?(param)
|
97
|
+
'secret'
|
98
|
+
else
|
99
|
+
param
|
100
|
+
end
|
101
|
+
|
102
|
+
[param, value]
|
103
|
+
end]
|
104
|
+
end
|
82
105
|
end
|
83
106
|
end
|
@@ -12,8 +12,6 @@ module HaveAPI::ClientExamples
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def auth(method, desc)
|
15
|
-
login = {user: 'user', password: 'password', lifetime: 'fixed'}
|
16
|
-
|
17
15
|
case method
|
18
16
|
when :basic
|
19
17
|
<<END
|
@@ -30,6 +28,8 @@ $ curl --request OPTIONS \\
|
|
30
28
|
END
|
31
29
|
|
32
30
|
when :token
|
31
|
+
login = auth_token_credentials(desc).merge(lifetime: 'fixed')
|
32
|
+
|
33
33
|
<<END
|
34
34
|
# Acquire the token
|
35
35
|
$ curl --request POST \\
|
@@ -28,12 +28,14 @@ Authorization: Basic dXNlcjpzZWNyZXQ=
|
|
28
28
|
END
|
29
29
|
|
30
30
|
when :token
|
31
|
+
login = auth_token_credentials(desc).merge(lifetime: 'fixed')
|
32
|
+
|
31
33
|
<<END
|
32
34
|
POST /_auth/token/tokens HTTP/1.1
|
33
35
|
Host: #{host}
|
34
36
|
Content-Type: application/json
|
35
37
|
|
36
|
-
#{JSON.pretty_generate({token:
|
38
|
+
#{JSON.pretty_generate({token: login})}
|
37
39
|
END
|
38
40
|
end
|
39
41
|
end
|
@@ -21,7 +21,7 @@ END
|
|
21
21
|
#{init}
|
22
22
|
|
23
23
|
api.authenticate("basic", {
|
24
|
-
|
24
|
+
user: "user",
|
25
25
|
password: "secret"
|
26
26
|
}, function (client, status) {
|
27
27
|
console.log("Authenticated?", status);
|
@@ -34,8 +34,7 @@ END
|
|
34
34
|
|
35
35
|
// Request a new token
|
36
36
|
api.authenticate("token", {
|
37
|
-
|
38
|
-
password: "secret"
|
37
|
+
#{auth_token_credentials(desc).map { |k, v| "#{k}: \"#{v}\"" }.join(",\n ")}
|
39
38
|
}, function (client, status) {
|
40
39
|
console.log("Authenticated?", status);
|
41
40
|
|
@@ -18,7 +18,7 @@ END
|
|
18
18
|
<<END
|
19
19
|
#{init}
|
20
20
|
|
21
|
-
$api->authenticate("basic", ["
|
21
|
+
$api->authenticate("basic", ["user" => "user", "password" => "secret"]);
|
22
22
|
END
|
23
23
|
|
24
24
|
when :token
|
@@ -26,7 +26,7 @@ END
|
|
26
26
|
#{init}
|
27
27
|
|
28
28
|
// Get token using username and password
|
29
|
-
$api->authenticate("token", [
|
29
|
+
$api->authenticate("token", [#{auth_token_credentials(desc).map { |k, v| "\"#{k}\" => \"#{v}\"" }.join(', ')}]);
|
30
30
|
|
31
31
|
echo "Token = ".$api->getAuthenticationProvider()->getToken();
|
32
32
|
|
@@ -20,10 +20,10 @@ module HaveAPI::ClientExamples
|
|
20
20
|
when :basic
|
21
21
|
<<END
|
22
22
|
# Provide credentials on command line
|
23
|
-
#{init} --auth basic --
|
23
|
+
#{init} --auth basic --user user --password secret
|
24
24
|
|
25
25
|
# If username or password isn't provided, the user is asked on stdin
|
26
|
-
#{init} --auth basic --
|
26
|
+
#{init} --auth basic --user user
|
27
27
|
Password: secret
|
28
28
|
END
|
29
29
|
|
@@ -33,7 +33,7 @@ END
|
|
33
33
|
# Note that the client always has to call some action. APIs should provide
|
34
34
|
# an action to get information about the current user, so that's what we're
|
35
35
|
# calling now.
|
36
|
-
#{init} --auth token
|
36
|
+
#{init} --auth token #{auth_token_credentials(desc, password: false).map { |k, v| "--#{k} #{v}" }.join(' ')} --save user current
|
37
37
|
Password: secret
|
38
38
|
|
39
39
|
# Now the token is read from disk and the user does not have to provide username
|
@@ -21,7 +21,7 @@ END
|
|
21
21
|
<<END
|
22
22
|
#{init}
|
23
23
|
|
24
|
-
client.authenticate(:basic,
|
24
|
+
client.authenticate(:basic, user: "user", password: "secret")
|
25
25
|
END
|
26
26
|
|
27
27
|
when :token
|
@@ -29,7 +29,7 @@ END
|
|
29
29
|
#{init}
|
30
30
|
|
31
31
|
# Get token using username and password
|
32
|
-
client.authenticate(:token,
|
32
|
+
client.authenticate(:token, #{auth_token_credentials(desc).map { |k, v| "#{k}: \"#{v}\"" }.join(', ')})
|
33
33
|
|
34
34
|
puts "Token = \#{client.auth.token}"
|
35
35
|
|
data/lib/haveapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haveapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Skokan
|
@@ -44,56 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '7.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: '
|
54
|
+
version: '7.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sinatra
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0
|
61
|
+
version: 3.1.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: 3.0
|
68
|
+
version: 3.1.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: tilt
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0
|
75
|
+
version: 2.3.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0
|
82
|
+
version: 2.3.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: redcarpet
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.6'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.6'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.17.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.17.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: mail
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -315,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
315
315
|
- !ruby/object:Gem::Version
|
316
316
|
version: '0'
|
317
317
|
requirements: []
|
318
|
-
rubygems_version: 3.
|
318
|
+
rubygems_version: 3.4.13
|
319
319
|
signing_key:
|
320
320
|
specification_version: 4
|
321
321
|
summary: Framework for creating self-describing APIs
|