simple_youtube 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,14 @@
1
+ #### Create classes for YouTube resources.
2
+ module Youtube
3
+ class Video < ActiveYoutube
4
+ end
5
+
6
+ class User < ActiveYoutube
7
+ end
8
+
9
+ class Standardfeed < ActiveYoutube
10
+ end
11
+
12
+ class Playlist < ActiveYoutube
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + "/simple_youtube/activeyoutube"
2
+ require File.dirname(__FILE__) + "/simple_youtube/youtube"
@@ -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