active_public_resources 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,18 @@
|
|
1
|
+
module ActivePublicResources
|
2
|
+
module ResponseTypes
|
3
|
+
class Folder < BaseResponseType
|
4
|
+
attr_accessor :parent_id, :videos, :exercises, :images
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@videos = []
|
9
|
+
@exercises = []
|
10
|
+
@images = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def kind
|
14
|
+
'folder'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActivePublicResources
|
2
|
+
module ResponseTypes
|
3
|
+
class Video < BaseResponseType
|
4
|
+
attr_accessor :thumbnail_url, :url, :duration, :width, :height, :username,
|
5
|
+
:num_views, :num_likes, :num_comments, :created_date
|
6
|
+
|
7
|
+
def kind
|
8
|
+
'video'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext/object/blank"
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
require "active_public_resources/version"
|
5
|
+
require "active_public_resources/client"
|
6
|
+
require "active_public_resources/request_criteria"
|
7
|
+
|
8
|
+
# Drivers
|
9
|
+
require "active_public_resources/driver"
|
10
|
+
require "active_public_resources/driver_response"
|
11
|
+
require "active_public_resources/drivers/vimeo"
|
12
|
+
require "active_public_resources/drivers/youtube"
|
13
|
+
require "active_public_resources/drivers/schooltube"
|
14
|
+
require "active_public_resources/drivers/khan_academy"
|
15
|
+
require "active_public_resources/drivers/quizlet"
|
16
|
+
|
17
|
+
# Return Types
|
18
|
+
require "active_public_resources/base_return_type"
|
19
|
+
require "active_public_resources/return_types/file"
|
20
|
+
require "active_public_resources/return_types/iframe"
|
21
|
+
require "active_public_resources/return_types/image_url"
|
22
|
+
require "active_public_resources/return_types/oembed"
|
23
|
+
require "active_public_resources/return_types/url"
|
24
|
+
|
25
|
+
# Response Types
|
26
|
+
require "active_public_resources/base_response_type"
|
27
|
+
require "active_public_resources/response_types/video"
|
28
|
+
require "active_public_resources/response_types/image"
|
29
|
+
require "active_public_resources/response_types/exercise"
|
30
|
+
require "active_public_resources/response_types/folder"
|
31
|
+
require "active_public_resources/response_types/quiz"
|
32
|
+
|
33
|
+
module ActivePublicResources
|
34
|
+
def self.root
|
35
|
+
File.expand_path '../..', __FILE__
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.symbolize_keys(hash)
|
39
|
+
hash.inject({}){|result, (key, value)|
|
40
|
+
new_key = case key
|
41
|
+
when String then key.to_sym
|
42
|
+
else key
|
43
|
+
end
|
44
|
+
new_value = case value
|
45
|
+
when Hash then symbolize_keys(value)
|
46
|
+
when Array then value.map{ |v| v.is_a?(Hash) ? symbolize_keys(v) : v }
|
47
|
+
else value
|
48
|
+
end
|
49
|
+
result[new_key] = new_value
|
50
|
+
result
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
APR = ActivePublicResources
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Client do
|
4
|
+
|
5
|
+
let(:client) { APR::Client.new(config_data) }
|
6
|
+
let(:criteria) { APR::RequestCriteria.new({ :query => "education" }) }
|
7
|
+
|
8
|
+
describe ".initialize" do
|
9
|
+
it "requires valid config as initialize params" do
|
10
|
+
expect {
|
11
|
+
APR::Client.new
|
12
|
+
}.to raise_error(ArgumentError, "key/value pair must be provided")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "with valid config" do
|
16
|
+
client.initialized_drivers.should include :vimeo
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "vimeo" do
|
21
|
+
it "should perform request", :vcr, :record => :none do
|
22
|
+
results = client.perform_request(:vimeo, criteria)
|
23
|
+
next_criteria = results.next_criteria
|
24
|
+
next_criteria.page.should eq(2)
|
25
|
+
next_criteria.per_page.should eq(25)
|
26
|
+
results.total_items.should eq(141538)
|
27
|
+
results.items.length.should eq(25)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "youtube" do
|
32
|
+
it "should perform request", :vcr, :record => :none do
|
33
|
+
results = client.perform_request(:youtube, criteria)
|
34
|
+
next_criteria = results.next_criteria
|
35
|
+
next_criteria.page.should eq(2)
|
36
|
+
next_criteria.per_page.should eq(25)
|
37
|
+
results.total_items.should eq(1000000)
|
38
|
+
results.items.length.should eq(25)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "shooltube" do
|
43
|
+
it "should perform request", :vcr, :record => :none do
|
44
|
+
results = client.perform_request(:schooltube, criteria)
|
45
|
+
next_criteria = results.next_criteria
|
46
|
+
next_criteria.page.should eq(2)
|
47
|
+
next_criteria.per_page.should eq(25)
|
48
|
+
results.items.length.should eq(25)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "khan_academy" do
|
53
|
+
it "should traverse folders", :vcr, :record => :none do
|
54
|
+
results = client.perform_request(:khan_academy, criteria)
|
55
|
+
results.items.length.should eq(14)
|
56
|
+
|
57
|
+
folder = results.items.first
|
58
|
+
rc_2 = APR::RequestCriteria.new({ folder: folder.id });
|
59
|
+
results_2 = client.perform_request(:khan_academy, rc_2)
|
60
|
+
results_2.items.length.should eq(30)
|
61
|
+
results_2.items.map(&:kind).uniq.should eq(['video'])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "quizlet" do
|
66
|
+
it "should perform request", :vcr, :record => :none do
|
67
|
+
results = client.perform_request(:quizlet, criteria)
|
68
|
+
next_criteria = results.next_criteria
|
69
|
+
next_criteria.page.should eq(2)
|
70
|
+
next_criteria.per_page.should eq(25)
|
71
|
+
results.items.length.should eq(25)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::Driver do
|
4
|
+
|
5
|
+
it "should raises NotImplementedError" do
|
6
|
+
class APR::Drivers::Foo < APR::Drivers::Driver
|
7
|
+
end
|
8
|
+
[:perform_request].each do |mthd|
|
9
|
+
expect {
|
10
|
+
APR::Drivers::Foo.new.send(mthd)
|
11
|
+
}.to raise_error(NotImplementedError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not raise error when methods are overridden" do
|
16
|
+
class APR::Drivers::Foo < APR::Drivers::Driver
|
17
|
+
def perform_request(*args); end
|
18
|
+
end
|
19
|
+
[:perform_request].each do |mthd|
|
20
|
+
expect {
|
21
|
+
APR::Drivers::Foo.new.send(mthd)
|
22
|
+
}.not_to raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#validate_options" do
|
27
|
+
before :each do
|
28
|
+
class APR::Drivers::Foo < APR::Drivers::Driver
|
29
|
+
def initialize(opts={})
|
30
|
+
validate_options(opts, [:a, :b, :c])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise error when options are not valid" do
|
36
|
+
expect {
|
37
|
+
APR::Drivers::Foo.new
|
38
|
+
}.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not raise error when options are valid" do
|
42
|
+
expect {
|
43
|
+
APR::Drivers::Foo.new({ a: 'x', b: 'y', c: 'z' })
|
44
|
+
}.not_to raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::KhanAcademy do
|
4
|
+
|
5
|
+
let(:driver) { APR::Drivers::KhanAcademy.new }
|
6
|
+
|
7
|
+
describe "#perform_request" do
|
8
|
+
it "should get root folders", :vcr, :record => :none do
|
9
|
+
search_criteria = APR::RequestCriteria.new
|
10
|
+
results = driver.perform_request(search_criteria)
|
11
|
+
results.total_items.should eq(14)
|
12
|
+
results.items.length.should eq(14)
|
13
|
+
results.next_criteria.should be_nil
|
14
|
+
|
15
|
+
folder = results.items.first
|
16
|
+
folder.id.should eq("new-and-noteworthy")
|
17
|
+
folder.title.should eq("New and noteworthy")
|
18
|
+
folder.parent_id.should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should get folder: cs", :vcr, :record => :none do
|
22
|
+
search_criteria = APR::RequestCriteria.new(
|
23
|
+
{ folder: "cs" }
|
24
|
+
)
|
25
|
+
results = driver.perform_request(search_criteria)
|
26
|
+
results.total_items.should eq(1)
|
27
|
+
results.items.length.should eq(1)
|
28
|
+
results.next_criteria.should be_nil
|
29
|
+
|
30
|
+
folder = results.items.first
|
31
|
+
folder.id.should eq("programming")
|
32
|
+
folder.title.should eq("Drawing and animation")
|
33
|
+
folder.parent_id.should eq("root")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should get folder: cs/programming", :vcr, :record => :none do
|
37
|
+
search_criteria = APR::RequestCriteria.new(
|
38
|
+
{ folder: "programming" }
|
39
|
+
)
|
40
|
+
results = driver.perform_request(search_criteria)
|
41
|
+
results.total_items.should eq(12)
|
42
|
+
results.items.length.should eq(12)
|
43
|
+
results.next_criteria.should be_nil
|
44
|
+
|
45
|
+
folder = results.items.first
|
46
|
+
folder.id.should eq("intro-to-programming")
|
47
|
+
folder.title.should eq("Intro to programming")
|
48
|
+
folder.parent_id.should eq("cs")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get folder: science/mcat/society-and-culture/social-structures", :vcr, :record => :none do
|
52
|
+
search_criteria = APR::RequestCriteria.new(
|
53
|
+
{ folder: "social-structures" }
|
54
|
+
)
|
55
|
+
results = driver.perform_request(search_criteria)
|
56
|
+
results.total_items.should eq(8)
|
57
|
+
results.items.length.should eq(8)
|
58
|
+
results.next_criteria.should be_nil
|
59
|
+
|
60
|
+
videos = results.items.find_all { |item| item.kind == "video" }
|
61
|
+
videos.length.should be(6)
|
62
|
+
video = videos.first
|
63
|
+
video.kind.should eq("video")
|
64
|
+
video.title.should eq("Institutions")
|
65
|
+
video.description.should match /Institutions are structures of society/
|
66
|
+
video.thumbnail_url.should eq("https://img.youtube.com/vi/9KR1bad76qg/hqdefault.jpg")
|
67
|
+
video.url.should eq("http://www.youtube.com/watch?v=9KR1bad76qg&feature=youtube_gdata_player")
|
68
|
+
video.duration.should eq(207)
|
69
|
+
video.num_views.should eq(0)
|
70
|
+
video.num_likes.should eq(0)
|
71
|
+
video.num_comments.should eq(0)
|
72
|
+
video.created_date.strftime("%Y-%m-%d").should eq("2013-10-10")
|
73
|
+
video.username.should eq("Sydney Brown")
|
74
|
+
|
75
|
+
rt_url = video.return_types[0]
|
76
|
+
rt_url.return_type.should eq('url')
|
77
|
+
rt_url.url.should eq("http://www.youtube.com/watch?v=9KR1bad76qg&feature=youtube_gdata_player")
|
78
|
+
rt_url.title.should eq("Institutions")
|
79
|
+
|
80
|
+
rt_iframe = video.return_types[1]
|
81
|
+
rt_iframe.return_type.should eq('iframe')
|
82
|
+
rt_iframe.url.should eq("//www.youtube.com/embed/9KR1bad76qg?feature=oembed")
|
83
|
+
rt_url.title.should eq("Institutions")
|
84
|
+
|
85
|
+
video.width.should eq(640)
|
86
|
+
video.height.should eq(360)
|
87
|
+
|
88
|
+
exercises = results.items.find_all { |item| item.kind == "exercise" }
|
89
|
+
exercises.length.should be(2)
|
90
|
+
exercise = exercises.first
|
91
|
+
exercise.kind.should eq("exercise")
|
92
|
+
exercise.id.should eq("exd53ad0de")
|
93
|
+
exercise.title.should eq("Social structures - Passage 1")
|
94
|
+
exercise.thumbnail_url.should eq("https://ka-exercise-screenshots.s3.amazonaws.com/social-structures---passage-1_256.png")
|
95
|
+
exercise.url.should eq("http://www.khanacademy.org/exercise/social-structures---passage-1")
|
96
|
+
|
97
|
+
ex_rt_url = exercise.return_types[0]
|
98
|
+
ex_rt_url.return_type.should eq('url')
|
99
|
+
ex_rt_url.url.should eq("http://www.khanacademy.org/exercise/social-structures---passage-1")
|
100
|
+
ex_rt_url.title.should eq("Social structures - Passage 1")
|
101
|
+
|
102
|
+
exercise.return_types
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::Quizlet do
|
4
|
+
|
5
|
+
let(:driver) { APR::Drivers::Quizlet.new(config_data[:quizlet]) }
|
6
|
+
|
7
|
+
describe ".initialize" do
|
8
|
+
it "should throw error when intializing without proper config options" do
|
9
|
+
expect {
|
10
|
+
APR::Drivers::Quizlet.new
|
11
|
+
}.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#perform_request" do
|
16
|
+
it "should raise error when perform_request method is called without a query" do
|
17
|
+
expect {
|
18
|
+
driver.perform_request(APR::RequestCriteria.new)
|
19
|
+
}.to raise_error(StandardError, "must include query")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should perform request", :vcr, :record => :none do
|
23
|
+
search_criteria = APR::RequestCriteria.new({:query => "dogs"})
|
24
|
+
results = driver.perform_request(search_criteria)
|
25
|
+
|
26
|
+
next_criteria = results.next_criteria
|
27
|
+
next_criteria.page.should eq(2)
|
28
|
+
next_criteria.per_page.should eq(25)
|
29
|
+
results.items.length.should eq(25)
|
30
|
+
|
31
|
+
quiz = results.items.first
|
32
|
+
quiz.kind.should eq("quiz")
|
33
|
+
quiz.title.should eq("Dogs")
|
34
|
+
quiz.description.should eq("DOGS, DOGS, DOGS!!!!!!!!")
|
35
|
+
quiz.url.should eq("http://quizlet.com/23752218/dogs-flash-cards/")
|
36
|
+
quiz.created_date.strftime("%Y-%m-%d").should eq("2013-05-25")
|
37
|
+
|
38
|
+
quiz.return_types.map(&:url).should eq([
|
39
|
+
"http://quizlet.com/23752218/dogs-flash-cards/",
|
40
|
+
"https://quizlet.com/23752218/flashcards/embedv2",
|
41
|
+
"https://quizlet.com/23752218/learn/embedv2",
|
42
|
+
"https://quizlet.com/23752218/scatter/embedv2",
|
43
|
+
"https://quizlet.com/23752218/speller/embedv2",
|
44
|
+
"https://quizlet.com/23752218/test/embedv2",
|
45
|
+
"https://quizlet.com/23752218/spacerace/embedv2"
|
46
|
+
])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::Schooltube do
|
4
|
+
|
5
|
+
let(:driver) { APR::Drivers::Schooltube.new }
|
6
|
+
|
7
|
+
describe "#perform_request" do
|
8
|
+
it "should raise error when perform_request method is called without a query" do
|
9
|
+
expect {
|
10
|
+
driver.perform_request(APR::RequestCriteria.new)
|
11
|
+
}.to raise_error(StandardError, "must include query")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should perform request", :vcr, :record => :none do
|
15
|
+
search_criteria = APR::RequestCriteria.new({:query => "education"})
|
16
|
+
results = driver.perform_request(search_criteria)
|
17
|
+
next_criteria = results.next_criteria
|
18
|
+
next_criteria.page.should eq(2)
|
19
|
+
next_criteria.per_page.should eq(25)
|
20
|
+
results.items.length.should eq(25)
|
21
|
+
|
22
|
+
item = results.items.first
|
23
|
+
item.kind.should eq("video")
|
24
|
+
item.title.should eq("Fun - Educational School Trips - Call American Tours & Travel")
|
25
|
+
item.description.should match /customizing your next student/
|
26
|
+
item.thumbnail_url.should eq("http://schooltube-thumbnails.s3.amazonaws.com/c5/c3/dd/df/9c/f6/c5c3dddf-9cf6-c0e5-db1f-898f89c301e2.jpg")
|
27
|
+
item.url.should eq("http://bit.ly/pk3Sxs")
|
28
|
+
item.duration.should eq(102)
|
29
|
+
item.num_views.should eq(3513)
|
30
|
+
item.num_likes.should eq(0)
|
31
|
+
item.num_comments.should eq(0)
|
32
|
+
item.created_date.strftime("%Y-%m-%d").should eq("2009-11-12")
|
33
|
+
item.username.should eq("StudentGroupTravel")
|
34
|
+
|
35
|
+
rt_url = item.return_types[0]
|
36
|
+
rt_url.return_type.should eq('url')
|
37
|
+
rt_url.url.should eq("http://bit.ly/pk3Sxs")
|
38
|
+
rt_url.title.should eq("Fun - Educational School Trips - Call American Tours & Travel")
|
39
|
+
|
40
|
+
rt_iframe = item.return_types[1]
|
41
|
+
rt_iframe.return_type.should eq('iframe')
|
42
|
+
rt_iframe.url.should eq("//www.schooltube.com/embed/60f374fdba394a70b4ad")
|
43
|
+
rt_url.title.should eq("Fun - Educational School Trips - Call American Tours & Travel")
|
44
|
+
|
45
|
+
item.width.should eq(640)
|
46
|
+
item.height.should eq(360)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::Vimeo do
|
4
|
+
|
5
|
+
let(:driver) { APR::Drivers::Vimeo.new(config_data[:vimeo]) }
|
6
|
+
|
7
|
+
describe ".initialize" do
|
8
|
+
it "should throw error when intializing without proper config options" do
|
9
|
+
expect {
|
10
|
+
APR::Drivers::Vimeo.new
|
11
|
+
}.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should build a vimeo client on initialize" do
|
15
|
+
driver.client.should be_an_instance_of(::Vimeo::Advanced::Video)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#perform_request" do
|
20
|
+
it "should raise error when perform_request method is called without a query" do
|
21
|
+
expect {
|
22
|
+
driver.perform_request(APR::RequestCriteria.new)
|
23
|
+
}.to raise_error(StandardError, "must include query")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise error when client has not been set" do
|
27
|
+
driver.instance_variable_set("@client", nil)
|
28
|
+
search_criteria = APR::RequestCriteria.new({:query => "education"})
|
29
|
+
expect {
|
30
|
+
driver.perform_request(search_criteria)
|
31
|
+
}.to raise_error(StandardError, "driver has not been initialized properly")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should perform request", :vcr, :record => :none do
|
35
|
+
search_criteria = APR::RequestCriteria.new({:query => "education"})
|
36
|
+
results = driver.perform_request(search_criteria)
|
37
|
+
next_criteria = results.next_criteria
|
38
|
+
next_criteria.page.should eq(2)
|
39
|
+
next_criteria.per_page.should eq(25)
|
40
|
+
results.total_items.should eq(145819)
|
41
|
+
results.items.length.should eq(25)
|
42
|
+
|
43
|
+
item = results.items.first
|
44
|
+
item.kind.should eq("video")
|
45
|
+
item.title.should eq("Kynect 'education'")
|
46
|
+
item.description.should match /Character Design/
|
47
|
+
item.thumbnail_url.should eq("http://b.vimeocdn.com/ts/440/661/440661028_100.jpg")
|
48
|
+
item.url.should eq("http://vimeo.com/67741947")
|
49
|
+
item.duration.should eq(30)
|
50
|
+
item.num_views.should eq(16593)
|
51
|
+
item.num_likes.should eq(911)
|
52
|
+
item.num_comments.should eq(39)
|
53
|
+
item.created_date.strftime("%Y-%m-%d").should eq("2013-06-05")
|
54
|
+
item.username.should eq("Jens & Anna")
|
55
|
+
|
56
|
+
rt_url = item.return_types[0]
|
57
|
+
rt_url.return_type.should eq('url')
|
58
|
+
rt_url.url.should eq("http://vimeo.com/67741947")
|
59
|
+
rt_url.title.should eq("Kynect 'education'")
|
60
|
+
|
61
|
+
rt_iframe = item.return_types[1]
|
62
|
+
rt_iframe.return_type.should eq('iframe')
|
63
|
+
rt_iframe.url.should eq("//player.vimeo.com/video/67741947")
|
64
|
+
rt_url.title.should eq("Kynect 'education'")
|
65
|
+
|
66
|
+
item.width.should eq(640)
|
67
|
+
item.height.should eq(360)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APR::Drivers::Youtube do
|
4
|
+
|
5
|
+
let(:driver) { APR::Drivers::Youtube.new }
|
6
|
+
|
7
|
+
describe "#perform_request" do
|
8
|
+
it "should raise error when perform_request method is called without a query" do
|
9
|
+
expect {
|
10
|
+
driver.perform_request(APR::RequestCriteria.new)
|
11
|
+
}.to raise_error(StandardError, "must include query")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should perform request", :vcr, :record => :none do
|
15
|
+
search_criteria = APR::RequestCriteria.new({:query => "education"})
|
16
|
+
results = driver.perform_request(search_criteria)
|
17
|
+
next_criteria = results.next_criteria
|
18
|
+
next_criteria.page.should eq(2)
|
19
|
+
next_criteria.per_page.should eq(25)
|
20
|
+
results.total_items.should eq(1000000)
|
21
|
+
results.items.length.should eq(25)
|
22
|
+
|
23
|
+
item = results.items.first
|
24
|
+
item.kind.should eq("video")
|
25
|
+
item.title.should eq("Why I Hate School But Love Education||Spoken Word")
|
26
|
+
item.description.should match /The Latest Spoken Word/
|
27
|
+
item.thumbnail_url.should eq("https://i.ytimg.com/vi/y_ZmM7zPLyI/default.jpg")
|
28
|
+
item.url.should eq("https://www.youtube.com/watch?v=y_ZmM7zPLyI&feature=youtube_gdata_player")
|
29
|
+
item.duration.should eq(368)
|
30
|
+
item.num_views.should eq(4228173)
|
31
|
+
item.num_likes.should eq(101737)
|
32
|
+
item.num_comments.should eq(17837)
|
33
|
+
item.created_date.strftime("%Y-%m-%d").should eq("2012-12-02")
|
34
|
+
item.username.should eq("sulibreezy")
|
35
|
+
item.return_types.count.should eq(2)
|
36
|
+
|
37
|
+
rt_url = item.return_types[0]
|
38
|
+
rt_url.return_type.should eq('url')
|
39
|
+
rt_url.url.should eq("https://www.youtube.com/watch?v=y_ZmM7zPLyI&feature=youtube_gdata_player")
|
40
|
+
rt_url.title.should eq("Why I Hate School But Love Education||Spoken Word")
|
41
|
+
|
42
|
+
rt_iframe = item.return_types[1]
|
43
|
+
rt_iframe.return_type.should eq('iframe')
|
44
|
+
rt_iframe.url.should eq("//www.youtube.com/embed/y_ZmM7zPLyI?feature=oembed")
|
45
|
+
rt_url.title.should eq("Why I Hate School But Love Education||Spoken Word")
|
46
|
+
|
47
|
+
item.width.should eq(640)
|
48
|
+
item.height.should eq(360)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|