Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reply count to comments #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/youtube_it/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def delete_comment(video_id, comment_id)
def comments(video_id, opts = {})
client.comments(video_id, opts)
end

def comments_with_meta(youtube_id_or_url, opts = {})
client.comments_with_meta(youtube_id_or_url, opts)
end

def add_favorite(video_id)
client.add_favorite(video_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube_it/model/comment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class YouTubeIt
module Model
class Comment < YouTubeIt::Record
attr_reader :content, :published, :title, :updated, :url, :reply_to
attr_reader :content, :published, :title, :updated, :url, :reply_to, :reply_count

# YouTubeIt::Model::Author:: Information about the YouTube user who owns a piece of video content.
attr_reader :author
Expand Down
1 change: 1 addition & 0 deletions lib/youtube_it/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def parse_entry(entry)
:updated => entry.at("updated").text,
:url => entry.at("id").text,
:reply_to => parse_reply(entry),
:reply_count => (entry.at("yt|replyCount").text rescue nil),
:channel_id => (entry.at("yt|channelId").text rescue nil),
:gp_user_id => (entry.at("yt|googlePlusUserId").text rescue nil)
)
Expand Down
17 changes: 17 additions & 0 deletions lib/youtube_it/request/video_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ def comments(video_id, opts = {})
return YouTubeIt::Parser::CommentsFeedParser.new(response).parse
end

def comments_with_meta(youtube_id_or_url, opts = {})
url = if youtube_id_or_url.start_with?('http')
youtube_id_or_url
else
comment_url = "/feeds/api/videos/%s/comments?" % youtube_id_or_url
comment_url << opts.collect { |k, p| [k, p].join '=' }.join('&')
end
response = yt_session.get(url)
comments = YouTubeIt::Parser::CommentsFeedParser.new(response).parse
xml = Nokogiri::XML(response.body)

next_link = xml.at(:css, 'link[rel=next]')

url = next_link.nil? ? nil : next_link['href']
{ comments: comments, next_link: url }
end

def add_favorite(video_id)
favorite_body = video_xml_for(:favorite => video_id)
favorite_url = "/feeds/api/users/default/favorites"
Expand Down