Permalink
Browse files

[ADD] oauth-activeresource gem first version

  • Loading branch information...
0 parents commit f1af190ba067ccb2f50641d805ee0f4d353e0fcc @albertopq committed Feb 23, 2012
Showing with 1,539 additions and 0 deletions.
  1. +21 −0 Gemfile
  2. +101 −0 Gemfile.lock
  3. +20 −0 MIT-LICENSE
  4. +27 −0 README.rdoc
  5. +38 −0 Rakefile
  6. +48 −0 lib/oauth_active_resource.rb
  7. +3 −0 lib/oauth_active_resource/version.rb
  8. +4 −0 lib/tasks/oauth_active_resource_tasks.rake
  9. +21 −0 oauth_active_resource.gemspec
  10. +261 −0 test/dummy/README.rdoc
  11. +7 −0 test/dummy/Rakefile
  12. +15 −0 test/dummy/app/assets/javascripts/application.js
  13. +13 −0 test/dummy/app/assets/stylesheets/application.css
  14. +3 −0 test/dummy/app/controllers/application_controller.rb
  15. +2 −0 test/dummy/app/helpers/application_helper.rb
  16. 0 test/dummy/app/mailers/.gitkeep
  17. 0 test/dummy/app/models/.gitkeep
  18. +3 −0 test/dummy/app/models/user.rb
  19. +14 −0 test/dummy/app/views/layouts/application.html.erb
  20. +4 −0 test/dummy/config.ru
  21. +56 −0 test/dummy/config/application.rb
  22. +10 −0 test/dummy/config/boot.rb
  23. +25 −0 test/dummy/config/database.yml
  24. +5 −0 test/dummy/config/environment.rb
  25. +37 −0 test/dummy/config/environments/development.rb
  26. +67 −0 test/dummy/config/environments/production.rb
  27. +37 −0 test/dummy/config/environments/test.rb
  28. +7 −0 test/dummy/config/initializers/backtrace_silencers.rb
  29. +15 −0 test/dummy/config/initializers/inflections.rb
  30. +5 −0 test/dummy/config/initializers/mime_types.rb
  31. +7 −0 test/dummy/config/initializers/secret_token.rb
  32. +8 −0 test/dummy/config/initializers/session_store.rb
  33. +14 −0 test/dummy/config/initializers/wrap_parameters.rb
  34. +5 −0 test/dummy/config/locales/en.yml
  35. +58 −0 test/dummy/config/routes.rb
  36. +9 −0 test/dummy/db/migrate/20120215083511_create_users.rb
  37. 0 test/dummy/db/test.sqlite3
  38. 0 test/dummy/lib/assets/.gitkeep
  39. 0 test/dummy/log/.gitkeep
  40. 0 test/dummy/log/development.log
  41. +406 −0 test/dummy/log/test.log
  42. +26 −0 test/dummy/public/404.html
  43. +26 −0 test/dummy/public/422.html
  44. +25 −0 test/dummy/public/500.html
  45. 0 test/dummy/public/favicon.ico
  46. +6 −0 test/dummy/script/rails
  47. +7 −0 test/dummy/test/fixtures/users.yml
  48. +7 −0 test/dummy/test/unit/user_test.rb
  49. +56 −0 test/oauth_active_resource_test.rb
  50. +10 −0 test/test_helper.rb
@@ -0,0 +1,21 @@
+source "http://rubygems.org"
+
+# Declare your gem's dependencies in oauth_active_resource.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# jquery-rails is used by the dummy application
+gem "jquery-rails"
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :test do
+ gem "mocha"
+end
@@ -0,0 +1,101 @@
+PATH
+ remote: .
+ specs:
+ oauth-activeresource (0.0.1)
+ rails (~> 3.2.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.1)
+ actionpack (= 3.2.1)
+ mail (~> 2.4.0)
+ actionpack (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ activerecord (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ arel (~> 3.0.0)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.0)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.1)
+ jquery-rails (2.0.0)
+ railties (>= 3.2.0.beta, < 5.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ mail (2.4.1)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ metaclass (0.0.1)
+ mime-types (1.17.2)
+ mocha (0.10.3)
+ metaclass (~> 0.0.1)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.1)
+ actionmailer (= 3.2.1)
+ actionpack (= 3.2.1)
+ activerecord (= 3.2.1)
+ activeresource (= 3.2.1)
+ activesupport (= 3.2.1)
+ bundler (~> 1.0)
+ railties (= 3.2.1)
+ railties (3.2.1)
+ actionpack (= 3.2.1)
+ activesupport (= 3.2.1)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jquery-rails
+ mocha
+ oauth-activeresource!
+ sqlite3
@@ -0,0 +1,20 @@
+Copyright 2012 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
+= OauthActiveResource
+
+Rails gem that allows you to easily interact with an Oauth secured rest API with the ActiveResource model.
+You have to provide an http-like object that signs your requests with your already retrieved access_token, like the one that the oauth gem provides (http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html)
+
+= Getting Started
+
+Assuming that you are using oauth gem:
+
+1. Add into your Gemfile:
+
+ gem 'oauth-activeresource'
+
+2. Make your models inherit from OauthActiveResource instead ActiveResource
+
+ class MyModel < OauthActiveResource::Base
+ end
+
+3. Set a before_filter in your controllers to override your connection object with your access_token object
+
+ def set_oauth
+ MyModel.oauth_connection = session[:request_token].get_access_token( :oauth_verifier => params[:oauth_verifier] )
+ end
+
+ Where session[:request_token] is your OAuth::Consumer and params[:oauth_verifier] the parameters that the authorizer is sending to your callback method.
+
+
@@ -0,0 +1,38 @@
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'OauthActiveResource'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
@@ -0,0 +1,48 @@
+module OauthActiveResource
+ class Base < ActiveResource::Base
+
+ @@oauth_connection = nil
+
+ def self.oauth_connection= connection
+ @@oauth_connection = connection
+ end
+
+ def self.oauth_connection
+ @@oauth_connection
+ end
+
+ def self.connection(refresh = false)
+ @connection = Connection.new(@@oauth_connection, site,format) if @connection.nil? || refresh
+ @connection.timeout = timeout if timeout
+ return @connection
+ end
+
+ def format=(mime_type_reference_or_format)
+ format = mime_type_reference_or_format.is_a?(Symbol) ?
+ OauthActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format
+ self._format = format
+ connection.format = format if site
+ end
+
+ end
+
+ class Connection < ActiveResource::Connection
+ def initialize(oauth_connection, *args)
+ @oauth_connection = oauth_connection
+ super(*args)
+ end
+
+ private
+ def request(method, path, *arguments)
+ if @oauth_connection == nil
+ super(method, path, *arguments)
+ else
+ path = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
+ response = @oauth_connection.send(method, path, *arguments)
+ handle_response(response)
+ end
+ rescue Timeout::Error => e
+ raise TimeoutError.new(e.message)
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module OauthActiveResource
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :oauth_active_resource do
+# # Task goes here
+# end
@@ -0,0 +1,21 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "oauth_active_resource/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "oauth-activeresource"
+ s.version = OauthActiveResource::VERSION
+ s.authors = ["Alberto Pastor"]
+ s.email = ["albert.pastor@gmail.com"]
+ s.homepage = ""
+ s.summary = "Rails gem that allows you to easily interact with an Oauth secured rest API with the ActiveResource model."
+
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["test/**/*"]
+
+ s.add_dependency "rails", "~> 3.2.1"
+
+ s.add_development_dependency "sqlite3"
+end
Oops, something went wrong.

0 comments on commit f1af190

Please sign in to comment.