openstax_api 5.2.2 → 5.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae4df95ab9e38f20ee96bfe5d5cd310c10d5c7c7
4
- data.tar.gz: ed8ea2e60ff45728be9d4803a5e9db0a478e6256
3
+ metadata.gz: ab8a6785ca018f79bbd476d360b2a52956a6b56a
4
+ data.tar.gz: 4d77c522856c7f424a86e9c8e06646e2292af525
5
5
  SHA512:
6
- metadata.gz: cc6efaa3c7504398f7ccf5d67c318b5985d4884819edd0e385ac903aab6ff7b74d590e6ef480f4d8b607eed31d155859de30964c8d41a2b42c8533be45c53237
7
- data.tar.gz: b03775f4e8dbb68ad768ef7d1f93333174be78dd90362194de40fb2004fa3112298d0d2789ef68450bf37418c0394ac456fff06ce5638db138fa0e5dc695b824
6
+ metadata.gz: 27abc5a1882d7fa01c531d32d5e4e82192469d156ea843d3d6185df40e55474751834ef5a3135e2f51cdbf491275254b24ea025f7c59dd341b92279c629d4f5e
7
+ data.tar.gz: 460eb820b127aa0805dfb0c636ac810ca6bbc2533855c901e7330a147b66781aca5cfbc22b1b9abe44b2a0ea55d09c99abf5d3b5ee50fc7f61d000a29cbbfb82
@@ -25,9 +25,7 @@ module OpenStax
25
25
  model.class.transaction do
26
26
  consume!(model, represent_with: represent_with)
27
27
  yield model if block_given?
28
- OSU::AccessPolicy.require_action_allowed!(:create,
29
- current_api_user,
30
- model)
28
+ OSU::AccessPolicy.require_action_allowed!(:create, current_api_user, model)
31
29
 
32
30
  if model.save
33
31
  respond_with model, represent_with: represent_with,
@@ -38,30 +36,24 @@ module OpenStax
38
36
  end
39
37
  end
40
38
 
41
- def standard_read(model, represent_with=nil)
42
- OSU::AccessPolicy.require_action_allowed!(:read,
43
- current_api_user,
44
- model)
45
- respond_with model, represent_with: represent_with
39
+ def standard_read(model, represent_with=nil, use_timestamp_for_cache=false)
40
+ OSU::AccessPolicy.require_action_allowed!(:read, current_api_user, model)
41
+ respond_with model, represent_with: represent_with \
42
+ if !use_timestamp_for_cache || stale?(model)
46
43
  end
47
44
 
48
45
  def standard_update(model, represent_with=nil)
49
46
  # Must be able to update the record before and after the update itself
50
- OSU::AccessPolicy.require_action_allowed!(:update,
51
- current_api_user,
52
- model)
47
+ OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, model)
53
48
 
54
49
  model.class.transaction do
55
50
  consume!(model, represent_with: represent_with)
56
51
  yield model if block_given?
57
- OSU::AccessPolicy.require_action_allowed!(:update,
58
- current_api_user,
59
- model)
52
+ OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, model)
60
53
 
61
54
  if model.save
62
55
  # http://stackoverflow.com/a/27413178
63
- respond_with model, represent_with: represent_with,
64
- responder: ResponderWithPutContent
56
+ respond_with model, represent_with: represent_with, responder: ResponderWithPutContent
65
57
  else
66
58
  render_api_errors(model.errors)
67
59
  end
@@ -69,9 +61,7 @@ module OpenStax
69
61
  end
70
62
 
71
63
  def standard_destroy(model)
72
- OSU::AccessPolicy.require_action_allowed!(:destroy,
73
- current_api_user,
74
- model)
64
+ OSU::AccessPolicy.require_action_allowed!(:destroy, current_api_user, model)
75
65
 
76
66
  if model.destroy
77
67
  head :no_content
@@ -82,44 +72,34 @@ module OpenStax
82
72
 
83
73
  def standard_index(relation, represent_with)
84
74
  model_klass = relation.base_class
85
- OSU::AccessPolicy.require_action_allowed!(:index,
86
- current_api_user,
87
- model_klass)
75
+ OSU::AccessPolicy.require_action_allowed!(:index, current_api_user, model_klass)
88
76
  relation.each do |item|
89
77
  # Must be able to read each record
90
- OSU::AccessPolicy.require_action_allowed!(:read,
91
- current_api_user,
92
- item)
78
+ OSU::AccessPolicy.require_action_allowed!(:read, current_api_user, item)
93
79
  end
94
- respond_with(Lev::Outputs.new(items: relation),
95
- represent_with: represent_with)
80
+ respond_with(Lev::Outputs.new(items: relation), represent_with: represent_with)
96
81
  end
97
82
 
98
83
  def standard_sort(*args)
99
84
  raise NotYetImplemented
100
85
  end
101
86
 
102
- def standard_nested_create(model, container_association,
103
- container, represent_with=nil)
87
+ def standard_nested_create(model, container_association, container, represent_with=nil)
104
88
  # Must be able to update the container
105
- OSU::AccessPolicy.require_action_allowed!(:update,
106
- current_api_user,
107
- container)
89
+ OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, container)
108
90
  model.send("#{container_association.to_s}=", container)
109
91
 
110
92
  standard_create(model, represent_with)
111
93
  end
112
94
 
113
95
  def render_api_errors(errors, status = :unprocessable_entity)
114
- hash = {status: Rack::Utils.status_code(status)}
96
+ hash = { status: Rack::Utils.status_code(status) }
115
97
  case errors
116
98
  when ActiveModel::Errors, Lev::BetterActiveModelErrors
117
99
  hash[:errors] = []
118
100
  errors.each do |attribute, message|
119
101
  hash[:errors] << {
120
- code: "#{attribute.to_s}_#{
121
- message.to_s.gsub(/[\s-]/, '_').gsub(/[^\w]/, '')
122
- }",
102
+ code: "#{attribute.to_s}_#{message.to_s.gsub(/[\s-]/, '_').gsub(/[^\w]/, '')}",
123
103
  message: errors.full_message(attribute, message)
124
104
  }
125
105
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Api
3
- VERSION = "5.2.2"
3
+ VERSION = "5.3.0"
4
4
  end
5
5
  end
Binary file