haveapi 0.18.2 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/haveapi.gemspec +2 -1
  3. data/lib/haveapi/action.rb +72 -31
  4. data/lib/haveapi/authentication/base.rb +1 -1
  5. data/lib/haveapi/authentication/basic/provider.rb +2 -2
  6. data/lib/haveapi/authentication/chain.rb +4 -4
  7. data/lib/haveapi/authentication/oauth2/config.rb +52 -14
  8. data/lib/haveapi/authentication/oauth2/provider.rb +98 -17
  9. data/lib/haveapi/authentication/oauth2/revoke_endpoint.rb +36 -0
  10. data/lib/haveapi/authentication/token/config.rb +1 -0
  11. data/lib/haveapi/authorization.rb +19 -12
  12. data/lib/haveapi/client_examples/js_client.rb +11 -1
  13. data/lib/haveapi/client_examples/php_client.rb +43 -1
  14. data/lib/haveapi/context.rb +21 -2
  15. data/lib/haveapi/example.rb +9 -9
  16. data/lib/haveapi/hooks.rb +23 -23
  17. data/lib/haveapi/metadata.rb +1 -1
  18. data/lib/haveapi/model_adapter.rb +14 -14
  19. data/lib/haveapi/model_adapters/active_record.rb +20 -20
  20. data/lib/haveapi/output_formatter.rb +4 -4
  21. data/lib/haveapi/output_formatters/base.rb +1 -1
  22. data/lib/haveapi/parameters/resource.rb +22 -22
  23. data/lib/haveapi/parameters/typed.rb +7 -7
  24. data/lib/haveapi/params.rb +24 -22
  25. data/lib/haveapi/resource.rb +9 -3
  26. data/lib/haveapi/resources/action_state.rb +16 -16
  27. data/lib/haveapi/route.rb +3 -2
  28. data/lib/haveapi/server.rb +113 -98
  29. data/lib/haveapi/spec/mock_action.rb +7 -7
  30. data/lib/haveapi/spec/spec_methods.rb +8 -8
  31. data/lib/haveapi/tasks/yard.rb +2 -2
  32. data/lib/haveapi/validator.rb +13 -13
  33. data/lib/haveapi/validator_chain.rb +6 -6
  34. data/lib/haveapi/validators/acceptance.rb +2 -2
  35. data/lib/haveapi/validators/confirmation.rb +4 -4
  36. data/lib/haveapi/validators/exclusion.rb +4 -4
  37. data/lib/haveapi/validators/format.rb +4 -4
  38. data/lib/haveapi/validators/inclusion.rb +3 -3
  39. data/lib/haveapi/validators/length.rb +1 -1
  40. data/lib/haveapi/validators/numericality.rb +3 -3
  41. data/lib/haveapi/validators/presence.rb +2 -2
  42. data/lib/haveapi/version.rb +1 -1
  43. data/lib/haveapi/views/version_page/auth_body.erb +6 -4
  44. data/lib/haveapi/views/version_page/resource_body.erb +2 -0
  45. data/lib/haveapi.rb +1 -0
  46. data/spec/authorization_spec.rb +28 -28
  47. data/spec/envelope_spec.rb +4 -4
  48. data/spec/parameters/typed_spec.rb +3 -3
  49. data/spec/params_spec.rb +2 -2
  50. data/spec/validators/acceptance_spec.rb +2 -2
  51. data/spec/validators/confirmation_spec.rb +4 -4
  52. data/spec/validators/exclusion_spec.rb +2 -2
  53. data/spec/validators/format_spec.rb +5 -5
  54. data/spec/validators/inclusion_spec.rb +8 -8
  55. data/spec/validators/presence_spec.rb +1 -1
  56. metadata +19 -4
@@ -12,8 +12,8 @@ module HaveAPI
12
12
  # message: 'the error message'
13
13
  # }
14
14
  #
15
- # In this case, the value could be anything but +one+, +two+ or
16
- # +three+.
15
+ # In this case, the value could be anything but `one`, `two` or
16
+ # `three`.
17
17
  class Validators::Exclusion < Validator
