Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/jwagener/oauth-active-resource

Conflicts:
	lib/oauth_active_resource/resource.rb
  • Loading branch information...
commit b3705a86671b474327b2f8cda2340e33b754f205 2 parents 0232d69 + ae56979
Thor Kell authored
View
12 Rakefile
@@ -4,14 +4,14 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.name = "oauth-active-resource"
- gem.summary = "An OAuth enabled ActiveResource wrapper"
- gem.email = "johannes@wagener.cc"
+ gem.name = "oauth-active-resource"
+ gem.summary = "An OAuth enabled ActiveResource wrapper"
+ gem.email = "johannes@wagener.cc"
gem.homepage = "http://github.com/jwagener/oauth-active-resource"
- gem.authors = ["Johannes Wagener"]
+ gem.authors = [ "Johannes Wagener", "Hannes Tyden" ]
gem.add_dependency "oauth", ">= 0.3.6"
- gem.add_dependency "activeresource"
- gem.add_dependency "multipart"
+ gem.add_dependency "activeresource"
+ gem.add_dependency "multipart"
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
View
2  VERSION.yml
@@ -1,4 +1,4 @@
---
:major: 0
:minor: 4
-:patch: 4
+:patch: 5
View
29 lib/oauth_active_resource.rb
@@ -1,19 +1,20 @@
require 'rubygems'
gem 'activeresource'
-require 'activeresource'
+require 'active_resource'
+
+gem 'oauth'
+require 'oauth'
require 'digest/md5'
module OAuthActiveResource
-
# TODO check if klass has ancestor OAuthActiveResource
def self.register(add_to_module, model_module, options = {})
-
oauth_connection = options[:access_token]
if oauth_connection.nil?
- oauth_connection = FakeOAuthAccessToken.new
+ oauth_connection = FakeOAuthAccessToken.new
end
site = options[:site]
@@ -22,7 +23,7 @@ def self.register(add_to_module, model_module, options = {})
model_module.constants.each do |klass|
# TODO check if klass.is_a OAuthActiveResource
sub = Class.new(model_module.const_get(klass)) do
- self.site = site
+ self.site = site
@oauth_connection = oauth_connection
end
const_set(klass, sub)
@@ -37,30 +38,28 @@ def self.method_missing(name,*args)
def self.destroy
name = self.model_name.split('::').last
self.parent.send :remove_const, name
- end
+ end
end
# Obscure (=Hash) token+secret, b/c it should stay one
if oauth_connection.nil?
dynamic_module_name = "AnonymousConsumer"
else
- hash = Digest::MD5.hexdigest("#{oauth_connection.token}#{oauth_connection.secret}")
+ hash = Digest::MD5.hexdigest("#{oauth_connection.token}#{oauth_connection.secret}")
dynamic_module_name = "OAuthConsumer#{hash}"
end
if add_to_module.const_defined? dynamic_module_name
- mod = add_to_module.const_get dynamic_module_name
+ mod = add_to_module.const_get dynamic_module_name
else
- add_to_module.const_set(dynamic_module_name, mod)
+ add_to_module.const_set(dynamic_module_name, mod)
end
return mod
end
-
end
-
-require 'oauth_active_resource/connection'
-require 'oauth_active_resource/resource'
-require 'oauth_active_resource/unique_resource_array'
-require 'oauth_active_resource/fake_oauth_access_token'
+require File.expand_path('oauth_active_resource/connection', File.dirname(__FILE__))
+require File.expand_path('oauth_active_resource/resource', File.dirname(__FILE__))
+require File.expand_path('oauth_active_resource/unique_resource_array', File.dirname(__FILE__))
+require File.expand_path('oauth_active_resource/fake_oauth_access_token', File.dirname(__FILE__))
View
17 lib/oauth_active_resource/connection.rb
@@ -1,7 +1,6 @@
module OAuthActiveResource
-
class Connection < ActiveResource::Connection
- def initialize(oauth_connection, *args)
+ def initialize(oauth_connection, *args)
@oauth_connection = oauth_connection
super(*args)
end
@@ -19,25 +18,25 @@ def handle_response(response)
# ugly code to insert the error_message into response
error_message = "#{format.decode response.body}"
if not error_message.nil? or error_message == ""
- exc.response.instance_eval do ||
+ exc.response.instance_eval do ||
@message = error_message
end
- end
+ end
ensure
raise exc
end
end
- private
- def request(method, path, *arguments)
+ private
+ def request(method, path, *arguments)
if @oauth_connection == nil
super(method, path, *arguments)
else
- response = @oauth_connection.request(method, "#{site.scheme}://#{site.host}:#{site.port}#{path}", *arguments)
+ response = @oauth_connection.request(method, "#{site.scheme}://#{site.host}:#{site.port}#{path}", *arguments)
handle_response(response)
end
- rescue Timeout::Error => e
+ rescue Timeout::Error => e
raise TimeoutError.new(e.message)
- end
+ end
end
end
View
17 lib/oauth_active_resource/fake_oauth_access_token.rb
@@ -1,16 +1,14 @@
module OAuthActiveResource
-
# just simulates the request and sign! methods of a oauth access token
- class FakeOAuthAccessToken < OAuth::Consumer
-
+ class FakeOAuthAccessToken < ::OAuth::Consumer
attr_accessor :token, :secret
def initialize()
@key = nil
- token = 'Anonymous'
- secret = 'Anonymous'
+ token = 'Anonymous'
+ secret = 'Anonymous'
# ensure that keys are symbols
- @options = @@default_options
+ @options = @@default_options
end
def request(http_method, path, token = nil, request_options = {}, *arguments)
@@ -18,12 +16,9 @@ def request(http_method, path, token = nil, request_options = {}, *arguments)
@http = create_http(path)
_uri = URI.parse(path)
path = "#{_uri.path}#{_uri.query ? "?#{_uri.query}" : ""}"
-
end
- rsp = http.request(create_http_request(http_method, path, token, request_options, *arguments))
-
- rsp
+ http.request(create_http_request(http_method, path, token, request_options, *arguments))
end
def get(path, headers = {})
@@ -49,7 +44,5 @@ def delete(path, headers = {})
def sign!(*args)
# do nothing
end
-
end
end
-
View
34 lib/oauth_active_resource/resource.rb
@@ -12,14 +12,14 @@ class << self
def self.connection(refresh = false)
@connection = Connection.new(oauth_connection, site,format) if @connection.nil? || refresh
- @connection.timeout = timeout if timeout
- return @connection
+ @connection.timeout = timeout if timeout
+ return @connection
end
#TODO remove when soundcloud api is fixed
# if self has no id, try extracting from uri
def load(*args)
- super(*args)
+ super(*args)
self.id = self.uri.split('/').last if self.id.nil? and defined? self.uri
end
@@ -31,16 +31,16 @@ def ==(other)
def self.load_collection(*args)
instantiate_collection(*args)
- end
+ end
#
# belongs_to :user
# => will look for a user-id tag and load this user
- #
+ #
def self.belongs_to(*args)
- args.each do |k|
+ args.each do |k|
name = k.to_s
- define_method(k) do
+ define_method(k) do
if @belongs_to_cache.nil?
@belongs_to_cache = {}
end
@@ -48,7 +48,7 @@ def self.belongs_to(*args)
resource = find_or_create_resource_for(name)
@belongs_to_cache[name] = resource.find(self.send("#{name}_id"))
end
- return @belongs_to_cache[name]
+ return @belongs_to_cache[name]
end
end
end
@@ -59,29 +59,29 @@ def self.belongs_to(*args)
# User 123 (http://example.com/users/123/) has many friends
# The list of friends can be accessed by http://example.com/users/123/friends
# Our class definition:
- #
+ #
# class User < Resource
# has_many :friends
# end
- #
+ #
# user = User.find(123)
# user.friends.each do |friend|
# p friend.name
# end
- #
- # # adding a friend
+ #
+ # # adding a friend
# stranger = User.find(987)
# user.friends << stranger
# user.friends.save
# => sends a PUT with collection of friends to http://example.com/users/123/friends ## OUTDATED!!?
def self.has_many(*args)
- args.each do |k|
+ args.each do |k|
name = k.to_s
singular = name.singularize
- define_method(k) do |*options|
+ define_method(k) do |*options|
- options = options.first || {}
+ options = options.first || {}
#if @has_many_cache.nil?
# @has_many_cache = {}
#end
@@ -93,13 +93,13 @@ def self.has_many(*args)
resource = find_or_create_resource_for(singular)
@has_many_cache[cache_name] = OAuthActiveResource::UniqueResourceArray.new(self.connection,resource,collection_path,options)
end
- return @has_many_cache[cache_name]
+ return @has_many_cache[cache_name]
end
end
end
- # ignore is added because the multipart gem is adding an extra new line
+ # ignore is added because the multipart gem is adding an extra new line
# to the last parameter which will break parsing of track[sharing]
def self.multipart_bug_fix(params)
ordered_params = ActiveSupport::OrderedHash.new
View
30 lib/oauth_active_resource/unique_resource_array.rb
@@ -38,8 +38,8 @@ def []=(*args)
# see has_many in Resource
class UniqueResourceArray < UniqueArray
- def initialize(connection, resource, collection_path,options = {})
- super()
+ def initialize(connection, resource, collection_path,options = {})
+ super()
@connection = connection
@collection_path = collection_path
@@ -58,20 +58,19 @@ def to_xml
return "<#{pt}> #{self.map { |obj| obj.to_xml({:skip_instruct => true})}.join(' ')} </#{pt}>"
end
-
# DEPRECATED...
- #def find(look_for)
- # if not (look_for.is_a? String or look_for.is_a? Integer)
- # look_for_id = look_for
- # else
- # look_for_id = look_for.id
- # end
- #
- # self.each do |obj|
- # obj.id == look_for_id and return obj
- # end
- # return nil
- #end
+ # def find(look_for)
+ # if not (look_for.is_a? String or look_for.is_a? Integer)
+ # look_for_id = look_for
+ # else
+ # look_for_id = look_for.id
+ # end
+ #
+ # self.each do |obj|
+ # obj.id == look_for_id and return obj
+ # end
+ # return nil
+ # end
def save
response = @connection.handle_response( @connection.put("#{@collection_path}",self.to_xml) )
@@ -83,5 +82,4 @@ def reload
return self
end
end
-
end
View
9 oauth-active-resource.gemspec
@@ -1,12 +1,15 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{oauth-active-resource}
- s.version = "0.4.4"
+ s.version = "0.4.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Johannes Wagener"]
- s.date = %q{2009-11-19}
+ s.authors = ["Johannes Wagener", "Hannes Tyden"]
+ s.date = %q{2010-05-26}
s.email = %q{johannes@wagener.cc}
s.extra_rdoc_files = [
"LICENSE",
Please sign in to comment.
Something went wrong with that request. Please try again.