Class: YouTubeIt::Client
- Inherits:
-
Object
- Object
- YouTubeIt::Client
- Includes:
- Logging
- Defined in:
- lib/youtube_it/client.rb
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) activity(user = nil, opts = {})
Fetches a user's activity feed.
- - (Object) add_comment(video_id, comment)
- - (Object) add_favorite(video_id)
- - (Object) add_playlist(options)
- - (Object) add_video_to_playlist(playlist_id, video_id)
-
- (Object) comments(video_id, opts = {})
opts is converted to get params and appended to comments gdata api url eg opts = { 'max-results' => 10, 'start-index' => 20 } hash does not play nice with symbols.
- - (Object) current_user
- - (Object) delete_favorite(video_id)
- - (Object) delete_playlist(playlist_id)
- - (Object) delete_video_from_playlist(playlist_id, playlist_entry_id)
- - (Object) dislike_video(video_id)
- - (Object) enable_http_debugging
- - (Object) favorites(user = nil, opts = {})
-
- (Client) initialize(*params)
constructor
Previously this was a logger instance but we now do it globally.
- - (Object) like_video(video_id)
-
- (Object) my_contacts(opts = {})
Get's all of the user's contacts/friends.
-
- (Object) my_video(video_id)
Gets the authenticated users video with the given ID.
-
- (Object) my_videos(opts = {})
Gets all videos.
- - (Object) playlist(playlist_id)
- - (Object) playlists(user = nil)
- - (Object) profile(user = nil)
- - (Object) subscribe_channel(channel_name)
- - (Object) subscriptions(user_id = nil)
- - (Object) unsubscribe_channel(subscription_id)
- - (Object) update_playlist(playlist_id, options)
- - (Object) upload_token(options, nexturl = "http://www.youtube.com/my_videos")
-
- (Object) video_by(vid)
Retrieves a single YouTube video.
- - (Object) video_by_user(user, vid)
- - (Object) video_delete(video_id)
- - (Object) video_update(video_id, opts = {})
- - (Object) video_upload(data, opts = {})
-
- (Object) videos_by(params, options = {})
Retrieves an array of standard feed, custom query, or user videos.
Methods included from Logging
Constructor Details
- (Client) initialize(*params)
Previously this was a logger instance but we now do it globally
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/youtube_it/client.rb', line 6 def initialize *params if params.first.is_a?(Hash) = params.first @user = [:username] @pass = [:password] @dev_key = [:dev_key] @client_id = [:client_id] || "youtube_it" @legacy_debug_flag = [:debug] elsif params.first puts "* warning: the method YouTubeIt::Client.new(user, passwd, dev_key) is deprecated, use YouTubeIt::Client.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')" @user = params.shift @pass = params.shift @dev_key = params.shift @client_id = params.shift || "youtube_it" @legacy_debug_flag = params.shift end end |
Instance Method Details
- (Object) activity(user = nil, opts = {})
Fetches a user's activity feed.
142 143 144 |
# File 'lib/youtube_it/client.rb', line 142 def activity(user = nil, opts = {}) client.get_activity(user, opts) end |
- (Object) add_comment(video_id, comment)
114 115 116 |
# File 'lib/youtube_it/client.rb', line 114 def add_comment(video_id, comment) client.add_comment(video_id, comment) end |
- (Object) add_favorite(video_id)
125 126 127 |
# File 'lib/youtube_it/client.rb', line 125 def add_favorite(video_id) client.add_favorite(video_id) end |
- (Object) add_playlist(options)
154 155 156 |
# File 'lib/youtube_it/client.rb', line 154 def add_playlist() client.add_playlist() end |
- (Object) add_video_to_playlist(playlist_id, video_id)
162 163 164 |
# File 'lib/youtube_it/client.rb', line 162 def add_video_to_playlist(playlist_id, video_id) client.add_video_to_playlist(playlist_id, video_id) end |
- (Object) comments(video_id, opts = {})
opts is converted to get params and appended to comments gdata api url eg opts = { 'max-results' => 10, 'start-index' => 20 } hash does not play nice with symbols
121 122 123 |
# File 'lib/youtube_it/client.rb', line 121 def comments(video_id, opts = {}) client.comments(video_id, opts) end |
- (Object) current_user
198 199 200 |
# File 'lib/youtube_it/client.rb', line 198 def current_user client.get_current_user end |
- (Object) delete_favorite(video_id)
129 130 131 |
# File 'lib/youtube_it/client.rb', line 129 def delete_favorite(video_id) client.delete_favorite(video_id) end |
- (Object) delete_playlist(playlist_id)
170 171 172 |
# File 'lib/youtube_it/client.rb', line 170 def delete_playlist(playlist_id) client.delete_playlist(playlist_id) end |
- (Object) delete_video_from_playlist(playlist_id, playlist_entry_id)
166 167 168 |
# File 'lib/youtube_it/client.rb', line 166 def delete_video_from_playlist(playlist_id, playlist_entry_id) client.delete_video_from_playlist(playlist_id, playlist_entry_id) end |
- (Object) dislike_video(video_id)
178 179 180 |
# File 'lib/youtube_it/client.rb', line 178 def dislike_video(video_id) client.rate_video(video_id, 'dislike') end |
- (Object) enable_http_debugging
194 195 196 |
# File 'lib/youtube_it/client.rb', line 194 def enable_http_debugging client.enable_http_debugging end |
- (Object) favorites(user = nil, opts = {})
133 134 135 |
# File 'lib/youtube_it/client.rb', line 133 def favorites(user = nil, opts = {}) client.favorites(user, opts) end |
- (Object) like_video(video_id)
174 175 176 |
# File 'lib/youtube_it/client.rb', line 174 def like_video(video_id) client.rate_video(video_id, 'like') end |
- (Object) my_contacts(opts = {})
Get's all of the user's contacts/friends.
213 214 215 |
# File 'lib/youtube_it/client.rb', line 213 def my_contacts(opts = {}) client.get_my_contacts(opts) end |
- (Object) my_video(video_id)
Gets the authenticated users video with the given ID. It may be private.
203 204 205 |
# File 'lib/youtube_it/client.rb', line 203 def my_video(video_id) client.get_my_video(video_id) end |
- (Object) my_videos(opts = {})
Gets all videos
208 209 210 |
# File 'lib/youtube_it/client.rb', line 208 def my_videos(opts = {}) client.get_my_videos(opts) end |
- (Object) playlist(playlist_id)
146 147 148 |
# File 'lib/youtube_it/client.rb', line 146 def playlist(playlist_id) client.playlist playlist_id end |
- (Object) playlists(user = nil)
150 151 152 |
# File 'lib/youtube_it/client.rb', line 150 def playlists(user = nil) client.playlists(user) end |
- (Object) profile(user = nil)
137 138 139 |
# File 'lib/youtube_it/client.rb', line 137 def profile(user = nil) client.profile(user) end |
- (Object) subscribe_channel(channel_name)
182 183 184 |
# File 'lib/youtube_it/client.rb', line 182 def subscribe_channel(channel_name) client.subscribe_channel(channel_name) end |
- (Object) subscriptions(user_id = nil)
190 191 192 |
# File 'lib/youtube_it/client.rb', line 190 def subscriptions(user_id = nil) client.subscriptions(user_id) end |
- (Object) unsubscribe_channel(subscription_id)
186 187 188 |
# File 'lib/youtube_it/client.rb', line 186 def unsubscribe_channel(subscription_id) client.unsubscribe_channel(subscription_id) end |
- (Object) update_playlist(playlist_id, options)
158 159 160 |
# File 'lib/youtube_it/client.rb', line 158 def update_playlist(playlist_id, ) client.update_playlist(playlist_id, ) end |
- (Object) upload_token(options, nexturl = "http://www.youtube.com/my_videos")
110 111 112 |
# File 'lib/youtube_it/client.rb', line 110 def upload_token(, nexturl = "http://www.youtube.com/my_videos") client.get_upload_token(, nexturl) end |
- (Object) video_by(vid)
Retrieves a single YouTube video.
Parameters
vid<String>:: The ID or URL of the video that you'd like to retrieve.
user<String>:: The user that uploaded the video that you'd like to retrieve.
Returns
YouTubeIt::Model::Video
86 87 88 89 90 |
# File 'lib/youtube_it/client.rb', line 86 def video_by(vid) video_id = vid =~ /^http/ ? vid : "http://gdata.youtube.com/feeds/api/videos/#{vid}?v=2#{@dev_key ? '&key='+@dev_key : ''}" parser = YouTubeIt::Parser::VideoFeedParser.new(video_id) parser.parse end |
- (Object) video_by_user(user, vid)
92 93 94 95 96 |
# File 'lib/youtube_it/client.rb', line 92 def video_by_user(user, vid) video_id = "http://gdata.youtube.com/feeds/api/users/#{user}/uploads/#{vid}?v=2#{@dev_key ? '&key='+@dev_key : ''}" parser = YouTubeIt::Parser::VideoFeedParser.new(video_id) parser.parse end |
- (Object) video_delete(video_id)
106 107 108 |
# File 'lib/youtube_it/client.rb', line 106 def video_delete(video_id) client.delete(video_id) end |
- (Object) video_update(video_id, opts = {})
102 103 104 |
# File 'lib/youtube_it/client.rb', line 102 def video_update(video_id, opts = {}) client.update(video_id, opts) end |
- (Object) video_upload(data, opts = {})
98 99 100 |
# File 'lib/youtube_it/client.rb', line 98 def video_upload(data, opts = {}) client.upload(data, opts) end |
- (Object) videos_by(params, options = {})
Retrieves an array of standard feed, custom query, or user videos.
Parameters
If fetching videos for a standard feed:
params<Symbol>:: Accepts a symbol of :top_rated, :top_favorites, :most_viewed,
:most_popular, :most_recent, :most_discussed, :most_linked,
:most_responded, :recently_featured, and :watch_on_mobile.
You can find out more specific information about what each standard feed provides
by visiting: http://code.google.com/apis/youtube/reference.html#Standard_feeds
options<Hash> (optional):: Accepts the options of :time, :page (default is 1),
and :per_page (default is 25). :offset and :max_results
can also be passed for a custom offset.
If fetching videos by tags, categories, query:
params<Hash>:: Accepts the keys :tags, :categories, :query, :order_by,
:author, :racy, :response_format, :video_format, :page (default is 1),
and :per_page(default is 25)
options<Hash>:: Not used. (Optional)
If fetching videos for a particular user:
params<Hash>:: Key of :user with a value of the username.
options<Hash>:: Not used. (Optional)
Returns
YouTubeIt::Response::VideoSearch
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/youtube_it/client.rb', line 51 def videos_by(params, ={}) request_params = params.respond_to?(:to_hash) ? params : request_params[:page] = integer_or_default(request_params[:page], 1) request_params[:dev_key] = @dev_key if @dev_key unless request_params[:max_results] request_params[:max_results] = integer_or_default(request_params[:per_page], 25) end unless request_params[:offset] request_params[:offset] = calculate_offset(request_params[:page], request_params[:max_results] ) end if params.respond_to?(:to_hash) and not params[:user] request = YouTubeIt::Request::VideoSearch.new(request_params) elsif (params.respond_to?(:to_hash) && params[:user]) || (params == :favorites) request = YouTubeIt::Request::UserSearch.new(params, request_params) else request = YouTubeIt::Request::StandardSearch.new(params, request_params) end logger.debug "Submitting request [url=#{request.url}]." if @legacy_debug_flag parser = YouTubeIt::Parser::VideosFeedParser.new(request.url) parser.parse end |