basic_youtube 1.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.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in basic_youtube.gemspec
4
+ gemspec
5
+ gem 'rspec'
6
+ gem 'httparty'
7
+ gem 'active_support'
8
+ gem 'i18n'
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ basic_youtube (0.0.1)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ active_support (3.0.0)
11
+ activesupport (= 3.0.0)
12
+ activesupport (3.0.0)
13
+ diff-lcs (1.1.3)
14
+ httparty (0.8.3)
15
+ multi_json (~> 1.0)
16
+ multi_xml
17
+ i18n (0.6.0)
18
+ multi_json (1.3.6)
19
+ multi_xml (0.5.1)
20
+ rspec (2.9.0)
21
+ rspec-core (~> 2.9.0)
22
+ rspec-expectations (~> 2.9.0)
23
+ rspec-mocks (~> 2.9.0)
24
+ rspec-core (2.9.0)
25
+ rspec-expectations (2.9.1)
26
+ diff-lcs (~> 1.1.3)
27
+ rspec-mocks (2.9.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ active_support
34
+ basic_youtube!
35
+ httparty
36
+ i18n
37
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Neil Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ # BasicYoutube
2
+
3
+ A basic youtube rails library created to provide access to public data.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'basic_youtube'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install basic_youtube
18
+
19
+ ## Usage
20
+
21
+ > channel = BasicYoutube::Channel.new("BananaNeil")
22
+
23
+
24
+ > video = BasicYoutube::Video.new("VzWnMh-roJE")
25
+
26
+
27
+ ## Channel Responds to the following methods:
28
+
29
+ > channel.age
30
+ > channel.author
31
+ > channel.category
32
+ > channel.company
33
+ > channel.contact_count
34
+ > channel.contacts
35
+ > channel.content
36
+ > channel.description
37
+ > channel.entry
38
+ > channel.favorite_count
39
+ > channel.favorites
40
+ > channel.feed_link
41
+ > channel.first_name
42
+ > channel.gender
43
+ > channel.hours_uploaded
44
+ > channel.id
45
+ > channel.inbox
46
+ > channel.last_web_access
47
+ > channel.link
48
+ > channel.location
49
+ > channel.name
50
+ > channel.new_subscription_videos
51
+ > channel.occupation
52
+ > channel.playlists
53
+ > channel.published
54
+ > channel.pull_videos
55
+ > channel.pull_all_videos
56
+ > channel.pull_raw_videos
57
+ > channel.statistics
58
+ > channel.subscriber_count
59
+ > channel.subscription_count
60
+ > channel.subscriptions
61
+ > channel.thumbnail
62
+ > channel.title
63
+ > channel.total_upload_views
64
+ > channel.updated
65
+ > channel.upload_count
66
+ > channel.uploads
67
+ > channel.uri
68
+ > channel.username
69
+ > channel.video_watch_count
70
+ > channel.view_count
71
+
72
+
73
+ ## Video Responds to the following methods:
74
+
75
+ > video.api_link
76
+ > video.author
77
+ > average_rating
78
+ > video.category
79
+ > video.comments
80
+ > video.content
81
+ > video.description
82
+ > video.direct_link
83
+ > video.dislikes
84
+ > video.duration
85
+ > video.entry
86
+ > video.favorite_count
87
+ > video.group
88
+ > video.hours
89
+ > video.id
90
+ > video.keywords
91
+ > video.likes
92
+ > video.link
93
+ > video.minutes
94
+ > video.mobile_link
95
+ > video.player
96
+ > video.published
97
+ > video.rating
98
+ > video.raw_api_link
99
+ > video.raw_direct_link
100
+ > video.raw_mobile_link
101
+ > video.raw_related_videos
102
+ > video.raw_video_responses
103
+ > video.related_videos
104
+ > video.seconds
105
+ > video.statistics
106
+ > video.thumbnail
107
+ > video.title
108
+ > video.updated
109
+ > video.video_responses
110
+ > video.view_count
111
+ > video.where
112
+
113
+
114
+ ## Contributing
115
+
116
+ 1. Fork it
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
119
+ 4. Push to the branch (`git push origin my-new-feature`)
120
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/basic_youtube/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency "httparty"
6
+
7
+ gem.authors = ["Neil Johnson"]
8
+ gem.email = ["BananaNeil@gmail.com"]
9
+ gem.description = %q{Basic YouTube gem that allows for easy access to public information.}
10
+ gem.summary = %q{Provides easy access to Video views, comments, favorites, etc.., Channel subscribers, total views, channel vews, etc...}
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "basic_youtube"
17
+ gem.require_paths = ["lib","lib/basic_youtube"]
18
+ gem.version = BasicYoutube::VERSION
19
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require "basic_youtube/youtube_object"
3
+ require "basic_youtube/version"
4
+ require "basic_youtube/channel"
5
+ require "basic_youtube/video"
6
+ require 'httparty'
7
+
8
+
9
+ module BasicYoutube
10
+
11
+
12
+ #youtube errors
13
+ class YoutubeError < StandardError; end
14
+ #invalid accounts
15
+ class InvalidAccount < YoutubeError; end
16
+ #invalid videos
17
+ class InvalidVideo < YoutubeError; end
18
+
19
+ end
20
+
21
+ class String
22
+ def number?
23
+ true if Float(self) rescue false
24
+ end
25
+ end
@@ -0,0 +1,87 @@
1
+ require 'httparty'
2
+ module BasicYoutube
3
+ class Channel < YoutubeObject
4
+ include HTTParty
5
+ format :xml
6
+
7
+ VALID_METHODS = [:thumbnail, :id, :published, :updated, :category, :title, :content,
8
+ :link, {:author=>[:name, :uri]}, :age, :company, :description, :feed_link,
9
+ :first_name, :gender, :location, :occupation, {:statistics=> [:last_web_access,
10
+ :subscriber_count, :video_watch_count, :view_count, :total_upload_views]}, :username]
11
+
12
+ def initialize username
13
+ @dynamic_methods = {}
14
+ @username = username
15
+ @entry = nil
16
+ @all_videos=nil
17
+ end
18
+
19
+ def entry
20
+ @entry ||= self.class.call_youtube(@username)["entry"]
21
+ if @dynamic_methods.blank?
22
+ VALID_METHODS.each {|key| recursive_hash_access @dynamic_methods, @entry, key}
23
+ define_feeds
24
+ end
25
+ return @entry
26
+ rescue MultiXml::ParseError
27
+ raise InvalidAccount
28
+ end
29
+
30
+ def pull_videos start=1, max_results=25
31
+ return @all_videos[start-1..start+max_results-1] if @all_videos.present?
32
+ pull_raw_videos(start,max_results).map{|v| BasicYoutube::Video.new(v)}
33
+ end
34
+
35
+ def pull_all_videos
36
+ calls = (upload_count+1)/50
37
+ i = 0
38
+ videos = []
39
+ while i<=calls
40
+ pull_videos(i*50+1, 50).each {|v| videos << v}
41
+ i+=1
42
+ end
43
+ @all_videos = videos
44
+ return videos
45
+ end
46
+
47
+ def pull_raw_videos start=1, max_results=25
48
+ max_results=50 if max_results-start>50
49
+ videos = self.class.call_youtube(@username,"/uploads?start-index=#{start}&max-results=#{max_results}")["feed"]["entry"]
50
+ return max_results==1 ? [videos] : videos
51
+ end
52
+
53
+ def respond_to?(method)
54
+ entry if @dynamic_methods.blank?
55
+ return true if @dynamic_methods.keys.include? method
56
+ super
57
+ end
58
+
59
+ def hours_uploaded
60
+ v=pull_all_videos
61
+ v.map(&:hours).sum
62
+ end
63
+
64
+
65
+ private
66
+
67
+ def self.call_youtube username, nested_route=nil
68
+ base_uri "https://gdata.youtube.com"
69
+ data = get "/feeds/api/users/#{username}#{nested_route}"
70
+ end
71
+
72
+ def method_missing method
73
+ entry if @dynamic_methods.blank?
74
+ @dynamic_methods[method] || super
75
+ end
76
+
77
+
78
+ def define_feeds
79
+ (feeds = [:favorites,:contacts,:inbox,:playlists,:subscriptions,:uploads,:new_subscription_videos]).each do |key|
80
+ single_count = "#{key.to_s.singularize}_count".to_sym
81
+ @dynamic_methods[key] = feed_link[feeds.index(key)]
82
+ @dynamic_methods[single_count] = feed_link[feeds.index(key)]["countHint"].to_i if (send(key)["countHint"].present?)
83
+ end
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module BasicYoutube
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,91 @@
1
+ require 'httparty'
2
+ module BasicYoutube
3
+ class Video < YoutubeObject
4
+ include HTTParty
5
+ format :xml
6
+
7
+ VALID_METHODS = [:comments, :id, :published, :updated, :category, :title, :content, :link,
8
+ :where, {:group => [:category, :content, :description, :keywords,
9
+ :player, :thumbnail, :title, {:duration=>:seconds}]}, :rating, {:statistics =>
10
+ [:favorite_count, :view_count]}]
11
+
12
+ def initialize video
13
+ @dynamic_methods = {}
14
+ @id = video.respond_to?(:keys) ? video["id"].split("/").last : video
15
+ @entry = (video if video.respond_to?(:keys))
16
+ end
17
+
18
+ def id
19
+ @id
20
+ end
21
+
22
+ def dynamic_methods
23
+ h={};@dynamic_methods.each {|k,v| h[v.class].nil? ? h[v.class]=[k] : h[v.class] << k}
24
+ return h
25
+ end
26
+
27
+ def entry
28
+ @entry ||= self.class.call_youtube(@id)["entry"]
29
+ if @dynamic_methods.blank?
30
+ VALID_METHODS.each {|key| recursive_hash_access @dynamic_methods, @entry, key}
31
+ define_links
32
+ end
33
+ return @entry
34
+ rescue MultiXml::ParseError
35
+ raise InvalidVideo
36
+ end
37
+
38
+ def author
39
+ BasicYoutube::Channel.new(entry["author"]["name"])
40
+ end
41
+
42
+ def likes
43
+ average = rating["average"].to_f
44
+ total = rating["numRaters"].to_i
45
+ return (total*(average-1)/4).round
46
+ end
47
+
48
+ def dislikes
49
+ total = rating["numRaters"].to_i
50
+ return total-likes
51
+ end
52
+
53
+ def average_rating
54
+ average = rating["average"].to_f
55
+ end
56
+
57
+ def minutes
58
+ seconds.to_f/60
59
+ end
60
+
61
+ def hours
62
+ minutes/60
63
+ end
64
+
65
+
66
+ private
67
+
68
+ def self.call_youtube top_route, nested_route=nil
69
+ base_uri "https://gdata.youtube.com"
70
+ data = get "/feeds/api/videos/#{top_route}"
71
+ end
72
+
73
+ def method_missing method
74
+ (entry;@dynamic_methods[method]) if @dynamic_methods.blank?
75
+
76
+ return self.class.call_youtube(@dynamic_methods[method].split("videos/").last)["feed"]["entry"] if [:raw_video_responses,:raw_related_videos].include? method
77
+ return send("raw_#{method}").map{|v| BasicYoutube::Video.new(v)} if [:video_responses,:related_videos].include? method
78
+ @dynamic_methods[method] || super
79
+ end
80
+
81
+ def define_links
82
+ (links = [:direct_link,:video_responses,:related_videos,:mobile_link,:api_link]).each do |key|
83
+ single_count = "#{key.to_s.singularize}_count".to_sym
84
+ current_link = link[links.index(key)]["href"] if link.count>links.index(key)
85
+ @dynamic_methods[key] = current_link
86
+ @dynamic_methods["raw_#{key}".to_sym] = current_link
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,29 @@
1
+ module BasicYoutube
2
+ class YoutubeObject
3
+ ############################################
4
+ # Recursively assigns methods to the instance
5
+ # allowing for access to nested attributes of the
6
+ # entry hash, (eg, c.statistics => c.entry['statistics']
7
+ # and c.view_count => c.entry["statistics"]["viewCount"])
8
+
9
+ def recursive_hash_access dynamic_methods, base, key
10
+ if key.respond_to? :keys
11
+ key.each do |k,v|
12
+ recursive_hash_access(dynamic_methods, base, k)
13
+ v=[v] unless v.kind_of?(Array)
14
+ v.each do |v1|
15
+ recursive_hash_access(dynamic_methods, base[k.to_s.camelcase(:lower)], v1)
16
+ end
17
+ end
18
+ else
19
+ value = base[key.to_s.camelcase(:lower)]
20
+ begin
21
+ value = value.number? ? value.to_i : Date.parse(value)
22
+ rescue
23
+ end
24
+ dynamic_methods[key] = value
25
+ end
26
+ end
27
+ ############################################
28
+ end
29
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe BasicYoutube::Channel do
4
+ before do
5
+ @channel = BasicYoutube::Channel.new("BananaNeil")
6
+ @entry = {"entry"=>{"id"=>"http://gdata.youtube.com/feeds/api/users/YsmyStytOHPX9SaGBPda2Q", "published"=>"2008-11-18T06:51:28.000Z", "updated"=>"2012-06-10T13:04:18.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#userProfile"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/channeltypes.cat", "term"=>"DIRECTOR"}], "title"=>"I am a lion, rawr.", "content"=>"Email me = BananaNeil@gmail.com\n\nPage design = http://gemsemaj.deviantart.com/\n\nI am a lion.", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/channel/UCYsmyStytOHPX9SaGBPda2Q"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/YsmyStytOHPX9SaGBPda2Q"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "age"=>"21", "company"=>"Panthera leo.", "description"=>"Essentially, i am a lion. rawr.", "feedLink"=>[{"rel"=>"http://gdata.youtube.com/schemas/2007#user.favorites", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/favorites", "countHint"=>"180"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.contacts", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/contacts", "countHint"=>"2390"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.inbox", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/inbox"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.playlists", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/playlists"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.subscriptions", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/subscriptions", "countHint"=>"318"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.uploads", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/uploads", "countHint"=>"190"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#user.newsubscriptionvideos", "href"=>"https://gdata.youtube.com/feeds/api/users/banananeil/newsubscriptionvideos"}], "firstName"=>"Neil", "gender"=>"m", "hobbies"=>"you.", "hometown"=>"lots of places....", "lastName"=>"Johnson", "location"=>"Portland Oregon, US", "occupation"=>"Lion.", "statistics"=>{"lastWebAccess"=>"2012-05-14T21:15:09.000Z", "subscriberCount"=>"12236", "videoWatchCount"=>"0", "viewCount"=>"237276", "totalUploadViews"=>"1006317"}, "thumbnail"=>{"url"=>"https://i2.ytimg.com/i/YsmyStytOHPX9SaGBPda2Q/1.jpg?v=4f3e1533"}, "username"=>"banananeil"}}
7
+ @channel.class.stub(:call_youtube).and_return(@entry)
8
+ @videos = {"feed"=>{"entry"=>[{"id"=>"http://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs", "published"=>"2012-04-26T22:30:07.000Z", "updated"=>"2012-06-10T10:40:37.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"People", "label"=>"People & Blogs"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"mythbusters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big bang theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"bang"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Adam Savage"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Jamie Hyneman"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"stupid"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"people"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"smart"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"shows"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"science"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lion"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rawr"}], "title"=>"Smart Shows For Dumb People", "content"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"https://m.youtube.com/details?v=h74fp_CiZTs"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil/uploads/h74fp_CiZTs"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "comments"=>{"feedLink"=>{"rel"=>"http://gdata.youtube.com/schemas/2007#comments", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/comments", "countHint"=>"183"}}, "where"=>{"Point"=>{"pos"=>"47.65387 -122.25517"}}, "hd"=>nil, "group"=>{"category"=>"People", "content"=>[{"url"=>"https://www.youtube.com/v/h74fp_CiZTs?version=3&f=user_uploads&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"84", "format"=>"5"}, {"url"=>"rtsp://v2.cache2.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"1"}, {"url"=>"rtsp://v4.cache3.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"6"}], "description"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "keywords"=>"mythbusters, myth, busters, myth busters, big bang theory, big, bang, theory, Adam Savage, Jamie Hyneman, stupid, people, smart, shows, science, lion, rawr", "player"=>{"url"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata_player"}, "thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/0.jpg", "height"=>"360", "width"=>"480", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:21"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:03"}], "title"=>"Smart Shows For Dumb People", "duration"=>{"seconds"=>"84"}}, "rating"=>{"average"=>"4.394958", "max"=>"5", "min"=>"1", "numRaters"=>"357", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"16", "viewCount"=>"8388"}}, {"id"=>"http://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI", "published"=>"2012-04-20T01:39:35.000Z", "updated"=>"2012-06-10T22:13:05.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"People", "label"=>"People & Blogs"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"BananaNeil"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confessions"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confession"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"dark"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"secret"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"secrets"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confessions (film)"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"love"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"life"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lions"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rawr"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Lion (Animal)"}], "title"=>"Confessions 4/19/12", "content"=>"Email confessions to = BananaNeilConfessions@gmail.com\nOther confession videos = http://bit.ly/confessionsBN\nThat kid in my video = http://youtube.com/thatzak (he makes better videos than me)\n\nThis is a video in which i read peoples confessions.", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/watch?v=rHVRKrL_WuI&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"https://m.youtube.com/details?v=rHVRKrL_WuI"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil/uploads/rHVRKrL_WuI"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "comments"=>{"feedLink"=>{"rel"=>"http://gdata.youtube.com/schemas/2007#comments", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/comments", "countHint"=>"218"}}, "hd"=>nil, "group"=>{"category"=>"People", "content"=>[{"url"=>"https://www.youtube.com/v/rHVRKrL_WuI?version=3&f=user_uploads&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"334", "format"=>"5"}, {"url"=>"rtsp://v7.cache1.c.youtube.com/CigLENy73wIaHwniWv-yKlF1rBMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"334", "format"=>"1"}, {"url"=>"rtsp://v1.cache6.c.youtube.com/CigLENy73wIaHwniWv-yKlF1rBMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"334", "format"=>"6"}], "description"=>"Email confessions to = BananaNeilConfessions@gmail.com\nOther confession videos = http://bit.ly/confessionsBN\nThat kid in my video = http://youtube.com/thatzak (he makes better videos than me)\n\nThis is a video in which i read peoples confessions.", "keywords"=>"BananaNeil, Confessions, Confession, dark, secret, secrets, Confessions (film), love, life, lions, rawr, Lion (Animal)", "player"=>{"url"=>"https://www.youtube.com/watch?v=rHVRKrL_WuI&feature=youtube_gdata_player"}, "thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/0.jpg", "height"=>"360", "width"=>"480", "time"=>"00:02:47"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:23.500"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:02:47"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:04:10.500"}], "title"=>"Confessions 4/19/12", "duration"=>{"seconds"=>"334"}}, "rating"=>{"average"=>"4.93617", "max"=>"5", "min"=>"1", "numRaters"=>"376", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"53", "viewCount"=>"6549"}}]}}
9
+ end
10
+ describe ".entry" do
11
+ it "should return a hash equal to entry" do
12
+ @channel.entry.should == @entry["entry"]
13
+ end
14
+ end
15
+
16
+ describe ".pull_all_videos" do
17
+ before do
18
+ @channel.class.stub(:call_youtube).and_return(@entry,@videos)
19
+ end
20
+ it "should try to contact youtube once for the entry, and 4 times for the 190 videos" do
21
+ @channel.class.should_receive(:call_youtube).exactly(5).times
22
+ @channel.pull_all_videos
23
+ end
24
+ it "should return an array" do
25
+ @channel.pull_all_videos.class.should == Array
26
+ end
27
+ it "should store the response and only call youtube the minimum number of times" do
28
+ @channel.class.should_receive(:call_youtube).exactly(5).times
29
+ 3.times{@channel.pull_all_videos}
30
+ end
31
+ end
32
+
33
+ describe ".pull_raw_videos" do
34
+ before do
35
+ @channel.class.stub(:call_youtube).and_return(@videos)
36
+ end
37
+ it "should contact youtube" do
38
+ @channel.class.should_receive(:call_youtube)
39
+ @channel.pull_raw_videos
40
+ end
41
+ end
42
+
43
+ {Hash=>[:thumbnail, :author, :statistics, :favorites, :contacts, :inbox, :playlists, :subscriptions, :uploads, :new_subscription_videos],
44
+ String=>[:id, :title, :content, :name, :uri, :company, :description, :first_name, :gender, :location, :occupation, :username],
45
+ Date=>[:published, :updated, :last_web_access],
46
+ Array=>[:category, :link, :feed_link, :pull_raw_videos],
47
+ Fixnum=>[:age, :subscriber_count, :video_watch_count, :view_count, :total_upload_views, :favorite_count, :contact_count, :subscription_count, :upload_count],
48
+ Float=>[:hours_uploaded]}.each do |type,methods|
49
+ methods.each do |method|
50
+ describe ".#{method}" do
51
+ before do
52
+ @channel.class.stub(:call_youtube).and_return([:pull_raw_videos,:hours_uploaded].include?(method) ? @videos : @entry)
53
+ @channel.stub(:pull_all_videos).and_return(@videos["feed"]["entry"].map{|v| BasicYoutube::Video.new(v)}) if method==:hours_uploaded
54
+ end
55
+ it "should return a #{type}" do
56
+ @channel.send(method).class.should == type
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_support/all'
4
+
5
+ require 'basic_youtube' # and any other gems you need
6
+ require 'httparty'
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe BasicYoutube::Video do
4
+ before do
5
+ @video = BasicYoutube::Video.new("h74fp_CiZTs")
6
+ @entry = {"entry"=>{"id"=>"http://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs", "published"=>"2012-04-26T22:30:07.000Z", "updated"=>"2012-06-10T10:40:37.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"People", "label"=>"People & Blogs"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"mythbusters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big bang theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"bang"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Adam Savage"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Jamie Hyneman"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"stupid"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"people"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"smart"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"shows"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"science"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lion"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rawr"}], "title"=>"Smart Shows For Dumb People", "content"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"https://m.youtube.com/details?v=h74fp_CiZTs"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil/uploads/h74fp_CiZTs"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "comments"=>{"feedLink"=>{"rel"=>"http://gdata.youtube.com/schemas/2007#comments", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/comments", "countHint"=>"183"}}, "where"=>{"Point"=>{"pos"=>"47.65387 -122.25517"}}, "hd"=>nil, "group"=>{"category"=>"People", "content"=>[{"url"=>"https://www.youtube.com/v/h74fp_CiZTs?version=3&f=user_uploads&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"84", "format"=>"5"}, {"url"=>"rtsp://v2.cache2.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"1"}, {"url"=>"rtsp://v4.cache3.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"6"}], "description"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "keywords"=>"mythbusters, myth, busters, myth busters, big bang theory, big, bang, theory, Adam Savage, Jamie Hyneman, stupid, people, smart, shows, science, lion, rawr", "player"=>{"url"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata_player"}, "thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/0.jpg", "height"=>"360", "width"=>"480", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:21"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:03"}], "title"=>"Smart Shows For Dumb People", "duration"=>{"seconds"=>"84"}}, "rating"=>{"average"=>"4.394958", "max"=>"5", "min"=>"1", "numRaters"=>"357", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"16", "viewCount"=>"8382"}}}
7
+ @videos = {"feed"=>{"entry"=>[{"id"=>"http://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs", "published"=>"2012-04-26T22:30:07.000Z", "updated"=>"2012-06-10T10:40:37.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"People", "label"=>"People & Blogs"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"mythbusters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"myth busters"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big bang theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"big"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"bang"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"theory"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Adam Savage"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Jamie Hyneman"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"stupid"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"people"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"smart"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"shows"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"science"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lion"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rawr"}], "title"=>"Smart Shows For Dumb People", "content"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"https://m.youtube.com/details?v=h74fp_CiZTs"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil/uploads/h74fp_CiZTs"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "comments"=>{"feedLink"=>{"rel"=>"http://gdata.youtube.com/schemas/2007#comments", "href"=>"https://gdata.youtube.com/feeds/api/videos/h74fp_CiZTs/comments", "countHint"=>"183"}}, "where"=>{"Point"=>{"pos"=>"47.65387 -122.25517"}}, "hd"=>nil, "group"=>{"category"=>"People", "content"=>[{"url"=>"https://www.youtube.com/v/h74fp_CiZTs?version=3&f=user_uploads&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"84", "format"=>"5"}, {"url"=>"rtsp://v2.cache2.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"1"}, {"url"=>"rtsp://v4.cache3.c.youtube.com/CigLENy73wIaHwk7ZaLwpx--hxMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"84", "format"=>"6"}], "description"=>"That girl = http://youtube.com/nerdzrl\nI tweet and tumblr sometimes:\nhttp://BananaNeil.tumblr.com\nhttp://twitter.com/BananaNeil\n\nThis is a video in which I rant about how myth busters doesn't follow proper methods for executing scientific experiments, and how big bang theory is just a show that makes stupid people feel smart", "keywords"=>"mythbusters, myth, busters, myth busters, big bang theory, big, bang, theory, Adam Savage, Jamie Hyneman, stupid, people, smart, shows, science, lion, rawr", "player"=>{"url"=>"https://www.youtube.com/watch?v=h74fp_CiZTs&feature=youtube_gdata_player"}, "thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/0.jpg", "height"=>"360", "width"=>"480", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:21"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:00:42"}, {"url"=>"http://i.ytimg.com/vi/h74fp_CiZTs/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:03"}], "title"=>"Smart Shows For Dumb People", "duration"=>{"seconds"=>"84"}}, "rating"=>{"average"=>"4.394958", "max"=>"5", "min"=>"1", "numRaters"=>"357", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"16", "viewCount"=>"8388"}}, {"id"=>"http://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI", "published"=>"2012-04-20T01:39:35.000Z", "updated"=>"2012-06-10T22:13:05.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"People", "label"=>"People & Blogs"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"BananaNeil"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confessions"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confession"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"dark"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"secret"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"secrets"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Confessions (film)"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"love"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"life"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lions"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rawr"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"Lion (Animal)"}], "title"=>"Confessions 4/19/12", "content"=>"Email confessions to = BananaNeilConfessions@gmail.com\nOther confession videos = http://bit.ly/confessionsBN\nThat kid in my video = http://youtube.com/thatzak (he makes better videos than me)\n\nThis is a video in which i read peoples confessions.", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"https://www.youtube.com/watch?v=rHVRKrL_WuI&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"https://m.youtube.com/details?v=rHVRKrL_WuI"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil/uploads/rHVRKrL_WuI"}], "author"=>{"name"=>"BananaNeil", "uri"=>"https://gdata.youtube.com/feeds/api/users/BananaNeil"}, "comments"=>{"feedLink"=>{"rel"=>"http://gdata.youtube.com/schemas/2007#comments", "href"=>"https://gdata.youtube.com/feeds/api/videos/rHVRKrL_WuI/comments", "countHint"=>"218"}}, "hd"=>nil, "group"=>{"category"=>"People", "content"=>[{"url"=>"https://www.youtube.com/v/rHVRKrL_WuI?version=3&f=user_uploads&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"334", "format"=>"5"}, {"url"=>"rtsp://v7.cache1.c.youtube.com/CigLENy73wIaHwniWv-yKlF1rBMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"334", "format"=>"1"}, {"url"=>"rtsp://v1.cache6.c.youtube.com/CigLENy73wIaHwniWv-yKlF1rBMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"334", "format"=>"6"}], "description"=>"Email confessions to = BananaNeilConfessions@gmail.com\nOther confession videos = http://bit.ly/confessionsBN\nThat kid in my video = http://youtube.com/thatzak (he makes better videos than me)\n\nThis is a video in which i read peoples confessions.", "keywords"=>"BananaNeil, Confessions, Confession, dark, secret, secrets, Confessions (film), love, life, lions, rawr, Lion (Animal)", "player"=>{"url"=>"https://www.youtube.com/watch?v=rHVRKrL_WuI&feature=youtube_gdata_player"}, "thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/0.jpg", "height"=>"360", "width"=>"480", "time"=>"00:02:47"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:23.500"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:02:47"}, {"url"=>"http://i.ytimg.com/vi/rHVRKrL_WuI/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:04:10.500"}], "title"=>"Confessions 4/19/12", "duration"=>{"seconds"=>"334"}}, "rating"=>{"average"=>"4.93617", "max"=>"5", "min"=>"1", "numRaters"=>"376", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"53", "viewCount"=>"6549"}}]}}
8
+ @video.class.stub(:call_youtube).and_return(@entry,@videos)
9
+ end
10
+ describe ".entry" do
11
+ it "should return a hash equal to entry" do
12
+ @video.entry.should == @entry["entry"]
13
+ end
14
+ end
15
+
16
+ describe ".author" do
17
+ it "should return a channel object" do
18
+ @video.author.is_a?(BasicYoutube::Channel).should == true
19
+ end
20
+ end
21
+
22
+ {Hash=>[:comments, :where, :group, :player, :duration, :rating, :statistics],
23
+ String=>[:id, :category, :title, :description, :keywords, :direct_link, :mobile_link,:api_link],
24
+ Date=>[:published, :updated],
25
+ Array=>[:content, :link, :thumbnail, :video_responses, :related_videos, :raw_video_responses, :raw_related_videos],
26
+ Fixnum=>[:favorite_count, :view_count, :likes, :dislikes, :seconds],
27
+ Float=>[:average_rating, :minutes, :hours]}.each do |type,methods|
28
+ methods.each do |method|
29
+ describe ".#{method}" do
30
+ it "should return a #{type}" do
31
+ @video.send(method).class.should == type
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'rating: average=4.394958, numRaters=357' do
38
+ before do
39
+ @video.stub(:rating).and_return({"average"=>"4.394958", "max"=>"5", "min"=>"1", "numRaters"=>"357", "rel"=>"http://schemas.google.com/g/2005#overall"})
40
+ end
41
+ describe ".likes" do
42
+ it "should return 303" do
43
+ @video.likes.should == 303
44
+ end
45
+ end
46
+ describe ".dislikes" do
47
+ it "should return 54" do
48
+ @video.dislikes.should == 54
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'rating: average=4.394958, numRaters=357' do
54
+ before do
55
+ @video.stub(:rating).and_return({"average"=>"4.9250784", "max"=>"5", "min"=>"1", "numRaters"=>"21943", "rel"=>"http://schemas.google.com/g/2005#overall"})
56
+ end
57
+ describe ".likes" do
58
+ it "should return 21532" do
59
+ @video.likes.should == 21532
60
+ end
61
+ end
62
+ describe ".dislikes" do
63
+ it "should return 411" do
64
+ @video.dislikes.should == 411
65
+ end
66
+ end
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basic_youtube
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Neil Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Basic YouTube gem that allows for easy access to public information.
31
+ email:
32
+ - BananaNeil@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - basic_youtube.gemspec
43
+ - lib/.rspec
44
+ - lib/basic_youtube.rb
45
+ - lib/basic_youtube/channel.rb
46
+ - lib/basic_youtube/version.rb
47
+ - lib/basic_youtube/video.rb
48
+ - lib/basic_youtube/youtube_object.rb
49
+ - spec/.rspec
50
+ - spec/channel_spec.rb
51
+ - spec/spec_helper.rb
52
+ - spec/video_spec.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ - lib/basic_youtube
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.23
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Provides easy access to Video views, comments, favorites, etc.., Channel
78
+ subscribers, total views, channel vews, etc...
79
+ test_files:
80
+ - spec/.rspec
81
+ - spec/channel_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/video_spec.rb
84
+ has_rdoc: