punndit_youtube 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/punndit_youtube/client.rb +3 -1
- data/lib/punndit_youtube/parser.rb +33 -3
- data/lib/punndit_youtube/version.rb +1 -1
- data/punndit_youtube.gemspec +1 -1
- data/spec/punndit_helper.rb +18 -0
- data/spec/punndit_youtube_spec.rb +13 -3
- data/spec/spec_helper.rb +11 -0
- metadata +10 -6
@@ -14,16 +14,46 @@ module PunnditYoutube
|
|
14
14
|
class VideoFeedParser < FeedParser #:nodoc:
|
15
15
|
def parse_content(response)
|
16
16
|
json_body = JSON.parse(response.body)
|
17
|
+
e = json_body['entry']
|
17
18
|
|
18
|
-
|
19
|
+
video = PunnditYoutube::Model::Video.new(
|
20
|
+
:id => e['media$group']['yt$videoid']['$t'],
|
21
|
+
:title => e['title']['$t'],
|
22
|
+
:description => e['media$group']['media$description']['$t'],
|
23
|
+
:comment_url => e['gd$comments']['gd$feedLink']['href'],
|
24
|
+
:video_url => e['media$group']['media$player']['url'],
|
25
|
+
#:keywords => e['mediage$group']['media$keywords']['$t'], if e['mediage$group']['media$keywords']['$t']
|
26
|
+
:thumbnails => e['media$group']['media$thumbnail'],
|
27
|
+
#:aspect_ratio => e['media$group']['yt$aspectRatio']['$t'], if e['media$group']['yt$aspectRatio']['$t']
|
28
|
+
:duration => e['media$group']['yt$duration']['seconds'],
|
29
|
+
:uploaded => e['media$group']['yt$uploaded']['$t'],
|
30
|
+
:uploader_id => e['media$group']['yt$uploaderId']['$t'],
|
31
|
+
:stats => {:favorites => e['yt$statistics']['favoriteCount'], :view_count => e['yt$statistics']['viewCount'], :likes => e['yt$rating']['numLikes'], :dislikes => e['yt$rating']['numDislikes'], :average => e['gd$rating']['average'], :max => e['gd$rating']['max'], :min => e['gd$rating']['min'], :numRaters => e['gd$rating']['numRaters'], :rel => e['gd$rating']['rel']},
|
32
|
+
:updated_at => e['updated']['$t']
|
33
|
+
)
|
19
34
|
end
|
20
35
|
end
|
21
36
|
# END VideoFeedParser
|
22
37
|
|
23
38
|
class VideosFeedParser < FeedParser #:nodoc:
|
24
39
|
def parse_content(response)
|
25
|
-
|
26
|
-
|
40
|
+
e = JSON.parse(response.body)
|
41
|
+
|
42
|
+
video = PunnditYoutube::Model::Video.new(
|
43
|
+
:id => e['media$group']['yt$videoid']['$t'],
|
44
|
+
:title => e['title']['$t'],
|
45
|
+
:description => e['media$group']['media$description']['$t'],
|
46
|
+
:comment_url => e['gd$comments']['gd$feedLink']['href'],
|
47
|
+
:video_url => e['media$group']['media$player']['url'],
|
48
|
+
#:keywords => e['mediage$group']['media$keywords']['$t'], if e['mediage$group']['media$keywords']['$t']
|
49
|
+
:thumbnails => e['media$group']['media$thumbnail'],
|
50
|
+
#:aspect_ratio => e['media$group']['yt$aspectRatio']['$t'], if e['media$group']['yt$aspectRatio']['$t']
|
51
|
+
:duration => e['media$group']['yt$duration']['seconds'],
|
52
|
+
:uploaded => e['media$group']['yt$uploaded']['$t'],
|
53
|
+
:uploader_id => e['media$group']['yt$uploaderId']['$t'],
|
54
|
+
:stats => {:favorites => e['yt$statistics']['favoriteCount'], :view_count => e['yt$statistics']['viewCount'], :likes => e['yt$rating']['numLikes'], :dislikes => e['yt$rating']['numDislikes'], :average => e['gd$rating']['average'], :max => e['gd$rating']['max'], :min => e['gd$rating']['min'], :numRaters => e['gd$rating']['numRaters'], :rel => e['gd$rating']['rel']},
|
55
|
+
:updated_at => e['updated']['$t']
|
56
|
+
)
|
27
57
|
end
|
28
58
|
end
|
29
59
|
# END VideosFeedParser
|
data/punndit_youtube.gemspec
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/punndit_youtube/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["David Slone"]
|
6
6
|
gem.email = ["dbslone@gmail.com"]
|
7
|
-
gem.description = %q{
|
7
|
+
gem.description = %q{punndit_youtube is a Ruby client for parsing the YouTube API v2 using JSON objects. This is a lot cleaner and simpler method than trying to use the XML data provided. This is for simple tasks involving YouTube like getting a Playlist(s), Channel, or single video information. This version does not currently support advances searches on the YouTube API.}
|
8
8
|
gem.summary = %q{Ruby client for the YouTube API v2}
|
9
9
|
gem.homepage = "http://www.punndit.com"
|
10
10
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'punndit_youtube'
|
2
|
+
|
3
|
+
class TestClient
|
4
|
+
def initialize
|
5
|
+
@client = PunnditYoutube::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def should_find_video videoID
|
9
|
+
client = PunnditYoutube::Client.new
|
10
|
+
client.single_video(videoID)
|
11
|
+
end
|
12
|
+
|
13
|
+
def should_find_playlist playlistID
|
14
|
+
client = PunnditYoutube::Client.new
|
15
|
+
client.playlist(playlistID)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,6 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe PunnditYoutube
|
4
|
-
it "should
|
3
|
+
describe PunnditYoutube do
|
4
|
+
it "should find video" do
|
5
|
+
client = TestClient.new
|
6
|
+
video = client.should_find_video("9OEYK60naug")
|
7
|
+
video.title.should_not be_empty
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should find playlist" do
|
11
|
+
client = TestClient.new
|
12
|
+
playlist = client.should_find_playlist("PLA2F6CB53687F34AA")
|
13
|
+
playlist.title.should_not be_empty
|
14
|
+
end
|
5
15
|
|
6
16
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punndit_youtube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,11 +27,11 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.6'
|
30
|
-
description:
|
30
|
+
description: punndit_youtube is a Ruby client for parsing the YouTube API v2 using
|
31
31
|
JSON objects. This is a lot cleaner and simpler method than trying to use the XML
|
32
|
-
data provided.
|
33
|
-
|
34
|
-
|
32
|
+
data provided. This is for simple tasks involving YouTube like getting a Playlist(s),
|
33
|
+
Channel, or single video information. This version does not currently support advances
|
34
|
+
searches on the YouTube API.
|
35
35
|
email:
|
36
36
|
- dbslone@gmail.com
|
37
37
|
executables: []
|
@@ -54,7 +54,9 @@ files:
|
|
54
54
|
- lib/punndit_youtube/record.rb
|
55
55
|
- lib/punndit_youtube/version.rb
|
56
56
|
- punndit_youtube.gemspec
|
57
|
+
- spec/punndit_helper.rb
|
57
58
|
- spec/punndit_youtube_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
58
60
|
homepage: http://www.punndit.com
|
59
61
|
licenses: []
|
60
62
|
post_install_message:
|
@@ -80,4 +82,6 @@ signing_key:
|
|
80
82
|
specification_version: 3
|
81
83
|
summary: Ruby client for the YouTube API v2
|
82
84
|
test_files:
|
85
|
+
- spec/punndit_helper.rb
|
83
86
|
- spec/punndit_youtube_spec.rb
|
87
|
+
- spec/spec_helper.rb
|