active_public_resources 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +24 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.txt +18 -0
  8. data/README.md +326 -0
  9. data/Rakefile +7 -0
  10. data/active_public_resources.gemspec +27 -0
  11. data/active_public_resources_config.yml.example +10 -0
  12. data/lib/active_public_resources/base_response_type.rb +11 -0
  13. data/lib/active_public_resources/base_return_type.rb +17 -0
  14. data/lib/active_public_resources/client.rb +22 -0
  15. data/lib/active_public_resources/driver.rb +21 -0
  16. data/lib/active_public_resources/driver_response.rb +15 -0
  17. data/lib/active_public_resources/drivers/khan_academy.rb +143 -0
  18. data/lib/active_public_resources/drivers/quizlet.rb +92 -0
  19. data/lib/active_public_resources/drivers/schooltube.rb +99 -0
  20. data/lib/active_public_resources/drivers/vimeo.rb +181 -0
  21. data/lib/active_public_resources/drivers/youtube.rb +113 -0
  22. data/lib/active_public_resources/request_criteria.rb +51 -0
  23. data/lib/active_public_resources/response_types/exercise.rb +11 -0
  24. data/lib/active_public_resources/response_types/folder.rb +18 -0
  25. data/lib/active_public_resources/response_types/image.rb +11 -0
  26. data/lib/active_public_resources/response_types/quiz.rb +11 -0
  27. data/lib/active_public_resources/response_types/video.rb +12 -0
  28. data/lib/active_public_resources/return_types/file.rb +11 -0
  29. data/lib/active_public_resources/return_types/iframe.rb +11 -0
  30. data/lib/active_public_resources/return_types/image_url.rb +11 -0
  31. data/lib/active_public_resources/return_types/oembed.rb +11 -0
  32. data/lib/active_public_resources/return_types/url.rb +11 -0
  33. data/lib/active_public_resources/version.rb +3 -0
  34. data/lib/active_public_resources.rb +55 -0
  35. data/spec/lib/active_public_resources/client_spec.rb +75 -0
  36. data/spec/lib/active_public_resources/driver_spec.rb +48 -0
  37. data/spec/lib/active_public_resources/drivers/khan_academy_spec.rb +106 -0
  38. data/spec/lib/active_public_resources/drivers/quizlet_spec.rb +50 -0
  39. data/spec/lib/active_public_resources/drivers/schooltube_spec.rb +50 -0
  40. data/spec/lib/active_public_resources/drivers/vimeo_spec.rb +71 -0
  41. data/spec/lib/active_public_resources/drivers/youtube_spec.rb +52 -0
  42. data/spec/lib/active_public_resources/live_client_spec.rb +91 -0
  43. data/spec/lib/active_public_resources/request_criteria_spec.rb +53 -0
  44. data/spec/spec_helper.rb +46 -0
  45. data/spec/vcr/active_public_resources/client/khan_academy_should_traverse_folders.yml +1039 -0
  46. data/spec/vcr/active_public_resources/client/quizlet_should_perform_request.yml +70 -0
  47. data/spec/vcr/active_public_resources/client/shooltube_should_perform_request.yml +815 -0
  48. data/spec/vcr/active_public_resources/client/vimeo_should_perform_request.yml +70 -0
  49. data/spec/vcr/active_public_resources/client/youtube_should_perform_request.yml +212 -0
  50. data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_folder_cs/programming.yml +117 -0
  51. data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_folder_cs.yml +72 -0
  52. data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_folder_science/mcat/society_and_culture/social_structures.yml +578 -0
  53. data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_root_folders.yml +122 -0
  54. data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_cs/programming.yml +120 -0
  55. data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_cs.yml +73 -0
  56. data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_science/mcat/society_and_culture/social_structures.yml +577 -0
  57. data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_root_folders.yml +119 -0
  58. data/spec/vcr/active_public_resources/drivers/quizlet_driver_perform_request/should_perform_request.yml +75 -0
  59. data/spec/vcr/active_public_resources/drivers/quizlet_perform_request/should_perform_request.yml +72 -0
  60. data/spec/vcr/active_public_resources/drivers/schooltube_driver_perform_request/should_perform_request.yml +815 -0
  61. data/spec/vcr/active_public_resources/drivers/schooltube_perform_request/should_perform_request.yml +810 -0
  62. data/spec/vcr/active_public_resources/drivers/vimeo_driver_perform_request/should_perform_request.yml +279 -0
  63. data/spec/vcr/active_public_resources/drivers/vimeo_perform_request/should_perform_request.yml +70 -0
  64. data/spec/vcr/active_public_resources/drivers/youtube_driver_perform_request/should_perform_request.yml +212 -0
  65. data/spec/vcr/active_public_resources/drivers/youtube_perform_request/should_perform_request.yml +209 -0
  66. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f82492f1e5cfc67fee25365b48d83ce58efa170
