openstax_api 4.0.0 → 4.0.1

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: 5bd63382869d88bfbb49b1fe5fb7c1a5522f2369
4
- data.tar.gz: c80e6e53fa5a5f8c2942f723a5999e93198eccae
3
+ metadata.gz: 9a04be0fa091031552f0e4797e093a1751661e7d
4
+ data.tar.gz: 8e79ca4932124dcdf2948320db9d461ff94cd498
5
5
  SHA512:
6
- metadata.gz: 95c74b7898781162457f4f6b1180735c0a21c5ce2d5368eb2e2baeb7fddd66d04fda8fff3fc17f401ddfad6d9dc561d2e6f8c1d36e165119038a769b142c8804
7
- data.tar.gz: 86c0f23a3182e2bdb7051d48cef30106c2b5c2252f3563c723cd12ed685a06fec0f3be3ce903d6268588f63ca6625d61be08ad074564c7942642043540e1dad3
6
+ metadata.gz: d975020dd0e7bf4e5ba8eefb43fede87f83bf95de73a0f48ab915ddaa43f5131a965dcaf8e92a66671c664593d83eeeb45a9b5cb411298a14f8f0d65cd1e8c12
7
+ data.tar.gz: 86dc7e42cd01e76e895a48f19d5320ba1bcd48142de2471c3b3ac082d1ffccf656c6315f12c24ee88e83416cccd1b0179c075473d57367e23c9300a4c7b1cf5c
@@ -39,34 +39,26 @@ module OpenStax
39
39
  end
40
40
 
41
41
  def api_request(type, action, doorkeeper_token, args={})
42
- request_method = is_a_controller_spec? ?
43
- :controller_spec_api_request :
44
- :request_spec_api_request
45
- self.send(request_method, type, action, doorkeeper_token, args)
46
- end
47
-
48
- private
49
-
50
- def controller_spec_api_request(type, action, doorkeeper_token, args={})
51
42
  raise IllegalArgument if ![:get, :post, :put, :delete, :patch, :head].include?(type)
52
43
 
53
- # Add the doorkeeper token info and the accept header
44
+ header = is_a_controller_spec? ? request.env : {}
54
45
 
55
- request.env['HTTP_AUTHORIZATION'] = "Bearer #{doorkeeper_token.token}" \
56
- if doorkeeper_token
46
+ # Add the doorkeeper token info
47
+ header['HTTP_AUTHORIZATION'] = "Bearer #{doorkeeper_token.token}" if doorkeeper_token
57
48
 
58
- request.env['HTTP_ACCEPT'] = http_accept_string
49
+ # Select the version of the API based on the spec metadata and populate the accept header
50
+ version_string = self.class.metadata[:version].try(:to_s)
51
+ raise ArgumentError, "Top-level 'describe' metadata must include a value for ':version'" if version_string.nil?
52
+ header['HTTP_ACCEPT'] = "application/vnd.openstax.#{version_string}"
59
53
 
60
54
  # Set the raw post data in the request, converting to JSON if needed
61
-
62
55
  if args[:raw_post_data]
63
- request.env['RAW_POST_DATA'] = args[:raw_post_data].is_a?(Hash) ?
64
- args[:raw_post_data].to_json :
65
- args[:raw_post_data]
56
+ header['RAW_POST_DATA'] = args[:raw_post_data].is_a?(Hash) ?
57
+ args[:raw_post_data].to_json :
58
+ args[:raw_post_data]
66
59
  end
67
60
 
68
61
  # Set the data format
69
-
70
62
  args[:parameters] ||= {}
71
63
  args[:parameters][:format] = 'json'
72
64
 
@@ -79,29 +71,19 @@ module OpenStax
79
71
  action = "/api#{action}" if !action.starts_with?("/api/")
80
72
  end
81
73
 
82
- # Delegate the work to the normal HTTP request helpers
83
- self.send(type, action, args[:parameters], args[:session], args[:flash])
74
+ if is_a_controller_spec?
75
+ self.send(type, action, args[:parameters], args[:session], args[:flash])
76
+ else
77
+ self.send(type, action, args[:parameters], header)
78
+ end
84
79
  end
85
80
 
86
- def request_spec_api_request(type, route, doorkeeper_token=nil, args={})
87
- http_header = {}
88
- http_header['HTTP_AUTHORIZATION'] = "Bearer #{doorkeeper_token.token}" if doorkeeper_token.present?
89
- http_header['HTTP_ACCEPT'] = http_accept_string
90
-
91
- send(type, route, {format: :json}, http_header)
92
- end
81
+ private
93
82
 
94
83
  def is_a_controller_spec?
95
84
  self.class.metadata[:type] == :controller
96
85
  end
97
86
 
98
- def http_accept_string
99
- # Select the version of the API based on the spec metadata and populate the vnd string
100
- version_string = self.class.metadata[:version].try(:to_s)
101
- raise ArgumentError, "Top-level 'describe' metadata must include a value for ':version'" if version_string.nil?
102
- "application/vnd.openstax.#{version_string}"
103
- end
104
-
105
87
  end
106
88
  end
107
89
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Api
3
- VERSION = "4.0.0"
3
+ VERSION = "4.0.1"
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: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dante Soares