simple_youtube 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_youtube/activeyoutube.rb +22 -0
- data/lib/simple_youtube/youtube.rb +14 -0
- data/lib/simple_youtube.rb +2 -0
- data/test/fakeweb_helper.rb +18 -0
- data/test/fixture/playlist_cyanure1982.xml +752 -0
- data/test/fixture/standardfeed_toprated_jp.xml +1989 -0
- data/test/fixture/standardfeed_toprated_jp_comedy.xml +280 -0
- data/test/fixture/standardfeed_toprated_today.xml +1855 -0
- data/test/fixture/user_cyanure1982_playlists.xml +78 -0
- data/test/fixture/user_ionysis_favourites.xml +1496 -0
- data/test/fixture/user_ionysis_subscriptions.xml +43 -0
- data/test/fixture/user_vinyljunkie07_contacts.xml +424 -0
- data/test/fixture/video_category_comedy.xml +745 -0
- data/test/fixture/video_category_comedy_exclude_film.xml +354 -0
- data/test/fixture/video_category_david_beckham_news_or_sports.xml +1526 -0
- data/test/fixture/video_comments.xml +423 -0
- data/test/fixture/video_related.xml +1488 -0
- data/test/fixture/video_responses.xml +267 -0
- data/test/fixture/video_search.xml +309 -0
- data/test/youtube_test.rb +108 -0
- metadata +150 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
class ActiveYoutube < ActiveResource::Base
|
4
|
+
|
5
|
+
self.site = "http://gdata.youtube.com/feeds/api"
|
6
|
+
|
7
|
+
def self.find(args)
|
8
|
+
scope, type, query = args[:scope], args[:type], args[:params]
|
9
|
+
headers['Accept'] = "application/atom+xml"
|
10
|
+
path = "#{prefix()}#{collection_name}#{'/' if scope}#{scope}#{'/' if type}#{type}#{query_string(query)}"
|
11
|
+
convert_entry_to_array(instantiate_record(connection.get(path, headers)))
|
12
|
+
end
|
13
|
+
|
14
|
+
# if youtube only returns a single entry, then convert to an array to standardize subsequent feed processing
|
15
|
+
def self.convert_entry_to_array object
|
16
|
+
if object.respond_to?:entry and !(object.entry.kind_of? Array)
|
17
|
+
object.entry=[object.entry]
|
18
|
+
end
|
19
|
+
object
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
|
3
|
+
module FakewebHelper
|
4
|
+
# Make sure nothing gets out (IMPORTANT)
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
|
7
|
+
# Turns a fixture file name into a full path
|
8
|
+
def fixture_file(filename)
|
9
|
+
return '' if filename == ''
|
10
|
+
File.expand_path('./fixture/' + filename)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Convenience methods for stubbing URLs to fixtures
|
14
|
+
def stub_get(url, filename)
|
15
|
+
FakeWeb.register_uri(:get, url, :response => fixture_file(filename))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|