18
18
  name :exclude
19
19
  takes :exclude
@@ -28,8 +28,8 @@ module HaveAPI
28
28
 
29
29
  def describe
30
30
  {
31
- values: @values,
32
- message: @message,
31
+ values: @values,
32
+ message: @message,
33
33
  }
34
34
  end
35
35
 
@@ -25,10 +25,10 @@ module HaveAPI
25
25
 
26
26
  def describe
27
27
  {
28
- rx: @rx.source,
29
- match: @match,
30
- description: @desc,
31
- message: @message,
28
+ rx: @rx.source,
29
+ match: @match,
30
+ description: @desc,
31
+ message: @message,
32
32
  }
33
33
  end
34
34
 
@@ -12,7 +12,7 @@ module HaveAPI
12
12
  # message: 'the error message'
13
13
  # }
14
14
  #
15
- # Option +choices+ is an alias to +include+.
15
+ # Option `choices` is an alias to `include`.
16
16
  class Validators::Inclusion < Validator
17
17
  name :include
18
18
  takes :choices, :include
@@ -36,8 +36,8 @@ module HaveAPI
36
36
 
37
37
  def describe
38
38
  {
39
- values: @values,
40
- message: @message,
39
+ values: @values,
40
+ message: @message,
41
41
  }
42
42
  end
43
43
 
@@ -47,7 +47,7 @@ module HaveAPI
47
47
 
48
48
  def describe
49
49
  ret = {
50
- message: @message,
50
+ message: @message,
51
51
  }
52
52
 
53
53
  if @equals
@@ -11,7 +11,7 @@ module HaveAPI
11
11
  # message: 'the error message'
12
12
  # }
13
13
  #
14
- # Will allow values +3+, +5+, +7+ and +9+.
14
+ # Will allow values `3`, `5`, `7` and `9`.
15
15
  #
16
16
  # string :param, number: {
17
17
  # min: 3,
@@ -19,7 +19,7 @@ module HaveAPI
19
19
  # mod: 2,
20
20
  # }
21
21
  #
22
- # Will allow values +4+, +6+, +8+ and +10+.
22
+ # Will allow values `4`, `6`, `8` and `10`.
23
23
  class Validators::Numericality < Validator
24
24
  name :number
25
25
  takes :number
@@ -74,7 +74,7 @@ module HaveAPI
74
74
 
75
75
  def describe
76
76
  ret = {
77
- message: @message,
77
+ message: @message,
78
78
  }
79
79
 
80
80
  ret[:min] = @min if @min
@@ -27,8 +27,8 @@ module HaveAPI
27
27
 
28
28
  def describe
29
29
  {
30
- empty: @empty,
31
- message: @message,
30
+ empty: @empty,
31
+ message: @message,
32
32
  }
33
33
  end
34
34
 
@@ -1,4 +1,4 @@
1
1
  module HaveAPI
2
2
  PROTOCOL_VERSION = '2.0'
3
- VERSION = '0.18.2'
3
+ VERSION = '0.19.0'
4
4
  end
@@ -12,10 +12,12 @@
12
12
  </dl>
13
13
  <% elsif name == :oauth2 %>
14
14
  <dl>
15
- <dt>Authorize path:</dt>
16
- <dd><%= info[:authorize_path] %></dd>
17
- <dt>Token path:</dt>
18
- <dd><%= info[:token_path] %></dd>
15
+ <dt>Authorize URL:</dt>
16
+ <dd><%= info[:authorize_url] %></dd>
17
+ <dt>Token URL:</dt>
18
+ <dd><%= info[:token_url] %></dd>
19
+ <dt>Revoke URL:</dt>
20
+ <dd><%= info[:revoke_url] %></dd>
19
21
  </dl>
20
22
  <% end %>
21
23
 
@@ -17,6 +17,8 @@
17
17
  <dd><%= info[:description] %></dd>
18
18
  <dt>Authentication required:</dt>
