chocolate_rain 0.0.1 → 0.0.2
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.
- data/chocolate_rain.gemspec +3 -4
- data/lib/chocolate_rain/daemon.rb +67 -0
- data/lib/chocolate_rain/ftp_files_and_upload.rb +54 -0
- data/lib/chocolate_rain/mail_rain/inbox.rb +39 -0
- data/lib/chocolate_rain/mail_rain/mail_handler.rb +53 -0
- data/lib/chocolate_rain/version.rb +1 -1
- data/lib/chocolate_rain/y_video.rb +49 -0
- data/lib/chocolate_rain.rb +45 -4
- metadata +22 -39
- data/generators/youtube_model/USAGE +0 -3
- data/generators/youtube_model/templates/config.yml +0 -6
- data/generators/youtube_model/templates/model.rb +0 -17
- data/generators/youtube_model/templates/unit_test.rb +0 -7
- data/generators/youtube_model/youtube_model_generator.rb +0 -15
- data/lib/.DS_Store +0 -0
- data/lib/gdata/auth/authsub.rb +0 -161
- data/lib/gdata/auth/clientlogin.rb +0 -102
- data/lib/gdata/client/apps.rb +0 -27
- data/lib/gdata/client/base.rb +0 -182
- data/lib/gdata/client/blogger.rb +0 -28
- data/lib/gdata/client/booksearch.rb +0 -28
- data/lib/gdata/client/calendar.rb +0 -58
- data/lib/gdata/client/contacts.rb +0 -28
- data/lib/gdata/client/doclist.rb +0 -28
- data/lib/gdata/client/finance.rb +0 -28
- data/lib/gdata/client/gbase.rb +0 -28
- data/lib/gdata/client/gmail.rb +0 -28
- data/lib/gdata/client/health.rb +0 -28
- data/lib/gdata/client/notebook.rb +0 -28
- data/lib/gdata/client/photos.rb +0 -29
- data/lib/gdata/client/spreadsheets.rb +0 -28
- data/lib/gdata/client/webmaster_tools.rb +0 -28
- data/lib/gdata/client/youtube.rb +0 -47
- data/lib/gdata/client.rb +0 -84
- data/lib/gdata/g_data.rb +0 -22
- data/lib/gdata/http/default_service.rb +0 -82
- data/lib/gdata/http/mime_body.rb +0 -95
- data/lib/gdata/http/request.rb +0 -74
- data/lib/gdata/http/response.rb +0 -44
- data/lib/gdata/http.rb +0 -18
- data/lib/youtube_helpers.rb +0 -58
- data/lib/youtube_model.rb +0 -341
data/lib/youtube_model.rb
DELETED
@@ -1,341 +0,0 @@
|
|
1
|
-
include GData
|
2
|
-
|
3
|
-
module YouTubeModel # :nodoc:
|
4
|
-
def self.included(base)
|
5
|
-
base.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
# Call this method to make an ActiveResource model ready to roll with YouTube
|
10
|
-
def acts_as_youtube_model
|
11
|
-
self.site = "http://gdata.youtube.com/feeds/api"
|
12
|
-
self.timeout = 5
|
13
|
-
|
14
|
-
extend YouTubeModel::SingletonMethods
|
15
|
-
include YouTubeModel::InstanceMethods
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module InstanceMethods
|
20
|
-
# Returns an array of +entry+, or an empty array when there's no such +entry+
|
21
|
-
def videos
|
22
|
-
if respond_to?(:entry)
|
23
|
-
entry.is_a?(Array) ? entry : [entry]
|
24
|
-
else
|
25
|
-
[]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module SingletonMethods
|
31
|
-
# Retrieve the top rated videos for a time. Valid times are:
|
32
|
-
# * :today (1 day)
|
33
|
-
# * :this_week (7 days)
|
34
|
-
# * :this_month (1 month)
|
35
|
-
# * :all_time (default)
|
36
|
-
def top_rated(time = :all_time)
|
37
|
-
request("standardfeeds/top_rated#{query_string(:time => time)}")
|
38
|
-
end
|
39
|
-
|
40
|
-
# Retrieve the top favorited videos for a time. Valid times are:
|
41
|
-
# * :today (1 day)
|
42
|
-
# * :this_week (7 days)
|
43
|
-
# * :this_month (1 month)
|
44
|
-
# * :all_time (default)
|
45
|
-
def top_favorites(time = :all_time)
|
46
|
-
request("standardfeeds/top_favorites#{query_string(:time => time)}")
|
47
|
-
end
|
48
|
-
|
49
|
-
# Retrieve the most viewed videos for a time. Valid times are:
|
50
|
-
# * :today (1 day)
|
51
|
-
# * :this_week (7 days)
|
52
|
-
# * :this_month (1 month)
|
53
|
-
# * :all_time (default)
|
54
|
-
def most_viewed(time = :all_time)
|
55
|
-
request("standardfeeds/most_viewed#{query_string(:time => time)}")
|
56
|
-
end
|
57
|
-
|
58
|
-
# Retrieve the most recent videos for a time. Valid times are:
|
59
|
-
# * :today (1 day)
|
60
|
-
# * :this_week (7 days)
|
61
|
-
# * :this_month (1 month)
|
62
|
-
# * :all_time (default)
|
63
|
-
def most_recent(time = :all_time)
|
64
|
-
request("standardfeeds/most_recent#{query_string(:time => time)}")
|
65
|
-
end
|
66
|
-
|
67
|
-
# Retrieve the most discussed videos for a time. Valid times are:
|
68
|
-
# * :today (1 day)
|
69
|
-
# * :this_week (7 days)
|
70
|
-
# * :this_month (1 month)
|
71
|
-
# * :all_time (default)
|
72
|
-
def most_discussed(time = :all_time)
|
73
|
-
request("standardfeeds/most_discussed#{query_string(:time => time)}")
|
74
|
-
end
|
75
|
-
|
76
|
-
# Retrieve the most linked videos for a time. Valid times are:
|
77
|
-
# * :today (1 day)
|
78
|
-
# * :this_week (7 days)
|
79
|
-
# * :this_month (1 month)
|
80
|
-
# * :all_time (default)
|
81
|
-
def most_linked(time = :all_time)
|
82
|
-
request("standardfeeds/most_linked#{query_string(:time => time)}")
|
83
|
-
end
|
84
|
-
|
85
|
-
# Retrieve the most responded videos for a time. Valid times are:
|
86
|
-
# * :today (1 day)
|
87
|
-
# * :this_week (7 days)
|
88
|
-
# * :this_month (1 month)
|
89
|
-
# * :all_time (default)
|
90
|
-
def most_responded(time = :all_time)
|
91
|
-
request("standardfeeds/most_responded#{query_string(:time => time)}")
|
92
|
-
end
|
93
|
-
|
94
|
-
# Retrieve the recently featured videos.
|
95
|
-
def recently_featured
|
96
|
-
request("standardfeeds/recently_featured")
|
97
|
-
end
|
98
|
-
|
99
|
-
# Retrieve the videos watchables on mobile.
|
100
|
-
def watch_on_mobile
|
101
|
-
request("standardfeeds/watch_on_mobile")
|
102
|
-
end
|
103
|
-
|
104
|
-
# Finds videos by categories or keywords.
|
105
|
-
#
|
106
|
-
# Capitalize words if you refer to a category.
|
107
|
-
#
|
108
|
-
# You can use the operators +NOT+(-) and +OR+(|). For example:
|
109
|
-
# find_by_category_and_tag('cats|dogs', '-rats', 'Comedy')
|
110
|
-
def find_by_category_and_tag(*tags_and_cats)
|
111
|
-
request("videos/-/#{tags_and_cats.map{ |t| CGI::escape(t) }.join('/')}")
|
112
|
-
end
|
113
|
-
|
114
|
-
# Finds videos by tags (keywords).
|
115
|
-
#
|
116
|
-
# You can use the operators +NOT+(-) and +OR+(|). For example:
|
117
|
-
# find_by_tag('cats|dogs', '-rats')
|
118
|
-
def find_by_tag(*tags)
|
119
|
-
url = "videos/-/%7Bhttp%3A%2F%2Fgdata.youtube.com%2Fschemas%2F2007%2Fkeywords.cat%7D"
|
120
|
-
keywords = tags.map{ |t| CGI::escape(t) }.join('/')
|
121
|
-
request("#{url}#{keywords}")
|
122
|
-
end
|
123
|
-
|
124
|
-
# Finds videos by tags (keywords).
|
125
|
-
#
|
126
|
-
# You can use the operators +NOT+(-) and +OR+(|). For example:
|
127
|
-
# find_by_tag('cats|dogs', '-rats')
|
128
|
-
def find_by_category(*categories)
|
129
|
-
url = "videos/-/%7Bhttp%3A%2F%2Fgdata.youtube.com%2Fschemas%2F2007%2Fcategories.cat%7D"
|
130
|
-
keywords = categories.map{ |c| CGI::escape(c) }.join('/')
|
131
|
-
request("#{url}#{keywords}")
|
132
|
-
end
|
133
|
-
|
134
|
-
# Find uploaded videos by a user.
|
135
|
-
def uploaded_by(username)
|
136
|
-
request("users/#{username}/uploads")
|
137
|
-
end
|
138
|
-
|
139
|
-
# Comments for a video.
|
140
|
-
def comments_for(video)
|
141
|
-
request(video.comments.feedLink.href)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Related videos for a video.
|
145
|
-
def related_to(video)
|
146
|
-
request(video.link[2].href)
|
147
|
-
end
|
148
|
-
|
149
|
-
# Responses videos for a video.
|
150
|
-
def responses_to(video)
|
151
|
-
request(video.link[1].href)
|
152
|
-
end
|
153
|
-
|
154
|
-
# Find uploaded videos by a user as default.
|
155
|
-
def uploaded_by_user(token)
|
156
|
-
get_request_with_user_as_default("users/default/uploads", token)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Find a video through a search query. Options are:
|
160
|
-
# * :orderby (:relevance, :published, :viewCount, :rating)
|
161
|
-
# * :start_index
|
162
|
-
# * :max_results
|
163
|
-
# * :author
|
164
|
-
# * :lr
|
165
|
-
# * :racy (:include, :exclude)
|
166
|
-
# * :restriction
|
167
|
-
#
|
168
|
-
# See options details at {YouTube API}[http://code.google.com/apis/youtube/developers_guide_protocol.html#Searching_for_Videos]
|
169
|
-
#
|
170
|
-
# Note: +alt+ option is still in researching because it causes some errors.
|
171
|
-
def find(query, options = {})
|
172
|
-
options[:vq] = query
|
173
|
-
options[:orderby] ||= :relevance
|
174
|
-
options.delete(:alt)
|
175
|
-
params = Hash[*options.stringify_keys.collect{ |k, v|
|
176
|
-
[k.dasherize, v] }.flatten
|
177
|
-
]
|
178
|
-
request("videos#{query_string(params)}")
|
179
|
-
end
|
180
|
-
|
181
|
-
# Search for a specific video by its ID.
|
182
|
-
# http://www.youtube.com/watch?v=JMDcOViViNY
|
183
|
-
# Here the id is: *JMDcOViViNY* NOTE: this method returns the video itself,
|
184
|
-
# no need to call @yt.video
|
185
|
-
def find_by_id(id)
|
186
|
-
request("videos/#{id}")
|
187
|
-
end
|
188
|
-
|
189
|
-
# Fetchs few YouTube categories
|
190
|
-
def video_categories
|
191
|
-
[["Film & Animation", "Film"], ["Autos & Vehicles", "Autos"], ["Music", "Music"], ["Pets & Animals", "Animals"], ["Sports", "Sports"],
|
192
|
-
["Travel & Events", "Travel"], ["News & Politics", "News"], ["Howto & Style", "Howto"], ["Gaming", "Games"], ["Comedy", "Comedy"],
|
193
|
-
["People & Blogs", "People"], ["Entertainment", "Entertainment"], ["Education", "Education"], ["Nonprofits & Activism", "Nonprofit"],
|
194
|
-
["Science & Technology", "Tech"]]
|
195
|
-
end
|
196
|
-
|
197
|
-
# Fetchs all YouTube categories
|
198
|
-
def categories
|
199
|
-
connection.get('/schemas/2007/categories.cat')['category']
|
200
|
-
end
|
201
|
-
|
202
|
-
# Returns an array with only the +label+ and +term+ attributes of categories.
|
203
|
-
def categories_collection
|
204
|
-
categories.collect { |cat|
|
205
|
-
[cat['label'], cat['term']]
|
206
|
-
}
|
207
|
-
end
|
208
|
-
|
209
|
-
# Sends a POST to YouTube to get the upload url and token.
|
210
|
-
#
|
211
|
-
# Receives a hash with the following keys:
|
212
|
-
# * <tt>:title</tt> Title of the video.
|
213
|
-
# * <tt>:description</tt> Description of the video.
|
214
|
-
# * <tt>:category</tt> Category of the video.
|
215
|
-
# * <tt>:keywords</tt> Keywords for the video.
|
216
|
-
# * <tt>:auth_sub</tt> Authentication token.
|
217
|
-
# * <tt>:nexturl</tt> Url to redirect after the video has been uploaded. Leave it nil to go to http://www.youtube.com/my_videos
|
218
|
-
#
|
219
|
-
# Returns a hash with the keys:
|
220
|
-
# * <tt>:url</tt> url for upload the video to.
|
221
|
-
# * <tt>:token</tt> token hash necessary to upload.
|
222
|
-
# * <tt>:code</tt> response code of the POST.
|
223
|
-
def get_upload_url(meta)
|
224
|
-
xml_entry = build_xml_entry(meta)
|
225
|
-
headers = {
|
226
|
-
'Authorization' => %Q(AuthSub token="#{meta[:auth_sub]}"),
|
227
|
-
'X-GData-Client' => YT_CONFIG['auth_sub']['client_key'],
|
228
|
-
'X-GData-Key' => "key=#{YT_CONFIG['auth_sub']['developer_key']}",
|
229
|
-
'Content-Length' => xml_entry.length.to_s,
|
230
|
-
'Content-Type' => "application/atom+xml; charset=UTF-8"
|
231
|
-
}
|
232
|
-
response = connection.post('/action/GetUploadToken', xml_entry, headers)
|
233
|
-
meta[:nexturl] ||= 'http://www.youtube.com/my_videos'
|
234
|
-
upload = {}
|
235
|
-
(Hpricot.XML(response.body)/:response).each do |elm|
|
236
|
-
upload[:url] = "#{(elm/:url).text}?#{{:nexturl => meta[:nexturl]}.to_query}"
|
237
|
-
upload[:token] = (elm/:token).text
|
238
|
-
end if response.code == "200"
|
239
|
-
upload[:code] = response.code
|
240
|
-
|
241
|
-
upload
|
242
|
-
end
|
243
|
-
|
244
|
-
|
245
|
-
def delete_video(video_id, token)
|
246
|
-
delete_request_with_user_as_default("users/default/uploads/#{video_id}", token)
|
247
|
-
end
|
248
|
-
|
249
|
-
def update_video(video_id, token, video_params)
|
250
|
-
xml_entry = build_xml_entry(video_params)
|
251
|
-
put_request_with_user_as_default("users/default/uploads/#{video_id}", token, xml_entry)
|
252
|
-
end
|
253
|
-
|
254
|
-
# Find status of video uploaded by a user.
|
255
|
-
def video_status(token, video_id)
|
256
|
-
get_request_with_user_as_default("users/default/uploads/#{video_id}", token)
|
257
|
-
end
|
258
|
-
|
259
|
-
def videos_with_user_as_default(token)
|
260
|
-
get_request_with_user_as_default("users/default/uploads", token)
|
261
|
-
end
|
262
|
-
|
263
|
-
protected
|
264
|
-
|
265
|
-
# Loads a response into a new Object of this class
|
266
|
-
def request(url)
|
267
|
-
url = "#{self.prefix}#{url}" unless url =~ /\Ahttp:/
|
268
|
-
new.load(extend_attributes(connection.get(url, 'Accept' => '*/*')))
|
269
|
-
end
|
270
|
-
|
271
|
-
def put_request_with_user_as_default(url, token, meta)
|
272
|
-
headers = {
|
273
|
-
'Content-Type' => "application/atom+xml",
|
274
|
-
'Content-Length' => meta.length.to_s,
|
275
|
-
'Authorization' => %Q(AuthSub token="#{token}"),
|
276
|
-
'X-GData-Client' => YT_CONFIG['auth_sub']['client_key'],
|
277
|
-
'X-GData-Key' => "key=#{YT_CONFIG['auth_sub']['developer_key']}"
|
278
|
-
}
|
279
|
-
url = "#{self.prefix}#{url}" unless url =~ /\Ahttp:/
|
280
|
-
connection.put(url, meta, headers) rescue nil
|
281
|
-
end
|
282
|
-
|
283
|
-
def delete_request_with_user_as_default(url, token)
|
284
|
-
headers = {
|
285
|
-
'Accept' => 'application/atom+xml',
|
286
|
-
'Authorization' => %Q(AuthSub token="#{token}"),
|
287
|
-
'X-GData-Client' => YT_CONFIG['auth_sub']['client_key'],
|
288
|
-
'X-GData-Key' => "key=#{YT_CONFIG['auth_sub']['developer_key']}"
|
289
|
-
}
|
290
|
-
url = "#{self.prefix}#{url}" unless url =~ /\Ahttp:/
|
291
|
-
connection.delete(url, headers) rescue nil
|
292
|
-
end
|
293
|
-
|
294
|
-
def get_request_with_user_as_default(url, token)
|
295
|
-
headers = {
|
296
|
-
'Accept' => '*/*',
|
297
|
-
'Authorization' => %Q(AuthSub token="#{token}")
|
298
|
-
}
|
299
|
-
url = "#{self.prefix}#{url}" unless url =~ /\Ahttp:/
|
300
|
-
new.load(extend_attributes(connection.get(url, headers)))
|
301
|
-
end
|
302
|
-
|
303
|
-
private
|
304
|
-
|
305
|
-
# Adds some extra keys to the +attributes+ hash
|
306
|
-
def extend_attributes(yt)
|
307
|
-
unless yt['entry'].nil?
|
308
|
-
(yt['entry'].is_a?(Array) ? yt['entry'] : [yt['entry']]).each { |v| scan_id(v) }
|
309
|
-
else
|
310
|
-
scan_id(yt)
|
311
|
-
end
|
312
|
-
yt
|
313
|
-
end
|
314
|
-
|
315
|
-
# Renames the +id+ key to +api_id+ and leaves the simple video id on the
|
316
|
-
# +id+ key
|
317
|
-
def scan_id(attrs)
|
318
|
-
attrs['api_id'] = attrs['id']
|
319
|
-
attrs['id'] = attrs['api_id'].scan(/[\w-]+$/).to_s
|
320
|
-
attrs
|
321
|
-
end
|
322
|
-
|
323
|
-
# Builds the XML content to do the POST to obtain the upload url and token.
|
324
|
-
def build_xml_entry(attrs)
|
325
|
-
xml = Builder::XmlMarkup.new(:indent => 2)
|
326
|
-
xml.instruct! :xml, :version => '1.0', :encoding => nil
|
327
|
-
xml.entry :xmlns => 'http://www.w3.org/2005/Atom',
|
328
|
-
'xmlns:media' => 'http://search.yahoo.com/mrss/',
|
329
|
-
'xmlns:yt' => 'http://gdata.youtube.com/schemas/2007' do
|
330
|
-
xml.media :group do
|
331
|
-
xml.tag! 'media:title', attrs[:title]
|
332
|
-
xml.media :description, attrs[:content], :type => 'plain'
|
333
|
-
xml.media :category, attrs[:category], :scheme => 'http://gdata.youtube.com/schemas/2007/categories.cat'
|
334
|
-
xml.media :category, "ytm_#{YT_CONFIG['developer_tag']}", :scheme => 'http://gdata.youtube.com/schemas/2007/developertags.cat'
|
335
|
-
xml.tag! 'media:keywords', attrs[:keywords]
|
336
|
-
end
|
337
|
-
end
|
338
|
-
xml.target!
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|