active_public_resources 0.1.4 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.rspec +1 -1
- data/Gemfile +1 -0
- data/Guardfile +0 -1
- data/LICENSE.txt +1 -1
- data/README.md +12 -11
- data/Rakefile +1 -1
- data/active_public_resources_config.yml.example +1 -1
- data/lib/active_public_resources/base_response_type.rb +1 -1
- data/lib/active_public_resources/base_return_type.rb +1 -1
- data/lib/active_public_resources/driver.rb +2 -2
- data/lib/active_public_resources/driver_response.rb +1 -1
- data/lib/active_public_resources/drivers/khan_academy.rb +1 -1
- data/lib/active_public_resources/drivers/vimeo.rb +4 -4
- data/lib/active_public_resources/drivers/youtube.rb +38 -5
- data/lib/active_public_resources/request_criteria.rb +19 -3
- data/lib/active_public_resources/return_types/file.rb +1 -1
- data/lib/active_public_resources/return_types/iframe.rb +1 -1
- data/lib/active_public_resources/return_types/image_url.rb +1 -1
- data/lib/active_public_resources/version.rb +1 -1
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDliYWYzMjQ3NmM0ZDIxOTA4NThlOTJmNTE3NjEwYTY4MDMyYzM5ZQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e99a0eb62cafe3e34b5871ca70220f4b3270e6d
|
4
|
+
data.tar.gz: c838fe9798d6c23af9d4aa265d95c8aac22bcf67
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MWY3ODM3Y2JiY2Q5OTFmODY2MWJkMTRiYjk0OWRiZTUxYmU4ZWRiMjExNjkw
|
11
|
-
NTNhYmYxMGU2MTg5YmVhZmRmNzE5NTExNzYxNGZiMzExNWQ2YjM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Yjk3MjFmMDY2MWI4YTcyYWYzMWJiNDZkNWVjZmUyN2YxNzgyY2Q0NzZhYzQw
|
14
|
-
YjJjMzAzZmFmYWU5NDk2ZmU3ODQ1YzU2ZDc2ZjViMjdjMjY0ZWI2OWIzODNk
|
15
|
-
NGE1ZTFmNTRmYWQyOWQ5YWRiZjNmY2IyODQ1NjIyYmM5M2M1ODI=
|
6
|
+
metadata.gz: c9b311d3790c86e79cab9d454dbef60c67ffbf3c9731772bdb076da5325f9615838f001bbe056268e8dd23d023f1364ab1c2918b8cce8d52c709d4c6fbe8b668
|
7
|
+
data.tar.gz: 06a57c4494ff2d21610ded78dbe7ae679ca903846cb860b636f6b5f0397a3367688c59754577c32334749e4517dc6e970f2818cf9bb52106b64d8b912e358bc1
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
17
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.
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -39,9 +39,10 @@ There are several components that make up the full request/response circle with
|
|
39
39
|
A request criteria in this context is a ruby object which contains the criteria that is to be
|
40
40
|
passed to the driver.
|
41
41
|
|
42
|
-
| Name | Required? | Description
|
43
|
-
| -------------- |:---------:| -----------
|
42
|
+
| Name | Required? | Description
|
43
|
+
| -------------- |:---------:| -----------
|
44
44
|
| query | No | Search term
|
45
|
+
| channel | No | Id for channel (currently only supported by the youtube driver)
|
45
46
|
| page | No | Page of results. Defaults to 0
|
46
47
|
| per_page | No | Items to return per page. Defaults to 25
|
47
48
|
| content_filter | No | Filter flag. Can either be `none` or `strict`. Defaults to `none`
|
@@ -173,8 +174,8 @@ embed the video (iframe) or link to the video (url).
|
|
173
174
|
* **driver** - name of driver used (e.g. vimeo, youtube, quizlet, etc.)
|
174
175
|
* **remote_id** - id of media provided by the driver
|
175
176
|
* **url** - The url. Likely used as the 'href' attribute of the inserted link
|
176
|
-
* **text** - this is the suggested text for the inserted link. If the user has already selected
|
177
|
-
some content before opening this dialog, the link will wrap that content and this
|
177
|
+
* **text** - this is the suggested text for the inserted link. If the user has already selected
|
178
|
+
some content before opening this dialog, the link will wrap that content and this
|
178
179
|
value may be ignored
|
179
180
|
* **title** - this is used as the 'title' attribute of the inserted link
|
180
181
|
* **target** - this is used as the 'target' attribute of the inserted link
|
@@ -186,12 +187,12 @@ A driver in this context is a ruby class which performs requests and returns a r
|
|
186
187
|
### Vimeo
|
187
188
|
|
188
189
|
To use the Vimeo API, you must have credentials already. This requires a Vimeo app to
|
189
|
-
be registered. You can do it at [https://developer.vimeo.com/apps](https://developer.vimeo.com/apps).
|
190
|
-
There are 4 params which are necessary to perform the requests:
|
190
|
+
be registered. You can do it at [https://developer.vimeo.com/apps](https://developer.vimeo.com/apps).
|
191
|
+
There are 4 params which are necessary to perform the requests:
|
191
192
|
|
192
|
-
| Name | Required? | Description
|
193
|
-
| ------------------- |:---------:| -------------
|
194
|
-
| consumer_key | Yes | Vimeo API Client ID
|
193
|
+
| Name | Required? | Description
|
194
|
+
| ------------------- |:---------:| -------------
|
195
|
+
| consumer_key | Yes | Vimeo API Client ID
|
195
196
|
| consumer_secret | Yes | Vimeo API Client Secret
|
196
197
|
| access_token | Yes | Vimeo API OAuth Access Token
|
197
198
|
| access_token_secret | Yes | Vimeo API OAuth Access Token Secret
|
@@ -277,8 +278,8 @@ more_results = schooltube.perform_request( results.next_criteria )
|
|
277
278
|
Quizlet requires and Client ID to perform API requests. You can get this by visiting
|
278
279
|
[https://quizlet.com/api-dashboard](https://quizlet.com/api-dashboard).
|
279
280
|
|
280
|
-
| Name | Required? | Description
|
281
|
-
| --------- |:---------:| -------------
|
281
|
+
| Name | Required? | Description
|
282
|
+
| --------- |:---------:| -------------
|
282
283
|
| client_id | Yes | Quizlet Client ID (used for public and user access)
|
283
284
|
|
284
285
|
#### Return Types
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActivePublicResources
|
2
2
|
module Drivers
|
3
3
|
class Driver
|
4
|
-
|
4
|
+
|
5
5
|
def perform_request(*args)
|
6
6
|
raise NotImplementedError.new("You must implement perform_request.")
|
7
7
|
end
|
@@ -15,7 +15,7 @@ module ActivePublicResources
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -45,7 +45,7 @@ module ActivePublicResources
|
|
45
45
|
|
46
46
|
def parse_results(request_criteria, results, videos=[], exercises=[])
|
47
47
|
parent_id = parse_parent_id(results['slug'], results['extended_slug'])
|
48
|
-
|
48
|
+
|
49
49
|
driver_response = DriverResponse.new(
|
50
50
|
:criteria => request_criteria,
|
51
51
|
:next_criteria => nil,
|
@@ -21,9 +21,9 @@ module ActivePublicResources
|
|
21
21
|
# @option config_options [String] :access_token Vimeo access token (required)
|
22
22
|
# @option config_options [String] :access_token_secret Vimeo access token secret (required)
|
23
23
|
def initialize(config_options={})
|
24
|
-
validate_options(config_options,
|
24
|
+
validate_options(config_options,
|
25
25
|
[:consumer_key, :consumer_secret, :access_token, :access_token_secret])
|
26
|
-
|
26
|
+
|
27
27
|
@client = ::Vimeo::Advanced::Video.new(
|
28
28
|
config_options[:consumer_key],
|
29
29
|
config_options[:consumer_secret],
|
@@ -45,7 +45,7 @@ module ActivePublicResources
|
|
45
45
|
# @example Request
|
46
46
|
# driver = ActivePublicResources::Drivers::Vimeo.new({ .. config options .. })
|
47
47
|
# results = driver.perform_request({ query: 'education' })
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# @example Returns
|
50
50
|
# {
|
51
51
|
# 'items': [
|
@@ -83,7 +83,7 @@ module ActivePublicResources
|
|
83
83
|
def perform_request(request_criteria)
|
84
84
|
request_criteria.validate_presence!([:query])
|
85
85
|
raise StandardError.new("driver has not been initialized properly") unless @client
|
86
|
-
|
86
|
+
|
87
87
|
results = @client.search(request_criteria.query, {
|
88
88
|
:page => request_criteria.page || 1,
|
89
89
|
:per_page => request_criteria.per_page || 25,
|
@@ -8,23 +8,35 @@ module ActivePublicResources
|
|
8
8
|
DRIVER_NAME = "youtube"
|
9
9
|
API_KEY = ENV['YOUTUBE_API_KEY']
|
10
10
|
|
11
|
+
def initialize(config_options={})
|
12
|
+
@default_request_criteria = {}
|
13
|
+
if config_options[:default_request_criteria]
|
14
|
+
@default_request_criteria = config_options[:default_request_criteria]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
def perform_request(request_criteria)
|
12
|
-
request_criteria.
|
19
|
+
request_criteria.set_default_criteria!(@default_request_criteria)
|
20
|
+
unless request_criteria.validate_presence(:query) || request_criteria.validate_presence(:channel)
|
21
|
+
raise ArgumentError "you must specify at least a query or a channel"
|
22
|
+
end
|
23
|
+
|
13
24
|
uri = URI('https://www.googleapis.com/youtube/v3/search')
|
14
25
|
params = {
|
15
|
-
'q'
|
26
|
+
'q' => request_criteria.query,
|
16
27
|
'part' => 'snippet',
|
17
28
|
'type' => 'video',
|
18
|
-
'order'
|
19
|
-
'safeSearch'
|
29
|
+
'order' => sort(request_criteria.sort),
|
30
|
+
'safeSearch' => content_filter(request_criteria.content_filter),
|
20
31
|
'maxResults' => request_criteria.per_page || 25,
|
21
32
|
'key' => API_KEY
|
22
33
|
}
|
34
|
+
|
23
35
|
params['pageToken'] = request_criteria.page if request_criteria.is_a? String
|
24
36
|
params['userIp'] = request_criteria.remote_ip if request_criteria.remote_ip
|
37
|
+
params['channelId'] = channel_id(request_criteria.channel_name) if channel_id(request_criteria.channel_name)
|
25
38
|
|
26
39
|
uri.query = URI.encode_www_form(params)
|
27
|
-
|
28
40
|
res = Net::HTTP.get_response(uri)
|
29
41
|
results = JSON.parse(res.body)
|
30
42
|
return video_details(request_criteria, results)
|
@@ -32,6 +44,27 @@ module ActivePublicResources
|
|
32
44
|
|
33
45
|
private
|
34
46
|
|
47
|
+
def channel_id(channel_name)
|
48
|
+
# we are getting the name of the channel.
|
49
|
+
# we need to figure out its ID
|
50
|
+
if channel_name
|
51
|
+
uri = URI('https://www.googleapis.com/youtube/v3/search')
|
52
|
+
params = {
|
53
|
+
'q' => channel_name,
|
54
|
+
'part' => 'id',
|
55
|
+
'type' => 'channel',
|
56
|
+
'key' => API_KEY
|
57
|
+
}
|
58
|
+
uri.query = URI.encode_www_form(params)
|
59
|
+
res = Net::HTTP.get_response(uri)
|
60
|
+
results = JSON.parse(res.body)
|
61
|
+
return results['items'].first['id']['channelId'] unless results['items'].empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
|
35
68
|
def video_details(request_criteria, results)
|
36
69
|
video_ids = results['items'].map { |item| item['id']['videoId']}
|
37
70
|
uri = URI('https://www.googleapis.com/youtube/v3/videos')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActivePublicResources
|
2
2
|
class RequestCriteria
|
3
3
|
include ::ActiveModel::Serialization
|
4
|
-
|
4
|
+
|
5
5
|
SORTS = [
|
6
6
|
SORT_RELEVANCE = 'relevance',
|
7
7
|
SORT_RECENT = 'recent',
|
@@ -13,7 +13,7 @@ module ActivePublicResources
|
|
13
13
|
CONTENT_FILTER_STRICT = 'strict'
|
14
14
|
]
|
15
15
|
|
16
|
-
attr_accessor :query, :page, :per_page, :content_filter, :sort, :folder, :remote_ip
|
16
|
+
attr_accessor :query, :page, :per_page, :content_filter, :sort, :folder, :remote_ip, :channel_name
|
17
17
|
|
18
18
|
def initialize(args={})
|
19
19
|
args.each do |k,v|
|
@@ -41,6 +41,16 @@ module ActivePublicResources
|
|
41
41
|
@content_filter = val
|
42
42
|
end
|
43
43
|
|
44
|
+
def validate_presence(attr_name, *attr_names)
|
45
|
+
attr_names.unshift(attr_name)
|
46
|
+
attr_names.each do |k|
|
47
|
+
if instance_variable_get("@#{k}").blank?
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
44
54
|
def validate_presence!(attr_names)
|
45
55
|
attr_names.each do |k|
|
46
56
|
if instance_variable_get("@#{k}").blank?
|
@@ -49,8 +59,14 @@ module ActivePublicResources
|
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
62
|
+
def set_default_criteria!(default_criteria)
|
63
|
+
default_criteria.map do |k, v|
|
64
|
+
instance_variable_set("@#{k}", v) unless validate_presence(k)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
52
68
|
def attributes
|
53
69
|
instance_values
|
54
70
|
end
|
55
71
|
end
|
56
|
-
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,95 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_public_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Berry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 4.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: iso8601
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.8.6
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.8.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: vimeo
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.5.3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.5.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
|
-
description:
|
83
|
+
description: " Normalized searching and browsing of public resources "
|
84
84
|
email:
|
85
85
|
- cavneb@gmail.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
91
|
-
- .rspec
|
92
|
-
- .travis.yml
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
93
|
- Gemfile
|
94
94
|
- Guardfile
|
95
95
|
- LICENSE.txt
|
@@ -162,17 +162,17 @@ require_paths:
|
|
162
162
|
- lib
|
163
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
|
-
- -
|
165
|
+
- - ">="
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- -
|
170
|
+
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.2.
|
175
|
+
rubygems_version: 2.2.3
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Normalized searching and browsing of public resources
|