Skip to content

Loading…

add_comment method now returns parsed comment from API (with youtube unique_id) #96

Merged
merged 1 commit into from

2 participants

@jarthod

Totally backward compatible, only adding a new value to the returned hash.

@kylejginavan kylejginavan merged commit a74f63e into kylejginavan:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 29, 2012
  1. @jarthod
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 4 deletions.
  1. +5 −0 lib/youtube_it/parser.rb
  2. +2 −2 lib/youtube_it/request/video_upload.rb
  3. +17 −2 test/test_client.rb
View
5 lib/youtube_it/parser.rb
@@ -17,6 +17,11 @@ def parse
parse_content @content
end
+ def parse_single_entry
+ doc = Nokogiri::XML(@content)
+ parse_entry(doc.at("entry") || doc)
+ end
+
def parse_videos
doc = Nokogiri::XML(@content)
videos = []
View
4 lib/youtube_it/request/video_upload.rb
@@ -195,8 +195,8 @@ def add_comment(video_id, comment, opts = {})
comment_body = comment_xml_for(:comment => comment, :reply_to => reply_to_url(video_id, reply_to))
comment_url = "/feeds/api/videos/%s/comments" % video_id
response = yt_session.post(comment_url, comment_body)
-
- return {:code => response.status, :body => response.body}
+ comment = YouTubeIt::Parser::CommentsFeedParser.new(response.body).parse_single_entry
+ return {:code => response.status, :body => response.body, :comment => comment}
end
def delete_comment(video_id, comment_id)
View
19 test/test_client.rb
@@ -258,15 +258,19 @@ def test_should_upload_private_video
def test_should_add_comment_and_reply
video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
# Add comment
- @client.add_comment(video.unique_id, "test comment")
+ res = @client.add_comment(video.unique_id, "test comment")
+ assert_equal 201, res[:code]
wait_for_api
comment1 = @client.comments(video.unique_id).first
+ assert_same_comment comment1, res[:comment]
assert_equal "test comment", comment1.content
assert_nil comment1.reply_to
# Add reply
- @client.add_comment(video.unique_id, "reply comment", :reply_to => comment1)
+ res = @client.add_comment(video.unique_id, "reply comment", :reply_to => comment1)
+ assert_equal 201, res[:code]
wait_for_api
comment2 = @client.comments(video.unique_id).find {|c| c.content =~ /reply/}
+ assert_same_comment comment2, res[:comment]
assert_equal "reply comment", comment2.content
assert_equal comment1.unique_id, comment2.reply_to
# Delete comment
@@ -535,6 +539,17 @@ def assert_valid_video (video)
assert_operator ['allowed','moderated','denied'], :include?, video.access_control['comment']
end
+ def assert_same_comment c1, c2
+ assert_equal c1.unique_id, c2.unique_id
+ assert_equal c1.content, c2.content
+ assert_equal c1.published, c2.published
+ assert_equal c1.reply_to, c2.reply_to
+ assert_equal c1.title, c2.title
+ assert_equal c1.updated, c2.updated
+ assert_equal c1.url, c2.url
+ assert_equal c1.author.name, c2.author.name
+ end
+
def assert_valid_url (url)
URI::parse(url)
return true
Something went wrong with that request. Please try again.