openstax_api 0.0.1

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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +73 -0
  4. data/Rakefile +22 -0
  5. data/app/controllers/openstax/api/v1/api_controller.rb +75 -0
  6. data/app/controllers/openstax/api/v1/oauth_based_api_controller.rb +17 -0
  7. data/app/models/openstax/api/api_user.rb +82 -0
  8. data/app/representers/openstax/api/v1/representable_schema_printer.rb +85 -0
  9. data/lib/openstax_api/constraints.rb +21 -0
  10. data/lib/openstax_api/doorkeeper_extensions.rb +22 -0
  11. data/lib/openstax_api/engine.rb +20 -0
  12. data/lib/openstax_api/route_extensions.rb +17 -0
  13. data/lib/openstax_api/version.rb +5 -0
  14. data/lib/openstax_api.rb +8 -0
  15. data/spec/app/controllers/openstax/api/v1/api_controller_spec.rb +11 -0
  16. data/spec/app/controllers/openstax/api/v1/oauth_based_api_controller_spec.rb +11 -0
  17. data/spec/app/models/openstax/api/api_user_spec.rb +47 -0
  18. data/spec/app/representers/openstax/api/v1/representable_schema_printer_spec.rb +19 -0
  19. data/spec/dummy/README.md +1 -0
  20. data/spec/dummy/Rakefile +7 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/models/user.rb +2 -0
  26. data/spec/dummy/app/representers/user_representer.rb +8 -0
  27. data/spec/dummy/config/application.rb +53 -0
  28. data/spec/dummy/config/boot.rb +10 -0
  29. data/spec/dummy/config/database.yml +25 -0
  30. data/spec/dummy/config/environment.rb +5 -0
  31. data/spec/dummy/config/environments/development.rb +29 -0
  32. data/spec/dummy/config/environments/production.rb +69 -0
  33. data/spec/dummy/config/environments/test.rb +35 -0
  34. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/spec/dummy/config/initializers/doorkeeper.rb +75 -0
  36. data/spec/dummy/config/initializers/inflections.rb +15 -0
  37. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  38. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  39. data/spec/dummy/config/initializers/session_store.rb +8 -0
  40. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/spec/dummy/config/locales/en.yml +5 -0
  42. data/spec/dummy/config/routes.rb +2 -0
  43. data/spec/dummy/config.ru +4 -0
  44. data/spec/dummy/db/development.sqlite3 +0 -0
  45. data/spec/dummy/db/migrate/0_create_doorkeeper_tables.rb +42 -0
  46. data/spec/dummy/db/migrate/1_create_users.rb +10 -0
  47. data/spec/dummy/db/schema.rb +62 -0
  48. data/spec/dummy/db/test.sqlite3 +0 -0
  49. data/spec/dummy/log/development.log +541 -0
  50. data/spec/dummy/log/test.log +3183 -0
  51. data/spec/dummy/public/404.html +26 -0
  52. data/spec/dummy/public/422.html +26 -0
  53. data/spec/dummy/public/500.html +25 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/script/rails +6 -0
  56. data/spec/lib/openstax_api/constraints_spec.rb +74 -0
  57. data/spec/lib/openstax_api/doorkeeper_extensions_spec.rb +17 -0
  58. data/spec/lib/openstax_api/route_extensions_spec.rb +21 -0
  59. data/spec/spec_helper.rb +18 -0
  60. metadata +248 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax
