youtube_it 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -68,6 +68,11 @@ Upload videos:
68
68
 
69
69
  client.video_delete("FQK1URcxmb4")
70
70
 
71
+ Profiles
72
+
73
+ You can get a users profile:
74
+
75
+ client.profile(user_id)
71
76
 
72
77
 
73
78
  Comments
@@ -236,4 +241,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
236
241
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
237
242
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
238
243
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
239
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.4.0
@@ -115,8 +115,11 @@ class YouTubeIt
115
115
  client.add_comment(video_id, comment)
116
116
  end
117
117
 
118
- def comments(video_id)
119
- client.comments(video_id)
118
+ # opts is converted to get params and appended to comments gdata api url
119
+ # eg opts = { 'max-results' => 10, 'start-index' => 20 }
120
+ # hash does _not_ play nice with symbols
121
+ def comments(video_id, opts = {})
122
+ client.comments(video_id, opts)
120
123
  end
121
124
 
122
125
  def add_favorite(video_id)
@@ -131,6 +134,10 @@ class YouTubeIt
131
134
  client.favorites
132
135
  end
133
136
 
137
+ def profile(user_id)
138
+ client.profile(user_id)
139
+ end
140
+
134
141
  def playlist(playlist_id)
135
142
  client.playlist playlist_id
136
143
  end
@@ -0,0 +1,11 @@
1
+ class YouTubeIt
2
+ module Model
3
+ class Comment < YouTubeIt::Record
4
+ attr_reader :content, :published, :title, :updated, :url
5
+
6
+ # YouTubeIt::Model::Author:: Information about the YouTube user who owns a piece of video content.
7
+ attr_reader :author
8
+ end
9
+ end
10
+ end
11
+
@@ -4,17 +4,23 @@ class YouTubeIt
4
4
  attr_reader :age
5
5
  attr_reader :books
6
6
  attr_reader :company
7
+ attr_reader :description
7
8
  attr_reader :gender
8
9
  attr_reader :hobbies
9
10
  attr_reader :hometown
11
+ attr_reader :last_login
10
12
  attr_reader :location
13
+ attr_reader :join_date
11
14
  attr_reader :movies
12
15
  attr_reader :music
13
16
  attr_reader :occupation
14
17
  attr_reader :relationship
15
18
  attr_reader :school
16
- attr_reader :description
19
+ attr_reader :subscribers
20
+ attr_reader :upload_views
17
21
  attr_reader :username
22
+ attr_reader :videos_watched
23
+ attr_reader :view_count
18
24
  end
19
25
  end
20
26
  end
@@ -19,6 +19,36 @@ class YouTubeIt
19
19
  end
20
20
  end
21
21
 
22
+ class CommentsFeedParser < FeedParser #:nodoc:
23
+ # return array of comments
24
+ def parse_content(content)
25
+ doc = REXML::Document.new(content.body)
26
+ feed = doc.elements["feed"]
27
+
28
+ comments = []
29
+ feed.elements.each("entry") do |entry|
30
+ comments << parse_entry(entry)
31
+ end
32
+ return comments
33
+ end
34
+
35
+ protected
36
+ def parse_entry(entry)
37
+ author = YouTubeIt::Model::Author.new(
38
+ :name => entry.elements["author"].elements["name"].text,
39
+ :uri => entry.elements["author"].elements["uri"].text
40
+ )
41
+ YouTubeIt::Model::Comment.new(
42
+ :author => author,
43
+ :content => entry.elements["content"].text,
44
+ :published => entry.elements["published"].text,
45
+ :title => entry.elements["title"].text,
46
+ :updated => entry.elements["updated "].text,
47
+ :url => entry.elements["id"].text
48
+ )
49
+ end
50
+ end
51
+
22
52
  class PlaylistFeedParser < FeedParser #:nodoc:
23
53
 
24
54
  def parse_content(content)
@@ -63,6 +93,32 @@ class YouTubeIt
63
93
  end
64
94
  end
65
95
 
96
+ class ProfileFeedParser < FeedParser #:nodoc:
97
+ def parse_content(content)
98
+ xml = REXML::Document.new(content.body)
99
+ entry = xml.elements["entry"] || xml.elements["feed"]
100
+ YouTubeIt::Model::User.new(
101
+ :age => entry.elements["yt:age"] ? entry.elements["yt:age"].text : nil,
102
+ :company => entry.elements["yt:company"] ? entry.elements["yt:company"].text : nil,
103
+ :gender => entry.elements["yt:gender"] ? entry.elements["yt:gender"].text : nil,
104
+ :hobbies => entry.elements["yt:hobbies"] ? entry.elements["yt:hobbies"].text : nil,
105
+ :hometown => entry.elements["yt:hometown"] ? entry.elements["yt:hometown"].text : nil,
106
+ :location => entry.elements["yt:location"] ? entry.elements["yt:location"].text : nil,
107
+ :last_login => entry.elements["yt:statistics"].attributes["lastWebAccess"],
108
+ :join_date => entry.elements["published"] ? entry.elements["published"].text : nil,
109
+ :movies => entry.elements["yt:movies"] ? entry.elements["yt:movies"].text : nil,
110
+ :music => entry.elements["yt:music"] ? entry.elements["yt:music"].text : nil,
111
+ :occupation => entry.elements["yt:occupation"] ? entry.elements["yt:occupation"].text : nil,
112
+ :relationship => entry.elements["yt:relationship"] ? entry.elements["yt:relationship"].text : nil,
113
+ :school => entry.elements["yt:school"] ? entry.elements["yt:school"].text : nil,
114
+ :subscribers => entry.elements["yt:statistics"].attributes["subscriberCount"],
115
+ :videos_watched => entry.elements["yt:statistics"].attributes["videoWatchCount"],
116
+ :view_count => entry.elements["yt:statistics"].attributes["viewCount"],
117
+ :upload_views => entry.elements["yt:statistics"].attributes["totalUploadViews"]
118
+ )
119
+ end
120
+ end
121
+
66
122
  class VideoFeedParser < FeedParser #:nodoc:
