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 +4 -4
- data/lib/openstax/api/rspec_helpers.rb +16 -34
- data/lib/openstax/api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a04be0fa091031552f0e4797e093a1751661e7d
|
4
|
+
data.tar.gz: 8e79ca4932124dcdf2948320db9d461ff94cd498
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
44
|
+
header = is_a_controller_spec? ? request.env : {}
|
54
45
|
|
55
|
-
|
56
|
-
|
46
|
+
# Add the doorkeeper token info
|
47
|
+
header['HTTP_AUTHORIZATION'] = "Bearer #{doorkeeper_token.token}" if doorkeeper_token
|
57
48
|
|
58
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
83
|
-
|
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
|
-
|
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
|
data/lib/openstax/api/version.rb
CHANGED