Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add_comment method now returns parsed comment from API (with youtube …

…unique_id)
  • Loading branch information...
commit caf9662641132185c4cf0a2133db2e00dc0c3fef 1 parent cae90bd
@jarthod jarthod authored
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

0 comments on commit caf9662

Please sign in to comment.
Something went wrong with that request. Please try again.