4
+ module Api
5
+ describe Constraints do
6
+ context 'default is not defined' do
7
+ let!(:constraints) { Constraints.new(version: :v1) }
8
+ let(:req) { double('Request') }
9
+
10
+ it 'matches if version is correct in the accept headers' do
11
+ req.stub(:headers).and_return({
12
+ 'Accept' => 'application/vnd.dummy.openstax.v1'
13
+ })
14
+ expect(constraints.matches? req).to be_true
15
+ end
16
+
17
+ it 'does not match if version is incorrect in the accept headers' do
18
+ req.stub(:headers).and_return({
19
+ 'Accept' => 'application/vnd.dummy.openstax.v2'
20
+ })
21
+ expect(constraints.matches? req).to be_false
22
+ end
23
+
24
+ it 'does not match if version is not defined in the accept headers' do
25
+ req.stub(:headers).and_return({
26
+ 'Accept' => '*/*',
27
+ })
28
+ expect(constraints.matches? req).to be_false
29
+ end
30
+
31
+ it 'does not match if accept is not in headers' do
32
+ req.stub(:headers).and_return({
33
+ 'Host' => 'localhost'
34
+ })
35
+ expect(constraints.matches? req).to be_nil
36
+ end
37
+ end
38
+
39
+ context 'default is defined' do
40
+ let!(:default) { double('Default') }
41
+ let!(:constraints) { Constraints.new(version: :v1, default: default) }
42
+ let(:req) { double('Request') }
43
+
44
+ it 'matches if version is correct in the accept headers' do
45
+ req.stub(:headers).and_return({
46
+ 'Accept' => 'application/vnd.dummy.openstax.v1'
47
+ })
48
+ expect(constraints.matches? req).to be_true
49
+ end
50
+
51
+ it 'returns default if version is incorrect in the accept headers' do
52
+ req.stub(:headers).and_return({
53
+ 'Accept' => 'application/vnd.dummy.openstax.v2'
54
+ })
55
+ expect(constraints.matches? req).to eq(default)
56
+ end
57
+
58
+ it 'returns default if version is not defined in the accept headers' do
59
+ req.stub(:headers).and_return({
60
+ 'Accept' => '*/*',
61
+ })
62
+ expect(constraints.matches? req).to eq(default)
63
+ end
64
+
65
+ it 'returns default if accept is not in headers' do
66
+ req.stub(:headers).and_return({
67
+ 'Host' => 'localhost'
68
+ })
69
+ expect(constraints.matches? req).to eq(default)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax
4
+ module Api
5
+ describe DoorkeeperExtensions do
6
+ it 'must add methods to Doorkeeper::Application' do
7
+ application = Doorkeeper::Application.new
8
+ expect(application).to respond_to(:is_human?)
9
+ expect(application.is_human?).to eq(false)
10
+ expect(application).to respond_to(:is_application?)
11
+ expect(application.is_application?).to eq(true)
12
+ expect(application).to respond_to(:is_admin?)
13
+ expect(application.is_admin?).to eq(false)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax
4
+ module Api
5
+ describe RouteExtensions do
6
+ it 'must add api method to ActionDispatch::Routing::Mapper' do
7
+ mapper = ActionDispatch::Routing::Mapper.new(Rails.application.routes)
8
+ expect(mapper).to respond_to(:api)
9
+ Rails.application.routes.draw do
10
+ api :v1 do
11
+ resource :dummy_models
12
+ end
13
+ end
14
+ route_names = Rails.application.routes.named_routes.names
15
+ expect(route_names).to include(:api_dummy_models)
16
+ expect(route_names).to include(:new_api_dummy_models)
17
+ expect(route_names).to include(:edit_api_dummy_models)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'rspec/autorun'
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ config.use_transactional_fixtures = true
16
+ config.infer_base_class_for_anonymous_controllers = false
17
+ config.order = "random"
18
+ end
metadata ADDED
@@ -0,0 +1,248 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openstax_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dante Soares
8
+ - JP Slavinsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: roar
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.12.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 0.12.1
42
+ - !ruby/object:Gem::Dependency
43
+ name: roar-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.1.2
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.2
56
+ - !ruby/object:Gem::Dependency
57
+ name: doorkeeper
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0.5'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: openstax_utilities
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.1
84
+ - !ruby/object:Gem::Dependency
85
+ name: sqlite3
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.3'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec-rails
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '2.14'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.14'
112
+ description: Provides models, controllers and libraries that help OpenStax products
113
+ define API's for user applications.
114
+ email:
115
+ - dms3@rice.edu
116
+ - jps@kindlinglabs.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - MIT-LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - app/controllers/openstax/api/v1/api_controller.rb
125
+ - app/controllers/openstax/api/v1/oauth_based_api_controller.rb
126
+ - app/models/openstax/api/api_user.rb
127
+ - app/representers/openstax/api/v1/representable_schema_printer.rb
128
+ - lib/openstax_api.rb
129
+ - lib/openstax_api/constraints.rb
130
+ - lib/openstax_api/doorkeeper_extensions.rb
131
+ - lib/openstax_api/engine.rb
132
+ - lib/openstax_api/route_extensions.rb
133
+ - lib/openstax_api/version.rb
134
+ - spec/app/controllers/openstax/api/v1/api_controller_spec.rb
135
+ - spec/app/controllers/openstax/api/v1/oauth_based_api_controller_spec.rb
136
+ - spec/app/models/openstax/api/api_user_spec.rb
137
+ - spec/app/representers/openstax/api/v1/representable_schema_printer_spec.rb
138
+ - spec/dummy/README.md
139
+ - spec/dummy/Rakefile
140
+ - spec/dummy/app/assets/javascripts/application.js
141
+ - spec/dummy/app/assets/stylesheets/application.css
142
+ - spec/dummy/app/controllers/application_controller.rb
143
+ - spec/dummy/app/helpers/application_helper.rb
144
+ - spec/dummy/app/models/user.rb
145
+ - spec/dummy/app/representers/user_representer.rb
146
+ - spec/dummy/config.ru
147
+ - spec/dummy/config/application.rb
148
+ - spec/dummy/config/boot.rb
149
+ - spec/dummy/config/database.yml
150
+ - spec/dummy/config/environment.rb
151
+ - spec/dummy/config/environments/development.rb
152
+ - spec/dummy/config/environments/production.rb
153
+ - spec/dummy/config/environments/test.rb
154
+ - spec/dummy/config/initializers/backtrace_silencers.rb
155
+ - spec/dummy/config/initializers/doorkeeper.rb
156
+ - spec/dummy/config/initializers/inflections.rb
157
+ - spec/dummy/config/initializers/mime_types.rb
158
+ - spec/dummy/config/initializers/secret_token.rb
159
+ - spec/dummy/config/initializers/session_store.rb
160
+ - spec/dummy/config/initializers/wrap_parameters.rb
161
+ - spec/dummy/config/locales/en.yml
162
+ - spec/dummy/config/routes.rb
163
+ - spec/dummy/db/development.sqlite3
164
+ - spec/dummy/db/migrate/0_create_doorkeeper_tables.rb
165
+ - spec/dummy/db/migrate/1_create_users.rb
166
+ - spec/dummy/db/schema.rb
167
+ - spec/dummy/db/test.sqlite3
168
+ - spec/dummy/log/development.log
169
+ - spec/dummy/log/test.log
170
+ - spec/dummy/public/404.html
171
+ - spec/dummy/public/422.html
172
+ - spec/dummy/public/500.html
173
+ - spec/dummy/public/favicon.ico
174
+ - spec/dummy/script/rails
175
+ - spec/lib/openstax_api/constraints_spec.rb
176
+ - spec/lib/openstax_api/doorkeeper_extensions_spec.rb
177
+ - spec/lib/openstax_api/route_extensions_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/openstax/openstax_api
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.2.2
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: API utilities for OpenStax products and tools.
203
+ test_files:
204
+ - spec/app/controllers/openstax/api/v1/api_controller_spec.rb
205
+ - spec/app/controllers/openstax/api/v1/oauth_based_api_controller_spec.rb
206
+ - spec/app/models/openstax/api/api_user_spec.rb
207
+ - spec/app/representers/openstax/api/v1/representable_schema_printer_spec.rb
208
+ - spec/dummy/app/assets/javascripts/application.js
209
+ - spec/dummy/app/assets/stylesheets/application.css
210
+ - spec/dummy/app/controllers/application_controller.rb
211
+ - spec/dummy/app/helpers/application_helper.rb
212
+ - spec/dummy/app/models/user.rb
213
+ - spec/dummy/app/representers/user_representer.rb
214
+ - spec/dummy/config/application.rb
215
+ - spec/dummy/config/boot.rb
216
+ - spec/dummy/config/database.yml
217
+ - spec/dummy/config/environment.rb
218
+ - spec/dummy/config/environments/development.rb
219
+ - spec/dummy/config/environments/production.rb
220
+ - spec/dummy/config/environments/test.rb
221
+ - spec/dummy/config/initializers/backtrace_silencers.rb
222
+ - spec/dummy/config/initializers/doorkeeper.rb
223
+ - spec/dummy/config/initializers/inflections.rb
224
+ - spec/dummy/config/initializers/mime_types.rb
225
+ - spec/dummy/config/initializers/secret_token.rb
226
+ - spec/dummy/config/initializers/session_store.rb
227
+ - spec/dummy/config/initializers/wrap_parameters.rb
228
+ - spec/dummy/config/locales/en.yml
229
+ - spec/dummy/config/routes.rb
230
+ - spec/dummy/config.ru
231
+ - spec/dummy/db/development.sqlite3
232
+ - spec/dummy/db/migrate/0_create_doorkeeper_tables.rb
233
+ - spec/dummy/db/migrate/1_create_users.rb
234
+ - spec/dummy/db/schema.rb
235
+ - spec/dummy/db/test.sqlite3
236
+ - spec/dummy/log/development.log
237
+ - spec/dummy/log/test.log
238
+ - spec/dummy/public/404.html
239
+ - spec/dummy/public/422.html
240
+ - spec/dummy/public/500.html
241
+ - spec/dummy/public/favicon.ico
242
+ - spec/dummy/Rakefile
243
+ - spec/dummy/README.md
244
+ - spec/dummy/script/rails
245
+ - spec/lib/openstax_api/constraints_spec.rb
246
+ - spec/lib/openstax_api/doorkeeper_extensions_spec.rb
247
+ - spec/lib/openstax_api/route_extensions_spec.rb
248
+ - spec/spec_helper.rb