simple_youtube 1.0.3 → 2.0.0

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.
@@ -1,7 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'active_resource'
3
+ require File.dirname(__FILE__) + "/entry_interface_shim"
3
4
 
4
5
  class ActiveYoutube < ActiveResource::Base
6
+
7
+ include EntryInterfaceShim
5
8
 
6
9
  self.site = "http://gdata.youtube.com/feeds/api"
7
10
 
@@ -9,15 +12,7 @@ class ActiveYoutube < ActiveResource::Base
9
12
  scope, type, query = args[:scope], args[:type], args[:params]
10
13
  headers['Accept'] = "application/atom+xml"
11
14
  path = "#{prefix()}#{collection_name}#{'/' if scope}#{scope}#{'/' if type}#{type}#{query_string(query)}"
12
- convert_entry_to_array(instantiate_record(connection.get(path, headers)))
13
- end
14
-
15
- # if youtube only returns a single entry, then convert to an array to standardize subsequent feed processing
16
- def self.convert_entry_to_array object
17
- if object.respond_to?:entry and !(object.entry.kind_of? Array)
18
- object.entry=[object.entry]
19
- end
20
- object
21
- end
22
-
15
+ instantiate_record(connection.get(path, headers))
16
+ end
17
+
23
18
  end
@@ -0,0 +1,18 @@
1
+ #
2
+ # This module provides the interface for a response object to have
3
+ # a #entry method regardless of the response object being a single
4
+ # entry or a collection of entries
5
+ #
6
+ module EntryInterfaceShim
7
+ def entry
8
+ if attributes.has_key?('entry')
9
+ if attributes['entry'].kind_of? Array
10
+ return attributes['entry']
11
+ else
12
+ return [attributes['entry']]
13
+ end
14
+ else
15
+ [self]
16
+ end
17
+ end
18
+ end
@@ -1,6 +1,16 @@
1
+ require 'oauth'
2
+
1
3
  #### Create classes for YouTube resources.
2
4
  module Youtube
5
+
3
6
  class Video < ActiveYoutube
7
+
8
+ def self.update scope, user_name, update_xml, oauth_token, oauth_token_secret, x_gdata_key, host, host_secret
9
+ consumer = OAuth::Consumer.new(host, host_secret, {:site=>"https://www.google.com", :request_token_path=>"/accounts/OAuthGetRequestToken", :authorize_path=>"/accounts/OAuthAuthorizeToken", :access_token_path=>"/accounts/OAuthGetAccessToken"})
10
+ access_token = OAuth::AccessToken.new(consumer, oauth_token, oauth_token_secret)
11
+ access_token.put("http://gdata.youtube.com/feeds/api/users/#{user_name}/uploads/#{scope}", update_xml, {'Accept' => 'application/atom+xml', 'Content-Type' => 'application/atom+xml', 'X-GData-Key' => x_gdata_key})
12
+ end
13
+
4
14
  end
5
15
 
6
16
  class User < ActiveYoutube
@@ -11,4 +21,5 @@ module Youtube
11
21
 
12
22
  class Playlist < ActiveYoutube
13
23
  end
24
+
14
25
  end
@@ -13,6 +13,6 @@ module FakewebHelper
13
13
  # Convenience methods for stubbing URLs to fixtures
14
14
  def stub_get(url, filename)
15
15
  FakeWeb.register_uri(:get, url, :response => fixture_file(filename))
16
- end
17
-
16
+ end
17
+
18
18
  end
File without changes
File without changes
File without changes