punndit_youtube 0.0.7 → 0.0.8

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,7 +2,7 @@ module PunnditYoutube
2
2
  class Client
3
3
 
4
4
  #
5
- # Retrieves a single playlist
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, :videos
5
- #def videos
6
- #PunnditYoutube::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}?v=2").parse
7
- #end
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, :playlists
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(url)
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
@@ -1,3 +1,3 @@
1
1
  module PunnditYoutube
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -17,4 +17,8 @@ class TestClient
17
17
  @client.get_playlists(username)
18
18
  end
19
19
 
20
+ def should_find_channel_for_user username
21
+ @client.get_channel(username)
22
+ end
23
+
20
24
  end
@@ -19,4 +19,10 @@ describe PunnditYoutube do
19
19
  user.playlists.should_not be_empty
20
20
  end
21
21
 
22
+ it "should find channel for user" do
23
+ client = TestClient.new
24
+ user = client.should_find_channel_for_user("punndit")
25
+ user.videos.should_not be_empty
26
+ end
27
+
22
28
  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.7
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-30 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec