punndit_youtube 0.0.5 → 0.0.6

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.
@@ -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
  #
@@ -1,9 +1,7 @@
1
1
  module PunnditYoutube
2
2
  class Model
3
3
  class User < PunnditYoutube::Record
4
- def playlists
5
-
6
- end
4
+ attr_reader :name, :uri, :userID, :playlists
7
5
  end
8
6
  end
9
7
  end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module PunnditYoutube
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -6,13 +6,15 @@ class TestClient
6
6
  end
7
7
 
8
8
  def should_find_video videoID
9
- client = PunnditYoutube::Client.new
10
- client.single_video(videoID)
9
+ @client.single_video(videoID)
11
10
  end
12
11
 
13
12
  def should_find_playlist playlistID
14
- client = PunnditYoutube::Client.new
15
- client.playlist(playlistID)
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
@@ -13,4 +13,10 @@ describe PunnditYoutube do
13
13
  playlist.title.should_not be_empty
14
14
  end
15
15
 
16
+ it "should find playlists for user" do
17
+ client = TestClient.new
18
+ user = client.should_find_playlist_for_user("punndit")
19
+ user.playlists.should_not be_empty
20
+ end
21
+
16
22
  end
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: