punndit_youtube 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,18 @@ module PunnditYoutube
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
#
|
5
|
+
# Retrieves a single playlist
|
5
6
|
#
|
6
|
-
#
|
7
|
+
# === Parameters
|
8
|
+
# username<String>:: The username of the playlist(s) that you'd like to retrieve.
|
9
|
+
#
|
10
|
+
# === Returns
|
11
|
+
# PunnditYoutube::Model::User
|
12
|
+
#
|
7
13
|
def get_playlists(username)
|
8
|
-
|
14
|
+
url = "/feeds/api/users/#{username}/playlists?alt=json&v=2"
|
15
|
+
parser = PunnditYoutube::Parser::UserFeedParser.new(url)
|
16
|
+
parser.parse
|
9
17
|
end
|
10
18
|
|
11
19
|
#
|
@@ -95,6 +95,30 @@ module PunnditYoutube
|
|
95
95
|
end
|
96
96
|
# END PlaylistFeedParser
|
97
97
|
|
98
|
+
class UserFeedParser < FeedParser #:nodoc:
|
99
|
+
def parse_content(response)
|
100
|
+
playlists = []
|
101
|
+
|
102
|
+
json_body = JSON.parse(response.body)
|
103
|
+
json_body['feed']['entry'].each do |x|
|
104
|
+
playlist = PunnditYoutube::Model::Playlist.new(
|
105
|
+
:id => x['id']['$t'],
|
106
|
+
:title => x['title']['$t']
|
107
|
+
)
|
108
|
+
|
109
|
+
playlists.push(playlist)
|
110
|
+
end
|
111
|
+
|
112
|
+
user = PunnditYoutube::Model::User.new(
|
113
|
+
:name => json_body['feed']['author'][0]['name']['$t'],
|
114
|
+
:uri => json_body['feed']['author'][0]['uri']['$t'],
|
115
|
+
:userID => json_body['feed']['author'][0]['yt$userId']['$t'],
|
116
|
+
:playlists => playlists
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
# END UserFeedParser
|
121
|
+
|
98
122
|
class ChannelFeedParser < FeedParser #:nodoc:
|
99
123
|
def parse_content(url)
|
100
124
|
response = Net::HTTP.get_response("gdata.youtube.com", url)
|
data/spec/punndit_helper.rb
CHANGED
@@ -6,13 +6,15 @@ class TestClient
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def should_find_video videoID
|
9
|
-
client
|
10
|
-
client.single_video(videoID)
|
9
|
+
@client.single_video(videoID)
|
11
10
|
end
|
12
11
|
|
13
12
|
def should_find_playlist playlistID
|
14
|
-
client
|
15
|
-
|
13
|
+
@client.playlist(playlistID)
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_find_playlist_for_user username
|
17
|
+
@client.get_playlists(username)
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|