19
19
  <dd><%= info[:auth] ? 'yes' : 'no' %></dd>
20
+ <dt>Scope:</dt>
21
+ <dd><%= info[:scope] %></dd>
20
22
  <dt>Aliases:</dt>
21
23
  <dd><%= info[:aliases].join(', ') %></dd>
22
24
  <dt>Blocking:</dt>
data/lib/haveapi.rb CHANGED
@@ -4,6 +4,7 @@ require 'require_all'
4
4
  require 'active_support/inflector'
5
5
  require 'active_record' if ar
6
6
  require 'sinatra/base'
7
+ require 'sinatra/cookies'
7
8
  require 'sinatra/activerecord' if ar
8
9
  require 'pp'
9
10
  require 'github/markdown'
@@ -40,17 +40,17 @@ describe HaveAPI::Authorization do
40
40
  input whitelist: %i(param1)
41
41
  allow
42
42
  end
43
-
43
+
44
44
  expect(auth.authorized?(nil)).to be true
45
-
45
+
46
46
  action = Resource::Index
47
47
 
48
48
  expect(auth.filter_input(
49
- action.input.params,
50
- action.model_adapter(action.input.layout).input({
51
- param1: '123',
52
- param2: '456',
53
- })
49
+ action.input.params,
50
+ action.model_adapter(action.input.layout).input({
51
+ param1: '123',
52
+ param2: '456',
53
+ })
54
54
  ).keys).to contain_exactly(:param1)
55
55
  end
56
56
 
@@ -59,17 +59,17 @@ describe HaveAPI::Authorization do
59
59
  input blacklist: %i(param1)
60
60
  allow
61
61
  end
62
-
62
+
63
63
  expect(auth.authorized?(nil)).to be true
64
-
64
+
65
65
  action = Resource::Index
66
66
 
67
67
  expect(auth.filter_input(
68
- action.input.params,
69
- action.model_adapter(action.input.layout).input({
70
- param1: '123',
71
- param2: '456',
72
- })
68
+ action.input.params,
69
+ action.model_adapter(action.input.layout).input({
70
+ param1: '123',
71
+ param2: '456',
72
+ })
73
73
  ).keys).to contain_exactly(:param2)
74
74
  end
75
75
 
@@ -78,17 +78,17 @@ describe HaveAPI::Authorization do
78
78
  output whitelist: %i(param1)
79
79
  allow
80
80
  end
81
-
81
+
82
82
  expect(auth.authorized?(nil)).to be true
83
-
83
+
84
84
  action = Resource::Index
85
85
 
86
86
  expect(auth.filter_output(
87
- action.output.params,
88
- action.model_adapter(action.output.layout).output(nil, {
89
- param1: '123',
90
- param2: '456',
91
- })
87
+ action.output.params,
88
+ action.model_adapter(action.output.layout).output(nil, {
89
+ param1: '123',
90
+ param2: '456',
91
+ })
92
92
  ).keys).to contain_exactly(:param1)
93
93
  end
94
94
 
@@ -97,17 +97,17 @@ describe HaveAPI::Authorization do
97
97
  output blacklist: %i(param1)
98
98
  allow
99
99
  end
100
-
100
+
101
101
  expect(auth.authorized?(nil)).to be true
102
-
102
+
103
103
  action = Resource::Index
104
104
 
105
105
  expect(auth.filter_output(
106
- action.output.params,
107
- action.model_adapter(action.output.layout).output(nil, {
108
- param1: '123',
109
- param2: '456',
110
- })
106
+ action.output.params,
107
+ action.model_adapter(action.output.layout).output(nil, {
108
+ param1: '123',
109
+ param2: '456',
110
+ })
111
111
  ).keys).to contain_exactly(:param2)
112
112
  end
113
113
  end
@@ -5,10 +5,10 @@ describe 'Envelope' do
5
5
  it 'returns correct envelope' do
6
6
  call_api(:options, '/')