4
+ data.tar.gz: f45c20c7330389c2f59b8f3aad0e03b558780a7a
5
+ SHA512:
6
+ metadata.gz: 06100044d338f7837c23684f3ea49f7803242300a08497f90e45bceb1ed00826090dbc8e122d5ef2eeced25eb95019a2959473eccdc2c6baa63edd618d092e15
7
+ data.tar.gz: bbbbe5c9448f2b80ffcd3c2f51f8a72a5f258b8437a4fd91d066ae78220bc15130c9cc4af4a12a17e64f390076f42d6e9b2701d30cd420a2b99e16605497df59
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ active_public_resources_config.yml
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'yard'
4
+ gem 'rake'
5
+
6
+ group :test do
7
+ gem 'rspec', '~> 2.14.1'
8
+ # gem 'rspec-mocks', '~> 2.14.4'
9
+ gem 'vcr'
10
+ gem 'webmock'
11
+ gem 'simplecov', '~> 0.8.1', :require => false
12
+ gem 'growl'
13
+ gem 'growl-rspec'
14
+ end
15
+
16
+ group :development do
17
+ gem 'guard-rspec'
18
+ end
19
+
20
+ group :development, :test do
21
+ gem 'pry'
22
+ end
23
+
24
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cli: '--color --format nested' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013 Instructure
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to use,
6
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
+ Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,326 @@
1
+ # Active Public Resources
2
+
3
+ [![Build Status](https://travis-ci.org/instructure/active_public_resources.png)](https://travis-ci.org/instructure/active_public_resources)
4
+ [![Code Climate](https://codeclimate.com/github/instructure/active_public_resources.png)](https://codeclimate.com/github/instructure/active_public_resources)
5
+
6
+ Active Public Resources is a collection of resources online which return embeddable or linkable
7
+ resources. This gem normalizes the requests and responses into response type objects.
8
+
9
+ For example, you can search for videos via YouTube, Vimeo and SchoolTube. Each of these
10
+ requests will use a common interface (RequestCriteria) and a common response (DriverResponse).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'active_public_resources'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install active_public_resources
25
+
26
+ ## Concepts
27
+
28
+ There are several components that make up the full request/response circle with this gem:
29
+
30
+ * **Request Criteria** - The object which contains the criteria that is passed to the driver to make the request.
31
+ * **Driver Response** - The response object which contains the request criteria, next request criteria and a list of resulting response type objects.
32
+ * **Response Types** - Objects which are returned in the driver response. Includes Exercise, Folder, Image, Quiz and Video.
33
+ * **Return Types** - The linkable, downloadable or embeddable results of the response type.
34
+
35
+ ## Request Criteria
36
+
37
+ A request criteria in this context is a ruby object which contains the criteria that is to be
38
+ passed to the driver.
39
+
40
+ | Name | Required? | Description
41
+ | -------------- |:---------:| -----------
42
+ | query | No | Search term
43
+ | page | No | Page of results. Defaults to 0
44
+ | per_page | No | Items to return per page. Defaults to 25
45
+ | content_filter | No | Filter flag. Can either be `none` or `strict`. Defaults to `none`
46
+ | sort | No | Sort filter. Can be `relevance`, `recent` or `popular`. Defaults to `relevance`
47
+ | folder | No | Current folder. This is used for folder-based requests (e.g. Khan Academy). Defaults to `root`
48
+
49
+ Examples:
50
+
51
+ ```ruby
52
+ # Search-based criteria
53
+ criteria = APR::RequestCriteria.new(
54
+ :query => "education",
55
+ :page => 3,
56
+ :per_page => 15,
57
+ :sort => APR::RequestCriteria::SORT_RELEVANCE,
58
+ :content_filter => APR::RequestCriteria::CONTENT_FILTER_NONE
59
+ )
60
+
61
+ # Folder-based criteria
62
+ criteria = APR::RequestCriteria.new(
63
+ :folder => "engineering"
64
+ )
65
+ ```
66
+
67
+ ## Driver Response (and Response Types)
68
+
69
+ A driver response is the object which encapsulates the results of the driver's `perform_request` method. It contains the following data:
70
+
71
+ * **items** - Array of Response Types
72
+ * **criteria** - Original search criteria which was used to perform the request
73
+ * **next_criteria** - Next criteria which can be used to get the next set of results (e.g. page 2)
74
+ * **total_items** - Total number of results for search criteria
75
+
76
+ ### Folder
77
+
78
+ A folder is returned from API's which are browsable (e.g. Khan Academy).
79
+
80
+ * **id** - ID of folder
81
+ * **title** - Folder name
82
+ * **description** - Folder description
83
+ * **parent_id** - ID of parent folder (or `nil` for root)
84
+ * **items** - Array of Response Types for this folder (can include folders as well)
85
+
86
+ ### Image
87
+
88
+ * **id** - ID of image
89
+ * **title** - Image name
90
+ * **description** - Image description
91
+ * **url** - Image URL (used in HREF)
92
+ * **width** - Image width
93
+ * **height** - Image height
94
+
95
+ ### Quiz
96
+
97
+ * **id** - ID of quiz
98
+ * **title** - Quiz name
99
+ * **description** - Quiz description
100
+ * **url** - URL of quiz
101
+ * **term_count** - Number of items in quiz
102
+ * **created_date** - Date quiz was created
103
+ * **has_images** - Boolean flag to indicate if quiz has images
104
+ * **subjects** - Array of tags
105
+
106
+ ### Video
107
+
108
+ * **id** - ID of video
109
+ * **title** - Video name
110
+ * **description** - Video description
111
+ * **thumbnail_url** - Thumbnail image url
112
+ * **url** - URL to video
113
+ * **duration** - Duration in seconds
114
+ * **width** - Video width
115
+ * **height** - Video height
116
+ * **username** - Username of creator
117
+ * **num_views** - Number of views
118
+ * **num_likes** - Number of likes
119
+ * **num_comments** - Number of comments
120
+ * **created_date** - Date created
121
+
122
+ ### Exercise
123
+
124
+ * **id** - ID of exercise
125
+ * **title** - Exercise name
126
+ * **description** - Exercise description
127
+ * **thumbnail_url** - Thumbnail image url
128
+ * **url** - URL to exercise
129
+
130
+ ## Return Types
131
+
132
+ Return types are the embeddable, linkable or downloadable parts of the response type.
133
+ For example, if you have a video response type, you can either embed the video (oembed),
134
+ embed the video (iframe) or link to the video (url).
135
+
136
+ ### File
137
+
138
+ * **url** - this is a URL to the file that can be retrieved without requiring any additional authentication (no sessions, cookies, etc.)
139
+ * **text** - the filename
140
+ * **content_type** - content or MIME type of the file to be retrieved
141
+
142
+ ### IFrame
143
+
144
+ * **url** - this is used as the 'src' attribute of the embedded iframe
145
+ * **title** - this is used as the 'title' attribute of the embedded iframe
146
+ * **width** - this is used as the 'width' style of the embedded iframe
147
+ * **height** - this is used as the 'height' style of the embedded iframe
148
+
149
+ ### Image URL
150
+
151
+ * **url** - this is used as the 'src' attribute of the embedded image tag
152
+ * **text** - this is used as the 'alt' attribute of the embedded image tag
153
+ * **width** - this is used as the 'width' style of the embedded image tag
154
+ * **height** - this is used as the 'height' style of the embedded image tag
155
+
156
+ ### OEmbed
157
+
158
+ * **url** - this is the oEmbed resource URL
159
+ * **endpoint** - this is the oEmbed API endpoint URL
160
+
161
+ ### URL
162
+
163
+ * **url** - The url. Likely used as the 'href' attribute of the inserted link
164
+ * **text** - this is the suggested text for the inserted link. If the user has already selected
165
+ some content before opening this dialog, the link will wrap that content and this
166
+ value may be ignored
167
+ * **title** - this is used as the 'title' attribute of the inserted link
168
+ * **target** - this is used as the 'target' attribute of the inserted link
169
+
170
+ ## Drivers
171
+
172
+ A driver in this context is a ruby class which performs requests and returns a response.
173
+
174
+ ### Vimeo
175
+
176
+ To use the Vimeo API, you must have credentials already. This requires a Vimeo app to
177
+ be registered. You can do it at [https://developer.vimeo.com/apps](https://developer.vimeo.com/apps).
178
+ There are 4 params which are necessary to perform the requests:
179
+
180
+ | Name | Required? | Description
181
+ | ------------------- |:---------:| -------------
182
+ | consumer_key | Yes | Vimeo API Client ID
183
+ | consumer_secret | Yes | Vimeo API Client Secret
184
+ | access_token | Yes | Vimeo API OAuth Access Token
185
+ | access_token_secret | Yes | Vimeo API OAuth Access Token Secret
186
+
187
+ #### Return Types
188
+
189
+ Vimeo returns **Iframe** and **URL** return types.
190
+
191
+ #### Example:
192
+
193
+ ```ruby
194
+ criteria = APR::RequestCriteria.new( query: "education" )
195
+
196
+ vimeo = APR::Drivers::Vimeo.new(
197
+ :consumer_key => 'VIMEO_CONSUMER_KEY',
198
+ :consumer_secret => 'VIMEO_CONSUMER_SECRET',
199
+ :access_token => 'VIMEO_ACCESS_TOKEN',
200
+ :access_token_secret => 'VIMEO_ACCESS_TOKEN_SECRET'
201
+ )
202
+
203
+ results = vimeo.perform_request( criteria )
204
+ results.items.length # => 25
205
+ results.total_items # => 145063
206
+ results.next_criteria # => #<ActivePublicResources::RequestCriteria:0x007fa48392d388 @query="education", @page=2, @per_page=25>
207
+ results.items.first.title # => "Kynect 'education'"
208
+
209
+ more_results = vimeo.perform_request( results.next_criteria )
210
+ # ...
211
+ ```
212
+
213
+ ### YouTube
214
+
215
+ There are no credentials needed to query YouTube.
216
+
217
+ #### Return Types
218
+
219
+ YouTube returns **Iframe** and **URL** return types.
220
+
221
+ #### Example:
222
+
223
+ ```ruby
224
+ criteria = APR::RequestCriteria.new( query: "education" )
225
+
226
+ youtube = APR::Drivers::Youtube.new
227
+
228
+ results = youtube.perform_request( criteria )
229
+ results.items.length # => 25
230
+ results.total_items # => 1000000
231
+ results.next_criteria # => #<ActivePublicResources::RequestCriteria:0x007fa48392d388 @query="education", @page=2, @per_page=25>
232
+ results.items.first.title # => "Why I Hate School But Love Education||Spoken Word"
233
+
234
+ more_results = youtube.perform_request( results.next_criteria )
235
+ # ...
236
+ ```
237
+
238
+ ### SchoolTube
239
+
240
+ There are no credentials needed to query SchoolTube.
241
+
242
+ #### Return Types
243
+
244
+ SchoolTube returns **Iframe** and **URL** return types.
245
+
246
+ #### Example:
247
+
248
+ ```ruby
249
+ criteria = APR::RequestCriteria.new( query: "education" )
250
+
251
+ schooltube = APR::Drivers::Schooltube.new
252
+
253
+ results = schooltube.perform_request( criteria )
254
+ results.items.length # => 25
255
+ results.total_items # => nil (API does not offer total items)
256
+ results.next_criteria # => #<ActivePublicResources::RequestCriteria:0x007fa48392d388 @query="education", @page=2, @per_page=25>
257
+ results.items.first.title # => "Fun - Educational School Trips - Call American Tours & Travel"
258
+
259
+ more_results = schooltube.perform_request( results.next_criteria )
260
+ # ...
261
+ ```
262
+
263
+ ### Quizlet
264
+
265
+ Quizlet requires and Client ID to perform API requests. You can get this by visiting
266
+ [https://quizlet.com/api-dashboard](https://quizlet.com/api-dashboard).
267
+
268
+ | Name | Required? | Description
269
+ | --------- |:---------:| -------------
270
+ | client_id | Yes | Quizlet Client ID (used for public and user access)
271
+
272
+ #### Return Types
273
+
274
+ Quizlet returns **Iframe** and **URL** return types.
275
+
276
+ #### Example:
277
+
278
+ ```ruby
279
+ criteria = APR::RequestCriteria.new( query: "education" )
280
+
281
+ quizlet = APR::Drivers::Quizlet.new(
282
+ :client_id => 'rTHYaHnXTz'
283
+ )
284
+
285
+ results = quizlet.perform_request( criteria )
286
+ results.items.length # => 25
287
+ results.total_items # => 5001
288
+ results.next_criteria # => #<ActivePublicResources::RequestCriteria:0x007fa48392d388 @query="education", @page=2, @per_page=25>
289
+ results.items.first.title # => "Education"
290
+
291
+ results.items.first.return_types.map(&:url)
292
+ # => [ "http://quizlet.com/8572574/education-flash-cards/",
293
+ "https://quizlet.com/8572574/flashcards/embedv2",
294
+ "https://quizlet.com/8572574/learn/embedv2",
295
+ "https://quizlet.com/8572574/scatter/embedv2",
296
+ "https://quizlet.com/8572574/speller/embedv2",
297
+ "https://quizlet.com/8572574/test/embedv2",
298
+ "https://quizlet.com/8572574/spacerace/embedv2" ]
299
+
300
+ more_results = quizlet.perform_request( results.next_criteria )
301
+ ...
302
+ ```
303
+
304
+ ## Testing
305
+
306
+ Tests can be run with the rake task `spec`
307
+
308
+ $ rake spec
309
+
310
+ If you would like to test actual live API's you can do so as well. You need to
311
+ create the file `active_public_resources_config.yml` and populate it with actual
312
+ credentials for the different services. Once that is done, run the following
313
+ command:
314
+
315
+ $ rspec --tag live_api
316
+
317
+ This will run much slower because it is hitting the live API's, but a pass on these
318
+ tests means everything is working great!
319
+
320
+ ## Contributing
321
+
322
+ 1. Fork it
323
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
324
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
325
+ 4. Push to the branch (`git push origin my-new-feature`)
326
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_public_resources/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_public_resources"
8
+ spec.version = ActivePublicResources::VERSION
9
+ spec.authors = ["Eric Berry"]
10
+ spec.email = ["cavneb@gmail.com"]
11
+ spec.description = %q{ Normalized searching and browsing of public resources }
12
+ spec.summary = %q{ Normalized searching and browsing of public resources }
13
+ spec.homepage = "https://github.com/instructure/active_public_resources"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "active_support", ">= 3.0.0"
22
+
23
+ # Drivers
24
+ spec.add_dependency "vimeo", "~> 1.5.3"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ end
@@ -0,0 +1,10 @@
1
+ vimeo:
2
+ consumer_key: VIMEO_CONSUMER_KEY
3
+ consumer_secret: VIMEO_CONSUMER_SECRET
4
+ access_token: VIMEO_ACCESS_TOKEN
5
+ access_token_secret: VIMEO_ACCESS_TOKEN_SECRET
6
+ youtube:
7
+ schooltube:
8
+ khan_academy:
9
+ quizlet:
10
+ client_id: QUIZLET_CLIENT_ID
@@ -0,0 +1,11 @@
1
+ module ActivePublicResources
2
+ module ResponseTypes
3
+ class BaseResponseType
4
+ attr_accessor :id, :title, :description, :return_types
5
+
6
+ def initialize
7
+ @return_types = []
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module ActivePublicResources
2
+ module ReturnTypes
3
+ class BaseReturnType
4
+ attr_accessor :url
5
+
6
+ def initialize(args)
7
+ args.each do |k,v|
8
+ instance_variable_set("@#{k}", v) unless v.nil?
9
+ end
10
+ end
11
+
12
+ def return_type
13
+ raise NotImplementedError.new("You must implement return_type.")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ module ActivePublicResources
2
+ class Client
3
+ def initialize(config={})
4
+ raise ArgumentError.new("key/value pair must be provided") if config.blank?
5
+
6
+ @drivers = {}
7
+ ActivePublicResources.symbolize_keys(config).each do |k, v|
8
+ klass = "ActivePublicResources::Drivers::#{k.to_s.split('_').map(&:capitalize).join}".constantize
9
+ @drivers[k] = (v.present? ? klass.new(v) : klass.new)
10
+ end
11
+ end
12
+
13
+ def perform_request(driver_name, request_criteria)
14
+ @drivers[driver_name.to_sym].perform_request(request_criteria)
15
+ end
16
+
17
+ def initialized_drivers
18
+ @drivers.keys
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module ActivePublicResources
2
+ module Drivers
3
+ class Driver
4
+
5
+ def perform_request(*args)
6
+ raise NotImplementedError.new("You must implement perform_request.")
7
+ end
8
+
9
+ protected
10
+
11
+ def validate_options(opts, req=[])
12
+ req.each do |k|
13
+ if opts.blank? || opts[k].blank?
14
+ raise ArgumentError.new("must include #{req.join(', ')}, instead received #{opts.inspect}")
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module ActivePublicResources
2
+ module Drivers
3
+ class DriverResponse
4
+ attr_accessor :items, :criteria, :next_criteria, :total_items
5
+
6
+ def initialize(args)
7
+ args.each do |k,v|
8
+ instance_variable_set("@#{k}", v) unless v.nil?
9
+ end
10
+ @items ||= []
11
+ end
12
+
13
+ end
14
+ end
15
+ end