punndit_youtube 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/punndit_youtube/client.rb +17 -1
- data/lib/punndit_youtube/model/playlist.rb +4 -4
- data/lib/punndit_youtube/model/user.rb +10 -1
- data/lib/punndit_youtube/parser.rb +25 -3
- data/lib/punndit_youtube/version.rb +1 -1
- data/spec/punndit_helper.rb +4 -0
- data/spec/punndit_youtube_spec.rb +6 -0
- metadata +2 -2
@@ -2,7 +2,7 @@ module PunnditYoutube
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
#
|
5
|
-
# Retrieves a
|
5
|
+
# Retrieves a all playlists for a specified user
|
6
6
|
#
|
7
7
|
# === Parameters
|
8
8
|
# username<String>:: The username of the playlist(s) that you'd like to retrieve.
|
@@ -45,5 +45,21 @@ module PunnditYoutube
|
|
45
45
|
parser = PunnditYoutube::Parser::VideoFeedParser.new(url)
|
46
46
|
parser.parse
|
47
47
|
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Retrieves a users YouTube Channel videos
|
51
|
+
#
|
52
|
+
# === Parameters
|
53
|
+
# username<String>:: The username/channel that you'd like to retrieve.
|
54
|
+
# NOTE: YouTube channels and user uploads are considered the same thing.
|
55
|
+
#
|
56
|
+
# === Returns
|
57
|
+
# PunnditYoutube::Model::User
|
58
|
+
#
|
59
|
+
def get_channel(username)
|
60
|
+
url = "/feeds/api/users/#{username}/uploads?alt=json&v=2&itemsPerPage=101"
|
61
|
+
parser = PunnditYoutube::Parser::ChannelFeedParser.new(url)
|
62
|
+
parser.parse
|
63
|
+
end
|
48
64
|
end
|
49
65
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module PunnditYoutube
|
2
2
|
class Model
|
3
3
|
class Playlist < PunnditYoutube::Record
|
4
|
-
attr_reader :id, :title, :subtitle, :playlist_id, :author, :thumbnail, :updated_at
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
attr_reader :id, :title, :subtitle, :playlist_id, :author, :thumbnail, :updated_at
|
5
|
+
|
6
|
+
# Array of PunnditYoutube::Model::Videos objects
|
7
|
+
attr_reader :videos
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -1,7 +1,16 @@
|
|
1
1
|
module PunnditYoutube
|
2
2
|
class Model
|
3
3
|
class User < PunnditYoutube::Record
|
4
|
-
attr_reader :name, :uri, :userID
|
4
|
+
attr_reader :name, :uri, :userID
|
5
|
+
|
6
|
+
# Array of PunnditYoutube::Model::Playlist objects
|
7
|
+
attr_reader :playlists
|
8
|
+
|
9
|
+
# Array of PunnditYoutube::Model::Video objects
|
10
|
+
attr_reader :videos
|
11
|
+
|
12
|
+
# Total Number of videos the user has uploaded. This is helpful when doing pageing of results
|
13
|
+
attr_reader :totalResults
|
5
14
|
end
|
6
15
|
end
|
7
16
|
end
|
@@ -120,11 +120,33 @@ module PunnditYoutube
|
|
120
120
|
# END UserFeedParser
|
121
121
|
|
122
122
|
class ChannelFeedParser < FeedParser #:nodoc:
|
123
|
-
def parse_content(
|
124
|
-
response = Net::HTTP.get_response("gdata.youtube.com", url)
|
123
|
+
def parse_content(response)
|
125
124
|
json_body = JSON.parse(response.body)
|
125
|
+
|
126
|
+
videos = []
|
127
|
+
json_body['feed']['entry'].each do |e|
|
128
|
+
video = PunnditYoutube::Model::Video.new(
|
129
|
+
:id => e['media$group']['yt$videoid']['$t'],
|
130
|
+
:title => e['title']['$t'],
|
131
|
+
:description => e['media$group']['media$description']['$t'],
|
132
|
+
:video_url => e['media$group']['media$player']['url'],
|
133
|
+
:thumbnails => e['media$group']['media$thumbnail'],
|
134
|
+
:duration => e['media$group']['yt$duration']['seconds'],
|
135
|
+
:uploaded => e['media$group']['yt$uploaded']['$t'],
|
136
|
+
:uploader_id => e['media$group']['yt$uploaderId']['$t'],
|
137
|
+
:updated_at => e['updated']['$t']
|
138
|
+
)
|
139
|
+
videos.push(video)
|
140
|
+
end
|
141
|
+
|
142
|
+
user = PunnditYoutube::Model::User.new(
|
143
|
+
:name => json_body['feed']['author'][0]['name']['$t'],
|
144
|
+
:uri => json_body['feed']['author'][0]['uri']['$t'],
|
145
|
+
:userID => json_body['feed']['author'][0]['yt$userId']['$t'],
|
146
|
+
:totalResults => json_body['feed']['openSearch$totalResults']['$t'],
|
147
|
+
:videos => videos
|
148
|
+
)
|
126
149
|
|
127
|
-
|
128
150
|
end
|
129
151
|
end
|
130
152
|
# END ChannelFeedParser
|
data/spec/punndit_helper.rb
CHANGED
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.8
|
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-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|