7
7
  expect(api_response.envelope.keys).to contain_exactly(
8
- *%i(version status response message errors)
8
+ *%i(version status response message errors)
9
9
  )
10
10
  end
11
-
11
+
12
12
  it 'succeeds' do
13
13
  call_api(:options, '/')
14
14
  expect(api_response).to be_ok
@@ -17,11 +17,11 @@ describe 'Envelope' do
17
17
 
18
18
  context 'data' do
19
19
  empty_api
20
-
20
+
21
21
  it 'returns correct envelope' do
22
22
  call_api(:get, '/unknown_resource')
23
23
  expect(api_response.envelope.keys).to contain_exactly(
24
- *%i(status response message errors)
24
+ *%i(status response message errors)
25
25
  )
26
26
  end
27
27
 
@@ -11,9 +11,9 @@ describe 'Parameters::Typed' do
11
11
 
12
12
  it 'does not change provided arguments' do
13
13
  kwargs = {
14
- label: 'Param 1',
15
- desc: 'Desc',
16
- required: true,
14
+ label: 'Param 1',
15
+ desc: 'Desc',
16
+ required: true,
17
17
  }
18
18
  p_arg(kwargs)
19
19
  expect(kwargs.keys).to contain_exactly(*%i(label desc required))
data/spec/params_spec.rb CHANGED
@@ -156,7 +156,7 @@ describe HaveAPI::Params do
156
156
 
157
157
  expect do
158
158
  p.check_layout({
159
- my_resource: {}
159
+ my_resource: {}
160
160
  })
161
161
  end.not_to raise_error
162
162
  end
@@ -171,7 +171,7 @@ describe HaveAPI::Params do
171
171
 
172
172
  expect do
173
173
  p.check_layout({
174
- something_bad: {}
174
+ something_bad: {}
175
175
  })
176
176
  end.to raise_error(HaveAPI::ValidationError)
177
177
  end
@@ -7,7 +7,7 @@ describe HaveAPI::Validators::Acceptance do
7
7
  it "rejects incorrect value" do
8
8
  expect(@v.valid?('bar')).to be false
9
9
  end
10
- end
10
+ end
11
11
 
12
12
  context 'short form' do
13
13
  before(:each) do
@@ -20,7 +20,7 @@ describe HaveAPI::Validators::Acceptance do
20
20
  context 'full form' do
21
21
  before(:each) do
22
22
  @v = HaveAPI::Validators::Acceptance.new(:accept, {
23
- value: 'foo'
23
+ value: 'foo'
24
24
  })
25
25
  end
26
26
 
@@ -7,7 +7,7 @@ describe HaveAPI::Validators::Confirmation do
7
7
  it "rejects a different value" do
8
8
  expect(@v.validate('bar', {other_param: 'foo'})).to be false
9
9
  end
10
- end
10
+ end
11
11
 
12
12
  context 'short form' do
13
13
  before(:each) do
@@ -20,7 +20,7 @@ describe HaveAPI::Validators::Confirmation do
20
20
  context 'full form' do
21
21
  before(:each) do
22
22
  @v = HaveAPI::Validators::Confirmation.new(:confirm, {
23
- param: :other_param
23
+ param: :other_param
24
24
  })
25
25
  end
26
26
 
@@ -30,8 +30,8 @@ describe HaveAPI::Validators::Confirmation do
30
30
  context 'with equal = false' do
31
31
  before(:each) do
32
32
  @v = HaveAPI::Validators::Confirmation.new(:confirm, {
33
- param: :other_param,
34
- equal: false
33
+ param: :other_param,
34
+ equal: false
35
35
  })
36
36
  end
37
37
 
@@ -10,7 +10,7 @@ describe HaveAPI::Validators::Exclusion do
10
10
  expect(@v.valid?('zero')).to be true
11
11
  expect(@v.valid?('four')).to be true
12
12
  end
13
- end
13
+ end
14
14
 
15
15
  context 'short form' do
16
16
  before(:each) do
@@ -23,7 +23,7 @@ describe HaveAPI::Validators::Exclusion do
23
23
  context 'full form' do