67
123
 
68
124
  def parse_content(content)
@@ -209,12 +209,14 @@ class YouTubeIt
209
209
  {:code => response.code, :body => response.body}
210
210
  end
211
211
 
212
- def comments(video_id)
213
- comment_url = "/feeds/api/videos/%s/comments" % video_id
212
+ def comments(video_id, opts = {})
213
+ comment_url = "/feeds/api/videos/%s/comments?" % video_id
214
+ comment_url << opts.collect { |k,p| [k,p].join '=' }.join('&')
214
215
  http_connection do |session|
215
216
  response = session.get(comment_url)
216
217
  raise_on_faulty_response(response)
217
218
  {:code => response.code, :body => response.body}
219
+ return YouTubeIt::Parser::CommentsFeedParser.new(response).parse
218
220
  end
219
221
  end
220
222
 
@@ -261,6 +263,15 @@ class YouTubeIt
261
263
  return true
262
264
  end
263
265
 
266
+ def profile(user_id)
267
+ profile_url = "/feeds/api/users/%s?v=2" % user_id
268
+ http_connection do |session|
269
+ response = session.get(profile_url)
270
+ raise_on_faulty_response(response)
271
+ return YouTubeIt::Parser::ProfileFeedParser.new(response).parse
272
+ end
273
+ end
274
+
264
275
  def playlist(playlist_id)
265
276
  playlist_url = "/feeds/api/playlists/%s?v=2" % playlist_id
266
277
  http_connection do |session|
@@ -589,4 +600,4 @@ class YouTubeIt
589
600
  end
590
601
  end
591
602
  end
592
- end
603
+ end
data/lib/youtube_it.rb CHANGED
@@ -51,6 +51,7 @@ end
51
51
  parser
52
52
  model/author
53
53
  model/category
54
+ model/comment
54
55
  model/contact
55
56
  model/content
56
57
  model/playlist
@@ -65,4 +66,4 @@ end
65
66
  request/video_search
66
67
  response/video_search
67
68
  chain_io
68
- ).each{|m| require File.dirname(__FILE__) + '/youtube_it/' + m }
69
+ ).each{|m| require File.dirname(__FILE__) + '/youtube_it/' + m }
Binary file
data/test/test_client.rb CHANGED
@@ -233,7 +233,7 @@ class TestClient < Test::Unit::TestCase
233
233
  def test_should_add_new_comment
234
234
  video_id ="H1TrfM3xbgc"
235
235
  @client.add_comment(video_id, "test comment")
236
- comment = @client.comments(video_id)[:body]
236
+ comment = @client.comments(video_id).first.content
237
237
  assert comment.match(/test comment/)
238
238
  end
239
239
 
data/youtube_it.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{youtube_it}
8
- s.version = "1.3.1"
8
+ s.version = "1.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["chebyte", "kylejginavan"]
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/youtube_it/client.rb",
28
28
  "lib/youtube_it/model/author.rb",
29
29
  "lib/youtube_it/model/category.rb",
30
+ "lib/youtube_it/model/comment.rb",
30
31
  "lib/youtube_it/model/contact.rb",
31
32
  "lib/youtube_it/model/content.rb",
32
33
  "lib/youtube_it/model/playlist.rb",
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
43
44
  "lib/youtube_it/request/video_upload.rb",
44
45
  "lib/youtube_it/response/video_search.rb",
45
46
  "lib/youtube_it/version.rb",
47
+ "pkg/youtube_it-1.3.1.gem",
46
48
  "test/files/youtube_video_response.xml",
47
49
  "test/helper.rb",
48
50
  "test/test.mov",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: youtube_it
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.1
5
+ version: 1.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - chebyte
@@ -56,6 +56,7 @@ files:
56
56
  - lib/youtube_it/client.rb
57
57
  - lib/youtube_it/model/author.rb
58
58
  - lib/youtube_it/model/category.rb
59
+ - lib/youtube_it/model/comment.rb
59
60
  - lib/youtube_it/model/contact.rb
60
61
  - lib/youtube_it/model/content.rb
61
62
  - lib/youtube_it/model/playlist.rb
@@ -72,6 +73,7 @@ files:
72
73
  - lib/youtube_it/request/video_upload.rb
73
74
  - lib/youtube_it/response/video_search.rb
74
75
  - lib/youtube_it/version.rb
76
+ - pkg/youtube_it-1.3.1.gem
75
77
  - test/files/youtube_video_response.xml
76
78
  - test/helper.rb
77
79
  - test/test.mov