active_public_resources 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +24 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +18 -0
- data/README.md +326 -0
- data/Rakefile +7 -0
- data/active_public_resources.gemspec +27 -0
- data/active_public_resources_config.yml.example +10 -0
- data/lib/active_public_resources/base_response_type.rb +11 -0
- data/lib/active_public_resources/base_return_type.rb +17 -0
- data/lib/active_public_resources/client.rb +22 -0
- data/lib/active_public_resources/driver.rb +21 -0
- data/lib/active_public_resources/driver_response.rb +15 -0
- data/lib/active_public_resources/drivers/khan_academy.rb +143 -0
- data/lib/active_public_resources/drivers/quizlet.rb +92 -0
- data/lib/active_public_resources/drivers/schooltube.rb +99 -0
- data/lib/active_public_resources/drivers/vimeo.rb +181 -0
- data/lib/active_public_resources/drivers/youtube.rb +113 -0
- data/lib/active_public_resources/request_criteria.rb +51 -0
- data/lib/active_public_resources/response_types/exercise.rb +11 -0
- data/lib/active_public_resources/response_types/folder.rb +18 -0
- data/lib/active_public_resources/response_types/image.rb +11 -0
- data/lib/active_public_resources/response_types/quiz.rb +11 -0
- data/lib/active_public_resources/response_types/video.rb +12 -0
- data/lib/active_public_resources/return_types/file.rb +11 -0
- data/lib/active_public_resources/return_types/iframe.rb +11 -0
- data/lib/active_public_resources/return_types/image_url.rb +11 -0
- data/lib/active_public_resources/return_types/oembed.rb +11 -0
- data/lib/active_public_resources/return_types/url.rb +11 -0
- data/lib/active_public_resources/version.rb +3 -0
- data/lib/active_public_resources.rb +55 -0
- data/spec/lib/active_public_resources/client_spec.rb +75 -0
- data/spec/lib/active_public_resources/driver_spec.rb +48 -0
- data/spec/lib/active_public_resources/drivers/khan_academy_spec.rb +106 -0
- data/spec/lib/active_public_resources/drivers/quizlet_spec.rb +50 -0
- data/spec/lib/active_public_resources/drivers/schooltube_spec.rb +50 -0
- data/spec/lib/active_public_resources/drivers/vimeo_spec.rb +71 -0
- data/spec/lib/active_public_resources/drivers/youtube_spec.rb +52 -0
- data/spec/lib/active_public_resources/live_client_spec.rb +91 -0
- data/spec/lib/active_public_resources/request_criteria_spec.rb +53 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/vcr/active_public_resources/client/khan_academy_should_traverse_folders.yml +1039 -0
- data/spec/vcr/active_public_resources/client/quizlet_should_perform_request.yml +70 -0
- data/spec/vcr/active_public_resources/client/shooltube_should_perform_request.yml +815 -0
- data/spec/vcr/active_public_resources/client/vimeo_should_perform_request.yml +70 -0
- data/spec/vcr/active_public_resources/client/youtube_should_perform_request.yml +212 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_folder_cs/programming.yml +117 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_folder_cs.yml +72 -0
- 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
- data/spec/vcr/active_public_resources/drivers/khan_academy_driver_perform_request/should_get_root_folders.yml +122 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_cs/programming.yml +120 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_cs.yml +73 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_folder_science/mcat/society_and_culture/social_structures.yml +577 -0
- data/spec/vcr/active_public_resources/drivers/khan_academy_perform_request/should_get_root_folders.yml +119 -0
- data/spec/vcr/active_public_resources/drivers/quizlet_driver_perform_request/should_perform_request.yml +75 -0
- data/spec/vcr/active_public_resources/drivers/quizlet_perform_request/should_perform_request.yml +72 -0
- data/spec/vcr/active_public_resources/drivers/schooltube_driver_perform_request/should_perform_request.yml +815 -0
- data/spec/vcr/active_public_resources/drivers/schooltube_perform_request/should_perform_request.yml +810 -0
- data/spec/vcr/active_public_resources/drivers/vimeo_driver_perform_request/should_perform_request.yml +279 -0
- data/spec/vcr/active_public_resources/drivers/vimeo_perform_request/should_perform_request.yml +70 -0
- data/spec/vcr/active_public_resources/drivers/youtube_driver_perform_request/should_perform_request.yml +212 -0
- data/spec/vcr/active_public_resources/drivers/youtube_perform_request/should_perform_request.yml +209 -0
- metadata +182 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# To run this spec from the command line, use
|
2
|
+
# $ rspec --tag live_api
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe APR::Client, :live_api => true do
|
7
|
+
|
8
|
+
let(:client) { APR::Client.new(config_data) }
|
9
|
+
let(:criteria) { APR::RequestCriteria.new({ :query => "learn" }) }
|
10
|
+
|
11
|
+
describe "Vimeo" do
|
12
|
+
it "performs initial and subsequent requests" do
|
13
|
+
results = nil
|
14
|
+
|
15
|
+
results = client.perform_request(:vimeo, criteria)
|
16
|
+
next_criteria = results.next_criteria
|
17
|
+
next_criteria.page.should eq(2)
|
18
|
+
next_criteria.per_page.should eq(25)
|
19
|
+
results.total_items.should > 25
|
20
|
+
results.items.length.should eq(25)
|
21
|
+
|
22
|
+
next_results = client.perform_request(:vimeo, results.next_criteria)
|
23
|
+
next_results.next_criteria.page.should eq(3)
|
24
|
+
next_results.items.first.id.should_not eq(results.items.first.id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Youtube" do
|
29
|
+
it "performs initial and subsequent requests" do
|
30
|
+
results = nil
|
31
|
+
|
32
|
+
results = client.perform_request(:youtube, criteria)
|
33
|
+
next_criteria = results.next_criteria
|
34
|
+
next_criteria.page.should eq(2)
|
35
|
+
next_criteria.per_page.should eq(25)
|
36
|
+
results.total_items.should > 25
|
37
|
+
results.items.length.should eq(25)
|
38
|
+
|
39
|
+
next_results = client.perform_request(:youtube, results.next_criteria)
|
40
|
+
next_results.next_criteria.page.should eq(3)
|
41
|
+
next_results.items.first.id.should_not eq(results.items.first.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Schooltube" do
|
46
|
+
it "performs initial and subsequent requests" do
|
47
|
+
results = nil
|
48
|
+
|
49
|
+
results = client.perform_request(:schooltube, criteria)
|
50
|
+
next_criteria = results.next_criteria
|
51
|
+
next_criteria.page.should eq(2)
|
52
|
+
next_criteria.per_page.should eq(25)
|
53
|
+
results.items.length.should eq(25)
|
54
|
+
|
55
|
+
next_results = client.perform_request(:schooltube, results.next_criteria)
|
56
|
+
next_results.next_criteria.page.should eq(3)
|
57
|
+
next_results.items.first.id.should_not eq(results.items.first.id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Khan Academy" do
|
62
|
+
it "performs initial and subsequent requests" do
|
63
|
+
results = nil
|
64
|
+
|
65
|
+
root_folder = client.perform_request(:khan_academy, criteria)
|
66
|
+
root_folder.items.length.should eq(14)
|
67
|
+
|
68
|
+
sub_folder = root_folder.items.first
|
69
|
+
rc_2 = APR::RequestCriteria.new({ folder: sub_folder.id });
|
70
|
+
results_2 = client.perform_request(:khan_academy, rc_2)
|
71
|
+
results_2.items.length.should eq(30)
|
72
|
+
results_2.items.map(&:kind).uniq.should eq(['video'])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Quizlet" do
|
77
|
+
it "performs initial and subsequent requests" do
|
78
|
+
results = nil
|
79
|
+
|
80
|
+
results = client.perform_request(:quizlet, criteria)
|
81
|
+
next_criteria = results.next_criteria
|
82
|
+
next_criteria.page.should eq(2)
|
83
|
+
next_criteria.per_page.should eq(25)
|
84
|
+
results.items.length.should eq(25)
|
85
|
+
|
86
|
+
next_results = client.perform_request(:quizlet, results.next_criteria)
|
87
|
+
next_results.next_criteria.page.should eq(3)
|
88
|
+
next_results.items.first.id.should_not eq(results.items.first.id)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::RequestCriteria do
|
4
|
+
|
5
|
+
let(:criteria) { APR::RequestCriteria.new }
|
6
|
+
|
7
|
+
it "should set attrs as values on initialize" do
|
8
|
+
@request_criteria = APR::RequestCriteria.new({
|
9
|
+
:query => "education",
|
10
|
+
:page => 3,
|
11
|
+
:per_page => 15,
|
12
|
+
:sort => APR::RequestCriteria::SORT_RELEVANCE,
|
13
|
+
:content_filter => APR::RequestCriteria::CONTENT_FILTER_NONE
|
14
|
+
})
|
15
|
+
@request_criteria.query.should eq("education")
|
16
|
+
@request_criteria.page.should eq(3)
|
17
|
+
@request_criteria.per_page.should eq(15)
|
18
|
+
@request_criteria.sort.should eq(APR::RequestCriteria::SORT_RELEVANCE)
|
19
|
+
@request_criteria.content_filter.should eq(APR::RequestCriteria::CONTENT_FILTER_NONE)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#validate_options" do
|
23
|
+
it "should raise error when options are not present" do
|
24
|
+
expect {
|
25
|
+
criteria.validate_presence!([:query])
|
26
|
+
}.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not raise error when options are present" do
|
30
|
+
criteria.query = "education"
|
31
|
+
expect {
|
32
|
+
criteria.validate_presence!([:query])
|
33
|
+
}.to_not raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should validate sort" do
|
38
|
+
expect {
|
39
|
+
criteria.sort = "whatever"
|
40
|
+
}.to raise_error(ArgumentError, "is invalid. Must be in [relevance, recent, popular]")
|
41
|
+
|
42
|
+
expect { criteria.sort = APR::RequestCriteria::SORT_RELEVANCE }.to_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should validate sort" do
|
46
|
+
expect {
|
47
|
+
criteria.content_filter = "whatever"
|
48
|
+
}.to raise_error(ArgumentError, "is invalid. Must be in [none, strict]")
|
49
|
+
|
50
|
+
expect { criteria.content_filter = APR::RequestCriteria::CONTENT_FILTER_NONE }.to_not raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.setup
|
8
|
+
rescue LoadError => e
|
9
|
+
puts "Error loading bundler (#{e.message}): \"gem install bundler\" for bundler support."
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'active_public_resources'
|
13
|
+
require 'vcr'
|
14
|
+
require 'pry'
|
15
|
+
|
16
|
+
def config_data
|
17
|
+
yaml_path = File.join(ActivePublicResources.root, 'active_public_resources_config.yml')
|
18
|
+
unless File.exist? yaml_path
|
19
|
+
yaml_path = File.join(ActivePublicResources.root, 'active_public_resources_config.yml.example')
|
20
|
+
end
|
21
|
+
config = YAML::load(File.read(yaml_path))
|
22
|
+
ActivePublicResources.symbolize_keys(config)
|
23
|
+
end
|
24
|
+
|
25
|
+
VCR.configure do |c|
|
26
|
+
c.cassette_library_dir = File.join(ActivePublicResources.root, "spec", "vcr")
|
27
|
+
config_data.each do |driver_name, options|
|
28
|
+
(options || {}).each do |k,v|
|
29
|
+
c.filter_sensitive_data("#{driver_name.upcase}_#{k.upcase}") { v }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
c.allow_http_connections_when_no_cassette = true
|
33
|
+
c.hook_into :webmock
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.filter_run_excluding :live_api => true
|
38
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
39
|
+
config.around(:each, :vcr) do |example|
|
40
|
+
name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
|
41
|
+
options = {}
|
42
|
+
options[:record] = example.metadata[:record] if example.metadata[:record].present?
|
43
|
+
options[:match_requests_on] = example.metadata[:match_requests_on] if example.metadata[:match_requests_on].present?
|
44
|
+
VCR.use_cassette(name, options) { example.call }
|
45
|
+
end
|
46
|
+
end
|