Skip to content

Commit

Permalink
ratings (like/dislike) support
Browse files Browse the repository at this point in the history
  • Loading branch information
girishso committed May 24, 2011
1 parent ca6449e commit ccc5f75
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/youtube_it/client.rb
Expand Up @@ -170,6 +170,14 @@ def delete_playlist(playlist_id)
client.delete_playlist(playlist_id)
end

def like_video(video_id)
client.rate_video(video_id, 'like')
end

def dislike_video(video_id)
client.rate_video(video_id, 'dislike')
end

def enable_http_debugging
client.enable_http_debugging
end
Expand Down
23 changes: 23 additions & 0 deletions lib/youtube_it/request/video_upload.rb
Expand Up @@ -417,6 +417,28 @@ def delete_playlist(playlist_id)
return true
end

def rate_video(video_id, rating)
response = nil
rating_body = video_xml_for(:rating => rating)
rating_header = {
"Content-Type" => "application/atom+xml",
"Content-Length" => "#{rating_body.length}",
}
rating_url = "/feeds/api/videos/#{video_id}/ratings"

if @access_token.nil?
rating_header.merge!(authorization_headers)
http_connection do |session|
response = session.post(rating_url, rating_body, rating_header)
end
else
rating_header.merge!(authorization_headers_for_oauth)
response = @access_token.post("http://%s%s" % [base_url, rating_url], rating_body, rating_header)
end
raise_on_faulty_response(response)
{:code => response.code, :body => response.body}
end

def favorites
favorite_url = "/feeds/api/users/default/favorites"
http_connection do |session|
Expand Down Expand Up @@ -572,6 +594,7 @@ def video_xml_for(data)
b.entry(:xmlns => "http://www.w3.org/2005/Atom", 'xmlns:yt' => "http://gdata.youtube.com/schemas/2007") do | m |
m.content(data[:comment]) if data[:comment]
m.id(data[:favorite] || data[:playlist]) if data[:favorite] || data[:playlist]
m.tag!("yt:rating", :value => data[:rating]) if data[:rating]
end.to_s
end

Expand Down

0 comments on commit ccc5f75

Please sign in to comment.