nddrylliog_youtube_it 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +38 -0
  3. data/Manifest.txt +37 -0
  4. data/README.rdoc +296 -0
  5. data/Rakefile +21 -0
  6. data/VERSION +1 -0
  7. data/lib/youtube_it.rb +91 -0
  8. data/lib/youtube_it/chain_io.rb +76 -0
  9. data/lib/youtube_it/client.rb +469 -0
  10. data/lib/youtube_it/middleware/faraday_authheader.rb +24 -0
  11. data/lib/youtube_it/middleware/faraday_oauth.rb +21 -0
  12. data/lib/youtube_it/middleware/faraday_oauth2.rb +13 -0
  13. data/lib/youtube_it/middleware/faraday_youtubeit.rb +30 -0
  14. data/lib/youtube_it/model/activity.rb +17 -0
  15. data/lib/youtube_it/model/author.rb +13 -0
  16. data/lib/youtube_it/model/category.rb +11 -0
  17. data/lib/youtube_it/model/comment.rb +16 -0
  18. data/lib/youtube_it/model/contact.rb +19 -0
  19. data/lib/youtube_it/model/content.rb +18 -0
  20. data/lib/youtube_it/model/message.rb +12 -0
  21. data/lib/youtube_it/model/playlist.rb +11 -0
  22. data/lib/youtube_it/model/rating.rb +23 -0
  23. data/lib/youtube_it/model/subscription.rb +7 -0
  24. data/lib/youtube_it/model/thumbnail.rb +17 -0
  25. data/lib/youtube_it/model/user.rb +28 -0
  26. data/lib/youtube_it/model/video.rb +243 -0
  27. data/lib/youtube_it/parser.rb +543 -0
  28. data/lib/youtube_it/record.rb +12 -0
  29. data/lib/youtube_it/request/base_search.rb +76 -0
  30. data/lib/youtube_it/request/error.rb +15 -0
  31. data/lib/youtube_it/request/standard_search.rb +43 -0
  32. data/lib/youtube_it/request/user_search.rb +47 -0
  33. data/lib/youtube_it/request/video_search.rb +105 -0
  34. data/lib/youtube_it/request/video_upload.rb +552 -0
  35. data/lib/youtube_it/response/video_search.rb +41 -0
  36. data/lib/youtube_it/version.rb +4 -0
  37. data/test/files/recorded_response.xml +1 -0
  38. data/test/files/youtube_video_response.xml +53 -0
  39. data/test/helper.rb +9 -0
  40. data/test/test.mov +0 -0
  41. data/test/test_chain_io.rb +63 -0
  42. data/test/test_client.rb +504 -0
  43. data/test/test_field_search.rb +48 -0
  44. data/test/test_video.rb +48 -0
  45. data/test/test_video_feed_parser.rb +264 -0
  46. data/test/test_video_search.rb +147 -0
  47. data/youtube_it.gemspec +95 -0
  48. metadata +149 -0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'webmock', '~> 1.7.10', :group => :test
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ youtube_it (2.1.4)
5
+ builder
6
+ faraday (~> 0.7.3)
7
+ oauth (~> 0.4.4)
8
+ oauth2 (~> 0.5.2)
9
+ simple_oauth (~> 0.1.5)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ addressable (2.2.7)
15
+ builder (3.0.0)
16
+ crack (0.3.1)
17
+ faraday (0.7.6)
18
+ addressable (~> 2.2)
19
+ multipart-post (~> 1.1)
20
+ rack (~> 1.1)
21
+ multi_json (1.1.0)
22
+ multipart-post (1.1.5)
23
+ oauth (0.4.5)
24
+ oauth2 (0.5.2)
25
+ faraday (~> 0.7)
26
+ multi_json (~> 1.0)
27
+ rack (1.4.1)
28
+ simple_oauth (0.1.5)
29
+ webmock (1.7.10)
30
+ addressable (~> 2.2, > 2.2.5)
31
+ crack (>= 0.1.7)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ webmock (~> 1.7.10)
38
+ youtube_it!
@@ -0,0 +1,37 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ TODO.txt
6
+ lib/youtube_it.rb
7
+ lib/youtube_it/chain_io.rb
8
+ lib/youtube_it/client.rb
9
+ lib/youtube_it/model/author.rb
10
+ lib/youtube_it/model/category.rb
11
+ lib/youtube_it/model/contact.rb
12
+ lib/youtube_it/model/content.rb
13
+ lib/youtube_it/model/message.rb
14
+ lib/youtube_it/model/playlist.rb
15
+ lib/youtube_it/model/rating.rb
16
+ lib/youtube_it/model/thumbnail.rb
17
+ lib/youtube_it/model/user.rb
18
+ lib/youtube_it/model/video.rb
19
+ lib/youtube_it/parser.rb
20
+ lib/youtube_it/record.rb
21
+ lib/youtube_it/request/base_search.rb
22
+ lib/youtube_it/request/error.rb
23
+ lib/youtube_it/request/standard_search.rb
24
+ lib/youtube_it/request/user_search.rb
25
+ lib/youtube_it/request/video_search.rb
26
+ lib/youtube_it/request/video_upload.rb
27
+ lib/youtube_it/response/video_search.rb
28
+ lib/youtube_it/middleware/faraday_authheader.rb
29
+ lib/youtube_it/middleware/faraday_oauth.rb
30
+ lib/youtube_it/middleware/faraday_youtubeit.rb
31
+ lib/youtube_it/version.rb
32
+ test/helper.rb
33
+ test/test_chain_io.rb
34
+ test/test_client.rb
35
+ test/test_video.rb
36
+ test/test_video_search.rb
37
+
@@ -0,0 +1,296 @@
1
+ == DONATION
2
+
3
+ YOUTUBE_IT is developed by many contributors who are passioned about opensource projects
4
+ and selflessly donate their time and work. Following that spirit your donations to this project
5
+ will be destined to the Tuquito Libre Foundation(http://fundacion.tuquito.org.ar) for developing
6
+ technology projects intended to close the digital gap in Latin America.
7
+
8
+ {<img src=https://www.pledgie.com/campaigns/16746.png?skin_name=chrome>}[http://www.pledgie.com/campaigns/16746]
9
+
10
+ == DESCRIPTION
11
+
12
+ youtube_it is the most complete Ruby client for the YouTube GData API. It provides an easy
13
+ way to access the latest and most complete access to YouTube's video API.
14
+ In comparison with the earlier Youtube interfaces, this new API and
15
+ library offers much-improved flexibility around executing complex search
16
+ queries to obtain well-targeted video search results. In addition, standard video management
17
+ including but not limited to uploading, deleting, updating, like, dislike, ratings and
18
+ comments.
19
+
20
+ == INSTALLATION & SETUP:
21
+ * Create a youtube account.
22
+ * Create a developer key here http://code.google.com/apis/youtube/dashboard.
23
+ * sudo gem install youtube_it
24
+
25
+ Note: youtube_it supports ClientLogin(YouTube account), OAuth or AuthSub authentication methods.
26
+
27
+ == Example Rails 3 App
28
+
29
+ You can get an example how you can use youtube_it with Rails 3 here: http://github.com/chebyte/youtube_it_rails_app_example
30
+
31
+ == DEMO
32
+
33
+ You can see to youtube_it in action here: http://youtube-it.heroku.com
34
+
35
+ == ESTABLISHING A CLIENT
36
+
37
+ Creating a client:
38
+ $ require 'youtube_it'
39
+ $ client = YouTubeIt::Client.new
40
+
41
+ Client with developer key:
42
+ $ client = YouTubeIt::Client.new(:dev_key => "developer_key")
43
+
44
+ Client with youtube account and developer key:
45
+ $ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
46
+
47
+ Client with AuthSub:
48
+ $ client = YouTubeIt::AuthSubClient.new(:token => "token" , :dev_key => "developer_key")
49
+
50
+ Client with OAuth:
51
+ $ client = YouTubeIt::OAuthClient.new("consumer_key", "consumer_secret", "youtube_username", "developer_key")
52
+ $ client.authorize_from_access("access_token", "access_secret")
53
+
54
+ Client with OAuth2:
55
+ $ client = YouTubeIt::OAuth2Client.new(client_access_token: "access_token", client_refresh_token: "refresh_token", client_id: "client_id", client_secret: "client_secret", dev_key: "dev_key", expires_at: "expiration time")
56
+
57
+ If your access token is still valid (be careful, access tokens may only be valid for about 1 hour), you can use the client directly. If you want to refresh the access token using the refresh token just do:
58
+
59
+ $ client.refresh_access_token!
60
+
61
+ == VIDEO QUERIES
62
+
63
+ Note: Each type of client enables searching capabilities.
64
+
65
+ Basic Queries:
66
+ $ client.videos_by(:query => "penguin")
67
+ $ client.videos_by(:query => "penguin", :page => 2, :per_page => 15)
68
+ $ client.videos_by(:query => "penguin", :restriction => "DE")
69
+ $ client.videos_by(:tags => ['tiger', 'leopard'])
70
+ $ client.videos_by(:categories => [:news, :sports])
71
+ $ client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
72
+ $ client.videos_by(:user => 'liz')
73
+ $ client.videos_by(:favorites, :user => 'liz')
74
+ $ client.video_by("FQK1URcxmb4")
75
+ $ client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU")
76
+ $ client.video_by_user("chebyte","FQK1URcxmb4")
77
+
78
+ Standard Queries:
79
+ $ client.videos_by(:most_viewed)
80
+ $ client.videos_by(:most_linked, :page => 3)
81
+ $ client.videos_by(:top_rated, :time => :today)
82
+
83
+ Advanced Queries (with boolean operators OR (either), AND (include), NOT (exclude)):
84
+ $ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
85
+
86
+
87
+ Queries for safeSearch
88
+ The safe_search parameter indicates whether the search results should include restricted content as well as standard content.
89
+ The following values are valid for this parameter: none, moderate(default), strict
90
+
91
+ $ client.videos_by(:query => "penguin", :safe-search => "strict")
92
+
93
+ Fields Parameter(experimental features):
94
+ Return videos more than 1000 views
95
+ $ client.videos_by(:fields => {:view_count => "1000"})
96
+
97
+ Filter by date
98
+ $ client.videos_by(:fields => {:published => ((Date.today)})
99
+ $ client.videos_by(:fields => {:recorded => ((Date.today)})
100
+
101
+ Filter by date with range
102
+ $ client.videos_by(:fields => {:published => ((Date.today - 30)..(Date.today))})
103
+ $ client.videos_by(:fields => {:recorded => ((Date.today - 30)..(Date.today))})
104
+
105
+ == VIDEO MANAGEMENT
106
+
107
+ Note: YouTube account, OAuth or AuthSub enables video management.
108
+
109
+ Upload Video:
110
+ $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
111
+
112
+ Upload Video With A Developer Tag (Note the tags are not immediately available):
113
+ $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')
114
+
115
+ Update Video:
116
+ $ client.video_update("FQK1URcxmb4", :title => "new test",:description => 'new description', :category => 'People',:keywords => %w[cool blah test])
117
+
118
+ Delete Video:
119
+ $ client.video_delete("FQK1URcxmb4")
120
+
121
+ My Videos:
122
+ $ client.my_videos
123
+
124
+ My Video:
125
+ $ client.my_video(video_id)
126
+
127
+ Profile Details:
128
+ $ client.profile(user) #default: current user
129
+
130
+ List Comments:
131
+ $ client.comments(video_id)
132
+
133
+ Add A Comment:
134
+ $ client.add_comment(video_id, "test comment!")
135
+
136
+ List Favorites:
137
+ $ client.favorites(user) # default: current user
138
+
139
+ Add Favorite:
140
+ $ client.add_favorite(video_id)
141
+
142
+ Delete Favorite:
143
+ $ client.delete_favorite(video_id)
144
+
145
+ Like A Video:
146
+ $ client.like_video(video_id)
147
+
148
+ Dislike A Video:
149
+ $ client.dislike_video(video_id)
150
+
151
+ List Subscriptions:
152
+ $ client.subscriptions(user) # default: current user
153
+
154
+ Subscribe To A Channel:
155
+ $ client.subscribe_channel(channel_name)
156
+
157
+ Unsubscribe To A Channel:
158
+ $ client.unsubscribe_channel(subscription_id)
159
+
160
+ List New Subscription Videos:
161
+ $ client.new_subscription_videos(user) # default: current user
162
+
163
+ List Playlists:
164
+ $ client.playlists(user) # default: current user
165
+
166
+ Select Playlist:
167
+ $ client.playlist(playlist_id)
168
+
169
+ Select All Videos From A Playlist:
170
+ $ playlist = client.playlist(playlist_id)
171
+ $ playlist.videos
172
+
173
+ Create Playlist:
174
+ $ playlist = client.add_playlist(:title => "new playlist", :description => "playlist description")
175
+
176
+ Delete Playlist:
177
+ $ client.delete_playlist(playlist_id)
178
+
179
+ Add Video To Playlist:
180
+ $ client.add_video_to_playlist(playlist_id, video_id)
181
+
182
+ Remove Video From Playlist:
183
+ $ client.remove_video_from_playlist(playlist_id, playlist_entry_id)
184
+
185
+ List Related Videos
186
+ $ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded")
187
+ $ video.related.videos
188
+
189
+ Add Response Video
190
+ $ video.add_response(original_video_id, response_video_id)
191
+
192
+ Delete Response Video
193
+ $ video.delete_response(original_video_id, response_video_id)
194
+
195
+ List Response Videos
196
+ $ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded")
197
+ $ video.responses.videos
198
+
199
+
200
+ == ACCESS CONTROL LIST
201
+
202
+ You can give permissions in your videos, for example denied comments, rate, etc...
203
+ you can read more there http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl
204
+ you have available the followings options:
205
+
206
+ * :rate, :comment, :commentVote, :videoRespond, :list, :embed, :syndicate
207
+
208
+ with just two values:
209
+ * allowed or denied
210
+
211
+ Example
212
+
213
+ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
214
+
215
+ * upload video with denied comments
216
+
217
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :comment => "denied")
218
+
219
+
220
+ == Video Upload From Browser:
221
+
222
+ When uploading a video from your browser you need make a form upload with the followings params:
223
+ $ upload_token(params, nexturl)
224
+ params => params like :title => "title", :description => "description", :category => "People", :tags => ["test"]
225
+ nexturl => redirect to this url after upload
226
+
227
+
228
+ Controller
229
+ def upload
230
+ @upload_info = YouTubeIt::Client.new.upload_token(params, videos_url)
231
+ end
232
+
233
+ View (upload.html.erb)
234
+ <% form_tag @upload_info[:url], :multipart => true do %>
235
+ <%= hidden_field_tag :token, @upload_info[:token] %>
236
+ <%= label_tag :file %>
237
+ <%= file_field_tag :file %>
238
+ <%= submit_tag "Upload video" %>
239
+ <% end %>
240
+
241
+ == WIDESCREEN VIDEOS
242
+
243
+ If the videos has support for widescreen:
244
+ $ video.embed_html_with_width(1280)
245
+
246
+ Note: you can specify width or just use the default of 1280.
247
+
248
+ == USING HTML5
249
+
250
+ Now you can embed videos without use flash using html5, usefull for mobiles that not support flash but has html5 browser
251
+
252
+ You can specify these options
253
+ $ video.embed_html5({:class => 'video-player', :id => 'my-video', :width => '425', :height => '350', :frameborder => '1', :url_params => {:option_one => "value", :option_two => "value"}})
254
+
255
+ or just use with default options
256
+ $ video.embed_html5 #default: width: 425, height: 350, frameborder: 0
257
+
258
+ == LOGGING
259
+
260
+ YouTubeIt passes all logs through the logger variable on the class itself. In Rails context, assign the Rails logger to that variable to collect the messages
261
+ (don't forget to set the level to debug):
262
+ $ YouTubeIt.logger = RAILS_DEFAULT_LOGGER
263
+ $ RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
264
+
265
+ == CONTRIBUTORS:
266
+
267
+ * Kyle J. Ginavan.
268
+ * Mauro Torres - http://github.com/chebyte
269
+ * Marko Seppa - https://github.com/mseppae
270
+ * Walter Korman - https://github.com/shaper
271
+ * Shane Vitarana - https://github.com/shanev
272
+
273
+ == LICENSE:
274
+
275
+ MIT License
276
+
277
+ Copyright (c) 2010 Kyle J. Ginavan
278
+
279
+ Permission is hereby granted, free of charge, to any person obtaining
280
+ a copy of this software and associated documentation files (the
281
+ 'Software'), to deal in the Software without restriction, including
282
+ without limitation the rights to use, copy, modify, merge, publish,
283
+ distribute, sublicense, and/or sell copies of the Software, and to
284
+ permit persons to whom the Software is furnished to do so, subject to
285
+ the following conditions:
286
+
287
+ The above copyright notice and this permission notice shall be
288
+ included in all copies or substantial portions of the Software.
289
+
290
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
291
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
292
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
293
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
294
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
295
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
296
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup(:default, :test)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake/testtask'
15
+ Rake::TestTask.new(:test) do |test|
16
+ test.libs << 'test'
17
+ test.pattern = 'test/**/test_*.rb'
18
+ test.verbose = true
19
+ end
20
+
21
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.1.4
@@ -0,0 +1,91 @@
1
+ require 'logger'
2
+ require 'open-uri'
3
+ require 'net/https'
4
+ require 'digest/md5'
5
+ require 'rexml/document'
6
+ require 'builder'
7
+ require 'oauth'
8
+ require 'oauth2'
9
+ require 'faraday'
10
+
11
+ class YouTubeIt
12
+
13
+ # Base error class for the extension
14
+ class Error < RuntimeError
15
+ attr_reader :code
16
+ def initialize(msg, code = 0)
17
+ super(msg)
18
+ @code = code
19
+ end
20
+ end
21
+
22
+ def self.esc(s) #:nodoc:
23
+ CGI.escape(s.to_s)
24
+ end
25
+
26
+ # Set the logger for the library
27
+ def self.logger=(any_logger)
28
+ @logger = any_logger
29
+ end
30
+
31
+ # Get the logger for the library (by default will log to STDOUT). TODO: this is where we grab the Rails logger too
32
+ def self.logger
33
+ @logger ||= create_default_logger
34
+ end
35
+
36
+ def self.adapter=(faraday_adapter)
37
+ @adapter = faraday_adapter
38
+ end
39
+
40
+ def self.adapter
41
+ @adapter ||= Faraday.default_adapter
42
+ end
43
+
44
+ # Gets mixed into the classes to provide the logger method
45
+ module Logging #:nodoc:
46
+
47
+ # Return the base logger set for the library
48
+ def logger
49
+ YouTubeIt.logger
50
+ end
51
+ end
52
+
53
+ private
54
+ def self.create_default_logger
55
+ logger = Logger.new(STDOUT)
56
+ logger.level = Logger::DEBUG
57
+ logger
58
+ end
59
+ end
60
+
61
+ %w(
62
+ version
63
+ client
64
+ record
65
+ parser
66
+ model/author
67
+ model/category
68
+ model/comment
69
+ model/contact
70
+ model/content
71
+ model/message
72
+ model/playlist
73
+ model/rating
74
+ model/subscription
75
+ model/thumbnail
76
+ model/user
77
+ model/video
78
+ model/activity
79
+ request/base_search
80
+ request/error
81
+ request/user_search
82
+ request/standard_search
83
+ request/video_upload
84
+ request/video_search
85
+ response/video_search
86
+ middleware/faraday_authheader.rb
87
+ middleware/faraday_oauth.rb
88
+ middleware/faraday_oauth2.rb
89
+ middleware/faraday_youtubeit.rb
90
+ chain_io
91
+ ).each{|m| require File.dirname(__FILE__) + '/youtube_it/' + m }