openstax_api 5.3.0 → 5.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
  SHA1:
3
- metadata.gz: ab8a6785ca018f79bbd476d360b2a52956a6b56a
4
- data.tar.gz: 4d77c522856c7f424a86e9c8e06646e2292af525
3
+ metadata.gz: bd1e28d0e4f377076268137319caa8627e4946f1
4
+ data.tar.gz: 9594e636215544dc1a2f1d39e88cebb983434c0c
5
5
  SHA512:
6
- metadata.gz: 27abc5a1882d7fa01c531d32d5e4e82192469d156ea843d3d6185df40e55474751834ef5a3135e2f51cdbf491275254b24ea025f7c59dd341b92279c629d4f5e
7
- data.tar.gz: 460eb820b127aa0805dfb0c636ac810ca6bbc2533855c901e7330a147b66781aca5cfbc22b1b9abe44b2a0ea55d09c99abf5d3b5ee50fc7f61d000a29cbbfb82
6
+ metadata.gz: fe53719d70cdc83b38bae3987ad2d112341ef147a8a2a527cc295c0ddbcdf0bedbef72e50d675fd1f899804f902335d1513e9c29724658d98835542670ee4953
7
+ data.tar.gz: 340faad4b368f2a7af64c7a0c29bde1ed6266434b0fe369489182f7e901ed1e492eb09f8477dcb7af6903fbbfa6751cebe006414dcc5645891f562876775fc93
@@ -13,6 +13,7 @@ module OpenStax
13
13
 
14
14
  respond_to :json
15
15
 
16
+ before_filter :force_json_content_type
16
17
  after_filter :set_date_header
17
18
 
18
19
  # Keep old current_user method so we can use it
@@ -36,12 +37,6 @@ module OpenStax
36
37
  current_api_user.human_user
37
38
  end
38
39
 
39
- def consume!(model, options = {})
40
- # Don't error out if no CONTENT_TYPE header
41
- request.env['CONTENT_TYPE'] ||= 'application/json'
42
- super
43
- end
44
-
45
40
  protected
46
41
 
47
42
  def session_user?
@@ -52,6 +47,12 @@ module OpenStax
52
47
  response.date = Time.now unless response.date?
53
48
  end
54
49
 
50
+ def force_json_content_type
51
+ # Force JSON content_type
52
+ request.env['CONTENT_TYPE'] = 'application/json'
53
+ request.env['action_dispatch.request.content_type'] = 'application/json'
54
+ end
55
+
55
56
  end
56
57
 
57
58
  end
@@ -25,18 +25,31 @@ module OpenStax
25
25
  collection :items,
26
26
  readable: true,
27
27
  writeable: false,
28
+ exec_context: :decorator,
28
29
  schema_info: {
29
30
  required: true,
30
31
  description: "The items matching the query or a subset thereof when paginating"
31
32
  }
32
33
 
34
+ def items
35
+ return represented.items if represented.respond_to?(:items)
36
+ return represented[:items] if represented.respond_to?(:has_key?) && \
37
+ represented.has_key?(:items)
38
+ represented
39
+ end
40
+
33
41
  def total_count
34
- return represented[:total_count] if represented[:total_count]
35
- case represented[:items]
36
- when ActiveRecord::Relation
37
- represented[:items].limit(nil).offset(nil).count
38
- when Array
39
- represented[:items].count
42
+ return represented.total_count if represented.respond_to?(:total_count)
43
+ return represented[:total_count] if represented.respond_to?(:has_key?) && \
44
+ represented.has_key?(:total_count)
45
+
46
+ @items = items
47
+ if @items.respond_to?(:length)
48
+ if @items.respond_to?(:limit) && @items.respond_to?(:offset)
49
+ @items.limit(nil).offset(nil).length
50
+ else
51
+ @items.length
52
+ end
40
53
  else
41
54
  1
42
55
  end
@@ -14,8 +14,7 @@ module OpenStax
14
14
  scope(except: [:new, :edit],
15
15
  module: version,
16
16
  constraints: constraints) do
17
- get '/', to: '/apipie/apipies#index', defaults: {format: 'html',
18
- version: version.to_s}
17
+ get '/', to: '/apipie/apipies#index', defaults: {format: 'html', version: version.to_s}
19
18
 
20
19
  yield
21
20
 
@@ -90,8 +90,12 @@ module OpenStax
90
90
  end
91
91
  end
92
92
 
93
- if defined?(RSpec)
93
+ # Add the helpers to RSpec but don't error out if the rspec gem is not present
94
+ begin
95
+ require 'rspec/core'
96
+
94
97
  RSpec.configure do |c|
95
98
  c.include OpenStax::Api::RSpecHelpers
96
99
  end
100
+ rescue LoadError
97
101
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Api
3
- VERSION = "5.3.0"
3
+ VERSION = "5.4.0"
4
4
  end
5
5
  end
Binary file