openstax_api 9.0.0 → 9.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openstax/api/engine.rb +0 -2
- data/lib/openstax/api/roar.rb +19 -17
- data/lib/openstax/api/rspec_helpers.rb +4 -3
- data/lib/openstax/api/version.rb +1 -1
- metadata +57 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6edbd981e494d9f1063ba9d150596c629c7d0bf3908f87809664a6ce18befa2f
|
4
|
+
data.tar.gz: 35a521253e0bc888a538e28aeaaccac1b5380fbb9529cd6a8a202b540d2ec48e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14638e9706ece06c415252c5765fd334da5ac00e04ab6489c289bb606ed647adc48430bae0be3df93531c1c39e699e702207eeb7a3ee654a0460177cfb39e48c
|
7
|
+
data.tar.gz: 37e430223b7aef6665c9cb4f9065cef1f41e90cf6dc67795dc29cc04fb49c354e23cb0c0105ddb751de472b26dc58b86378194d54b1594861542ba4879909270
|
data/lib/openstax/api/engine.rb
CHANGED
@@ -13,8 +13,6 @@ module OpenStax
|
|
13
13
|
class Engine < ::Rails::Engine
|
14
14
|
isolate_namespace OpenStax::Api
|
15
15
|
|
16
|
-
config.autoload_paths += Dir[config.root.join('app', 'representers', '{**}')]
|
17
|
-
|
18
16
|
config.generators do |g|
|
19
17
|
g.test_framework :rspec, fixture: false
|
20
18
|
g.fixture_replacement :factory_bot, dir: 'spec/factories'
|
data/lib/openstax/api/roar.rb
CHANGED
@@ -13,7 +13,7 @@ module OpenStax
|
|
13
13
|
model_klass = relation.base_class
|
14
14
|
OSU::AccessPolicy.require_action_allowed!(:index, current_api_user, model_klass)
|
15
15
|
|
16
|
-
represent_with_options = { user_options: options
|
16
|
+
represent_with_options = { user_options: options, represent_with: represent_with }
|
17
17
|
|
18
18
|
relation.each do |item|
|
19
19
|
# Must be able to read each record
|
@@ -24,11 +24,10 @@ module OpenStax
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def standard_search(klass, routine, represent_with, options={})
|
27
|
-
search_options = { location: nil }
|
28
27
|
user = current_api_user
|
29
28
|
OSU::AccessPolicy.require_action_allowed!(:search, user, klass)
|
30
29
|
|
31
|
-
represent_with_options = { user_options: options
|
30
|
+
represent_with_options = { user_options: options, represent_with: represent_with }
|
32
31
|
|
33
32
|
result = routine.call(params, options)
|
34
33
|
return render_api_errors(result.errors) if result.errors.any?
|
@@ -38,12 +37,11 @@ module OpenStax
|
|
38
37
|
OSU::AccessPolicy.require_action_allowed!(:read, user, item)
|
39
38
|
end
|
40
39
|
|
41
|
-
respond_with outputs,
|
40
|
+
respond_with outputs, { status: :ok, location: nil }.merge(represent_with_options)
|
42
41
|
end
|
43
42
|
|
44
43
|
def standard_create(model, represent_with=nil, options={})
|
45
|
-
|
46
|
-
represent_with_options = { user_options: options }.merge(represent_with: represent_with)
|
44
|
+
represent_with_options = { user_options: options, represent_with: represent_with }
|
47
45
|
|
48
46
|
model.class.transaction do
|
49
47
|
consume!(model, represent_with_options.dup)
|
@@ -51,7 +49,7 @@ module OpenStax
|
|
51
49
|
OSU::AccessPolicy.require_action_allowed!(:create, current_api_user, model)
|
52
50
|
|
53
51
|
if model.save
|
54
|
-
respond_with model,
|
52
|
+
respond_with model, { status: :created, location: nil }.merge(represent_with_options)
|
55
53
|
else
|
56
54
|
render_api_errors(model.errors)
|
57
55
|
end
|
@@ -71,9 +69,7 @@ module OpenStax
|
|
71
69
|
def standard_read(model, represent_with=nil, use_timestamp_for_cache=false, options={})
|
72
70
|
OSU::AccessPolicy.require_action_allowed!(:read, current_api_user, model)
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
respond_with model, represent_with_options \
|
72
|
+
respond_with(model, { user_options: options, represent_with: represent_with }) \
|
77
73
|
if !use_timestamp_for_cache || stale?(model, template: false)
|
78
74
|
end
|
79
75
|
|
@@ -82,7 +78,7 @@ module OpenStax
|
|
82
78
|
OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, model)
|
83
79
|
|
84
80
|
responder_options = { responder: ResponderWithPutPatchDeleteContent }
|
85
|
-
represent_with_options = { user_options: options
|
81
|
+
represent_with_options = { user_options: options, represent_with: represent_with }
|
86
82
|
|
87
83
|
model.with_lock do
|
88
84
|
consume!(model, represent_with_options.dup)
|
@@ -106,11 +102,12 @@ module OpenStax
|
|
106
102
|
if model.respond_to?(:deleted?) && model.deleted?
|
107
103
|
|
108
104
|
responder_options = { responder: ResponderWithPutPatchDeleteContent }
|
109
|
-
represent_with_options = { user_options: options
|
105
|
+
represent_with_options = { user_options: options, represent_with: represent_with }
|
110
106
|
|
111
107
|
model.with_lock do
|
112
108
|
if model.destroy
|
113
109
|
model.send :clear_association_cache
|
110
|
+
yield model if block_given?
|
114
111
|
respond_with model, responder_options.merge(represent_with_options)
|
115
112
|
else
|
116
113
|
render_api_errors(model.errors)
|
@@ -128,12 +125,14 @@ module OpenStax
|
|
128
125
|
recursive = options.has_key?(:recursive) ? options[:recursive] : true
|
129
126
|
|
130
127
|
responder_options = { responder: ResponderWithPutPatchDeleteContent }
|
131
|
-
represent_with_options = {
|
132
|
-
|
128
|
+
represent_with_options = {
|
129
|
+
user_options: options.except(:recursive), represent_with: represent_with
|
130
|
+
}
|
133
131
|
|
134
132
|
model.with_lock do
|
135
133
|
if model.restore(recursive: recursive)
|
136
134
|
model.send :clear_association_cache
|
135
|
+
yield model if block_given?
|
137
136
|
respond_with model, responder_options.merge(represent_with_options)
|
138
137
|
else
|
139
138
|
render_api_errors(model.errors)
|
@@ -152,7 +151,10 @@ module OpenStax
|
|
152
151
|
|
153
152
|
case errors
|
154
153
|
when ActiveModel::Errors, Lev::BetterActiveModelErrors
|
155
|
-
hash[:errors] = errors.map do |
|
154
|
+
hash[:errors] = errors.map do |error|
|
155
|
+
attribute = error.attribute
|
156
|
+
message = error.message
|
157
|
+
|
156
158
|
{
|
157
159
|
code: "#{attribute.to_s}_#{message.to_s.gsub(/[\s-]/, '_').gsub(/[^\w]/, '')}",
|
158
160
|
message: errors.full_message(attribute, message)
|
@@ -164,8 +166,8 @@ module OpenStax
|
|
164
166
|
end
|
165
167
|
else
|
166
168
|
hash[:errors] = [errors].flatten.map do |error|
|
167
|
-
error.is_a?(Hash) ? error :
|
168
|
-
|
169
|
+
error.is_a?(Hash) ? error :
|
170
|
+
{ code: error.to_s.underscore, message: error.to_s.humanize }
|
169
171
|
end
|
170
172
|
end
|
171
173
|
|
@@ -71,9 +71,10 @@ module OpenStax
|
|
71
71
|
# be a URL fragment string -- in such a case, prepend "/api"
|
72
72
|
# to the front of the URL as a convenience to callers
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
action = "
|
74
|
+
action = action.to_s unless is_a_controller_spec?
|
75
|
+
if action.is_a?(String) && !action.include?('://')
|
76
|
+
action = "/#{action}" if !action.starts_with?('/')
|
77
|
+
action = "/api#{action}" if !action.starts_with?('/api/')
|
77
78
|
end
|
78
79
|
|
79
80
|
send type, action, args
|
data/lib/openstax/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dante Soares
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,132 +17,132 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.2'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '7'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
30
|
+
version: '5.2'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: representable
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
38
|
- - ">="
|
33
39
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
35
|
-
- - "<"
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '4.0'
|
40
|
+
version: '0'
|
38
41
|
type: :runtime
|
39
42
|
prerelease: false
|
40
43
|
version_requirements: !ruby/object:Gem::Requirement
|
41
44
|
requirements:
|
42
45
|
- - ">="
|
43
46
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
45
|
-
- - "<"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '4.0'
|
47
|
+
version: '0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: roar
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: roar-rails
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
type: :runtime
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: uber
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
89
|
+
version: '0'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: doorkeeper
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
type: :runtime
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: exception_notification
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: openstax_utilities
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '0'
|
125
125
|
type: :runtime
|
126
126
|
prerelease: false
|
127
127
|
version_requirements: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: '0'
|
132
132
|
- !ruby/object:Gem::Dependency
|
133
133
|
name: lev
|
134
134
|
requirement: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: '0'
|
139
139
|
type: :runtime
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: '0'
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: responders
|
148
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,6 +157,34 @@ dependencies:
|
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
|
+
- !ruby/object:Gem::Dependency
|
161
|
+
name: sprockets
|
162
|
+
requirement: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: listen
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
type: :development
|
182
|
+
prerelease: false
|
183
|
+
version_requirements: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
160
188
|
- !ruby/object:Gem::Dependency
|
161
189
|
name: sqlite3
|
162
190
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
302
|
- !ruby/object:Gem::Version
|
275
303
|
version: '0'
|
276
304
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
305
|
+
rubygems_version: 3.2.7
|
278
306
|
signing_key:
|
279
307
|
specification_version: 4
|
280
308
|
summary: API utilities for OpenStax products and tools.
|