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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f8d716f67fca1c587540e13f7db606522238ec2b77638f8278049d1812926c2
4
- data.tar.gz: 062e0e434cb74bb13021f4211c5c919108a14d771321534ac0bf6a92b59ce556
3
+ metadata.gz: 6edbd981e494d9f1063ba9d150596c629c7d0bf3908f87809664a6ce18befa2f
4
+ data.tar.gz: 35a521253e0bc888a538e28aeaaccac1b5380fbb9529cd6a8a202b540d2ec48e
5
5
  SHA512:
6
- metadata.gz: 9f97f203f831a97d8bc4ffce4a348dff922c5b4f1b7795715daf6f2ef615231f18b0921dd226b36be3e08b494843dc91fba391b991418caa229b557dfa631298
7
- data.tar.gz: 23d07578255d6cd7c84d08265ed866e02d1d20dfaa4efdcbaea260bc2064368382dab602b62fd1580c26b2a3b0f06ba7272e1d4665b21d371e8c855804dfde2f
6
+ metadata.gz: 14638e9706ece06c415252c5765fd334da5ac00e04ab6489c289bb606ed647adc48430bae0be3df93531c1c39e699e702207eeb7a3ee654a0460177cfb39e48c
7
+ data.tar.gz: 37e430223b7aef6665c9cb4f9065cef1f41e90cf6dc67795dc29cc04fb49c354e23cb0c0105ddb751de472b26dc58b86378194d54b1594861542ba4879909270
@@ -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'
@@ -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 }.merge(represent_with: represent_with)
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 }.merge(represent_with: represent_with)
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, search_options.merge(represent_with_options)
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
- create_options = { status: :created, location: nil }
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, create_options.merge(represent_with_options)
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
- represent_with_options = { user_options: options }.merge(represent_with: represent_with)
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 }.merge(represent_with: represent_with)
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 }.merge(represent_with: represent_with)
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 = { user_options: options.except(:recursive) }
132
- .merge(represent_with: represent_with)
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 |attribute, message|
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 : { code: error.to_s.underscore,
168
- message: error.to_s.humanize }
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
- if action.is_a? String
75
- action = "/#{action}" if !action.starts_with?("/")
76
- action = "/api#{action}" if !action.starts_with?("/api/")
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
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Api
3
- VERSION = '9.0.0'
3
+ VERSION = '9.4.0'
4
4
  end
5
5
  end
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.0.0
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: 2019-05-23 00:00:00.000000000 Z
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: '3.1'
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: '3.1'
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: '2.4'
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: '2.4'
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: '1.0'
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: '1.0'
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: '1.0'
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: '1.0'
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.1.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.1.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: '2.0'
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: '2.0'
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: '4.0'
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: '4.0'
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: 4.2.0
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: 4.2.0
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: 1.0.0
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: 1.0.0
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.0.1
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.