24
24
  before(:each) do
25
25
  @v = HaveAPI::Validators::Exclusion.new(:exclude, {
26
- values: %w(one two three)
26
+ values: %w(one two three)
27
27
  })
28
28
  end
29
29
 
@@ -10,7 +10,7 @@ describe HaveAPI::Validators::Format do
10
10
  expect(@v.valid?('bacacb')).to be false
11
11
  expect(@v.valid?('b')).to be false
12
12
  end
13
- end
13
+ end
14
14
 
15
15
  context 'with match = true' do
16
16
  context 'short form' do
@@ -24,7 +24,7 @@ describe HaveAPI::Validators::Format do
24
24
  context 'full form' do
25
25
  before(:each) do
26
26
  @v = HaveAPI::Validators::Format.new(:format, {
27
- rx: /^a[^b]+b$/
27
+ rx: /^a[^b]+b$/
28
28
  })
29
29
  end
30
30
 
@@ -35,11 +35,11 @@ describe HaveAPI::Validators::Format do
35
35
  context 'with match = false' do
36
36
  before(:each) do
37
37
  @v = HaveAPI::Validators::Format.new(:format, {
38
- rx: /^a[^b]+b$/,
39
- match: false
38
+ rx: /^a[^b]+b$/,
39
+ match: false
40
40
  })
41
41
  end
42
-
42
+
43
43
  it 'rejects a value that matches the regexp' do
44
44
  expect(@v.valid?('aab')).to be false
45
45
  expect(@v.valid?('aacacb')).to be false
@@ -10,15 +10,15 @@ describe HaveAPI::Validators::Inclusion do
10
10
  expect(@v.valid?('zero')).to be false
11
11
  expect(@v.valid?('four')).to be false
12
12
  end
13
- end
13
+ end
14
14
 
15
15
  [
16
- %w(one two three),
17
- {
18
- one: 'Fancy one',
19
- two: 'Fancy two',
20
- three: 'Fancy three'
21
- }
16
+ %w(one two three),
17
+ {
18
+ one: 'Fancy one',
19
+ two: 'Fancy two',
20
+ three: 'Fancy three'
21
+ }
22
22
  ].each do |include|
23
23
  context "with include as a '#{include.class}'" do
24
24
  context 'short form' do
@@ -32,7 +32,7 @@ describe HaveAPI::Validators::Inclusion do
32
32
  context 'full form' do
33
33
  before(:each) do
34
34
  @v = HaveAPI::Validators::Inclusion.new(:include, {
35
- values: %w(one two three)
35
+ values: %w(one two three)
36
36
  })
37
37
  end
38
38
 
@@ -24,7 +24,7 @@ describe HaveAPI::Validators::Presence do
24
24
  before(:each) do
25
25
  @v = HaveAPI::Validators::Presence.new(:required, {})
26
26
  end
27
-
27
+
28
28
  include_examples :all
29
29
  end
30
30
  end
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.18.2
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: tilt
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +156,14 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: 0.18.2
159
+ version: 0.19.0
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 0.18.2
166
+ version: 0.19.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: mail
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -210,6 +224,7 @@ files:
210
224
  - lib/haveapi/authentication/oauth2.rb
211
225
  - lib/haveapi/authentication/oauth2/config.rb
212
226
  - lib/haveapi/authentication/oauth2/provider.rb
227
+ - lib/haveapi/authentication/oauth2/revoke_endpoint.rb
213
228
  - lib/haveapi/authentication/token.rb
214
229
  - lib/haveapi/authentication/token/action_config.rb
215
230
  - lib/haveapi/authentication/token/action_request.rb
@@ -332,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
347
  - !ruby/object:Gem::Version
333
348
  version: '0'
334
349
  requirements: []
335
- rubygems_version: 3.4.13
350
+ rubygems_version: 3.4.22
336
351
  signing_key:
337
352
  specification_version: 4
338
353
  summary: Framework for creating self-describing APIs