acts_as_oauth_accessible 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ gem 'rspec', '>= 1.2.9', '< 1.9.9'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -12,6 +13,7 @@ begin
12
13
  gem.authors = ["SAWADA Tadashi"]
13
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
15
  gem.add_dependency "oauth", ">= 0.4.0"
16
+ gem.files = FileList['lib/**/*', 'generators/**/*', 'rails/**/*', 'init.rb', 'LICENSE', 'README.rdoc', 'Rakefile', 'VERSION', '*.gemspec'].to_a
15
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
18
  end
17
19
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{acts_as_oauth_accessible}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["SAWADA Tadashi"]
12
+ s.date = %q{2010-09-03}
13
+ s.description = %q{Rails plugin that enables your models to access OAuth services}
14
+ s.email = %q{cesare@mayverse.jp}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "acts_as_oauth_accessible.gemspec",
25
+ "generators/acts_as_oauth_accessible_generator.rb",
26
+ "generators/templates/config/oauth_providers.yml",
27
+ "generators/templates/db/migration.rb",
28
+ "generators/templates/models/consumer_token.rb",
29
+ "init.rb",
30
+ "lib/acts_as_oauth_accessible.rb",
31
+ "lib/acts_as_oauth_accessible/railtie.rb",
32
+ "lib/generators/acts_as_oauth_accessible_generator.rb",
33
+ "lib/generators/templates/config/oauth_providers.yml",
34
+ "lib/generators/templates/db/migration.rb",
35
+ "lib/generators/templates/models/consumer_token.rb",
36
+ "rails/init.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/cesare/acts_as_oauth_accessible}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{enables your Rails models to OAuth-access}
43
+ s.test_files = [
44
+ "spec/acts_as_oauth_accessible_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_runtime_dependency(%q<oauth>, [">= 0.4.0"])
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<oauth>, [">= 0.4.0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
+ s.add_dependency(%q<oauth>, [">= 0.4.0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,14 @@
1
+ class ActsAsOauthAccessibleGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.template 'config/oauth_providers.yml', 'config/oauth_providers.yml'
6
+ m.template 'models/consumer_token.rb', 'app/models/consumer_token.rb'
7
+
8
+ m.migration_template 'db/migration.rb', 'db/migrate', :assigns => {
9
+ :migration_name => "CreateConsumerTokens"
10
+ }, :migration_file_name => "create_consumer_tokens"
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,25 @@
1
+ development:
2
+ twitter:
3
+ key: YOUR_CONSUMER_KEY
4
+ secret: YOUR_CONSUMER_SECRET
5
+ options:
6
+ site: http://twitter.com
7
+ google:
8
+ key: YOUR_CONSUMER_KEY
9
+ secret: YOUR_CONSUMER_SECRET
10
+ options:
11
+ site: http://www.google.com
12
+
13
+
14
+ test:
15
+ twitter:
16
+ key: YOUR_CONSUMER_KEY
17
+ secret: YOUR_CONSUMER_SECRET
18
+ options:
19
+ site: http://twitter.com
20
+ google:
21
+ key: YOUR_CONSUMER_KEY
22
+ secret: YOUR_CONSUMER_SECRET
23
+ options:
24
+ site: http://www.google.com
25
+
@@ -0,0 +1,18 @@
1
+ class CreateConsumerTokens < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :consumer_tokens do |t|
4
+ t.string :oauth_accessible_type, :null => false, :limit => 30
5
+ t.integer :oauth_accessible_id, :null => false
6
+
7
+ t.string :type, :null => false, :limit => 30
8
+ t.string :provider, :null => false, :limit => 50
9
+ t.string :token, :null => false, :limit => 1024
10
+ t.string :secret, :null => false, :limit => 255
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :consumer_tokens
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ class ConsumerToken < ActiveRecord::Base
2
+ #
3
+ # associations
4
+ #
5
+ belongs_to :oauth_accessible, :polymorphic => true
6
+
7
+
8
+ #
9
+ # callback
10
+ #
11
+ before_validation :fix_provider
12
+
13
+
14
+ #
15
+ # callback methods
16
+ #
17
+ private
18
+
19
+ def fix_provider
20
+ self.provider = provider.to_s
21
+ end
22
+
23
+
24
+ #
25
+ # named scopes
26
+ #
27
+ named_scope :for, Proc.new {|name| { :conditions => ["provider = ?", name.to_s] }}
28
+
29
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "rails", "init")
@@ -1,8 +1,16 @@
1
1
  require 'oauth'
2
2
 
3
- module ActsAsOAuthAccessible
3
+ if defined?(Rails) && Rails.version >= '3.0.0'
4
+ require File.join(File.dirname(__FILE__), "acts_as_oauth_accessible", "railtie")
5
+ end
6
+
7
+
8
+ module ActsAsOauthAccessible
4
9
  def self.init(hash)
5
10
  @config = Config.new(hash)
11
+ if defined? ActiveRecord::Base
12
+ ActiveRecord::Base.send :include, ActsAsOauthAccessible
13
+ end
6
14
  end
7
15
 
8
16
  def self.config
@@ -11,7 +19,11 @@ module ActsAsOAuthAccessible
11
19
 
12
20
  module ClassMethods
13
21
  def acts_as_oauth_consumer
14
- self.include InstanceMethods
22
+ self.send :include, InstanceMethods
23
+ self.class_eval do
24
+ has_many :consumer_tokens, :as => :oauth_accessible
25
+ has_many :consumer_access_tokens, :as => :oauth_accessible
26
+ end
15
27
  end
16
28
  end
17
29
 
@@ -41,9 +53,8 @@ module ActsAsOAuthAccessible
41
53
 
42
54
  end
43
55
 
44
- def self.included(receiver)
45
- receiver.extend ClassMethods
46
- receiver.send :include, InstanceMethods
56
+ def self.included(base)
57
+ base.send :extend, ClassMethods
47
58
  end
48
59
 
49
60
  class Config
@@ -62,14 +73,7 @@ module ActsAsOAuthAccessible
62
73
  @name = name
63
74
  @key = entry['key']
64
75
  @secret = entry['secret']
65
- options = {}
66
- entry.each do |k,v|
67
- key = k.to_sym
68
- unless key == :key || key == :secret
69
- options[key] = v
70
- end
71
- end
72
- @options = options
76
+ @options = entry['options']
73
77
  end
74
78
 
75
79
  def create_consumer
@@ -0,0 +1,16 @@
1
+ module ActsAsOauthAccessible
2
+ class Railtie < Rails::Railtie
3
+ initializer "acts_as_oauth_accessible.configure_rails_initialization" do |app|
4
+ filename = File.join(Rails.root, 'config', 'oauth_providers.yml')
5
+ if File.exists? filename
6
+ require 'yaml'
7
+ source = YAML.load_file(filename)
8
+ ActsAsOauthAccessible.init(source[Rails.env])
9
+ end
10
+ end
11
+
12
+ generators do
13
+ require File.join(File.dirname(__FILE__), '..', 'generators', 'acts_as_oauth_accessible_generator')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/migration'
2
+ require 'rails/generators/active_record'
3
+
4
+ class ActsAsOauthAccessibleGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path('../templates', __FILE__)
9
+ end
10
+
11
+ def self.next_migration_number(path)
12
+ ActiveRecord::Generators::Base.next_migration_number(path)
13
+ end
14
+
15
+ def copy_config_files
16
+ copy_file('config/oauth_providers.yml', 'config/oauth_providers.yml')
17
+ end
18
+
19
+ def copy_models
20
+ template 'models/consumer_token.rb', 'app/models/consumer_token.rb'
21
+ end
22
+
23
+ def copy_migration_file
24
+ migration_template 'db/migration.rb', 'db/migrate/create_consumer_tokens'
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ development:
2
+ twitter:
3
+ key: YOUR_CONSUMER_KEY
4
+ secret: YOUR_CONSUMER_SECRET
5
+ options:
6
+ site: http://twitter.com
7
+ google:
8
+ key: YOUR_CONSUMER_KEY
9
+ secret: YOUR_CONSUMER_SECRET
10
+ options:
11
+ site: http://www.google.com
12
+
13
+
14
+ test:
15
+ twitter:
16
+ key: YOUR_CONSUMER_KEY
17
+ secret: YOUR_CONSUMER_SECRET
18
+ options:
19
+ site: http://twitter.com
20
+ google:
21
+ key: YOUR_CONSUMER_KEY
22
+ secret: YOUR_CONSUMER_SECRET
23
+ options:
24
+ site: http://www.google.com
25
+
@@ -0,0 +1,18 @@
1
+ class CreateConsumerTokens < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :consumer_tokens do |t|
4
+ t.string :oauth_accessible_type, :null => false, :limit => 30
5
+ t.integer :oauth_accessible_id, :null => false
6
+
7
+ t.string :type, :null => false, :limit => 30
8
+ t.string :provider, :null => false, :limit => 50
9
+ t.string :token, :null => false, :limit => 1024
10
+ t.string :secret, :null => false, :limit => 255
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :consumer_tokens
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ class ConsumerToken < ActiveRecord::Base
2
+ #
3
+ # associations
4
+ #
5
+ belongs_to :oauth_accessible, :polymorphic => true
6
+
7
+
8
+ #
9
+ # callback
10
+ #
11
+ before_validation :fix_provider
12
+
13
+
14
+ #
15
+ # callback methods
16
+ #
17
+ private
18
+
19
+ def fix_provider
20
+ self.provider = provider.to_s
21
+ end
22
+
23
+
24
+ #
25
+ # named scopes
26
+ #
27
+ named_scope :for, Proc.new {|name| { :conditions => ["provider = ?", name.to_s] }}
28
+
29
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ filename = File.join(Rails.root, 'config', 'oauth_providers.yml')
4
+ if File.exists? filename
5
+ require 'yaml'
6
+
7
+ source = YAML.load_file(filename)
8
+ ActsAsOauthAccessible.init(source[Rails.env])
9
+ end
@@ -1,7 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "ActsAsOauthAccessible" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'acts_as_oauth_accessible'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - SAWADA Tadashi
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-23 00:00:00 +09:00
17
+ date: 2010-09-03 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
@@ -35,6 +36,7 @@ dependencies:
35
36
  name: oauth
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
@@ -55,15 +57,24 @@ extra_rdoc_files:
55
57
  - LICENSE
56
58
  - README.rdoc
57
59
  files:
58
- - .document
59
- - .gitignore
60
60
  - LICENSE
61
61
  - README.rdoc
62
62
  - Rakefile
63
63
  - VERSION
64
+ - acts_as_oauth_accessible.gemspec
65
+ - generators/acts_as_oauth_accessible_generator.rb
66
+ - generators/templates/config/oauth_providers.yml
67
+ - generators/templates/db/migration.rb
68
+ - generators/templates/models/consumer_token.rb
69
+ - init.rb
64
70
  - lib/acts_as_oauth_accessible.rb
71
+ - lib/acts_as_oauth_accessible/railtie.rb
72
+ - lib/generators/acts_as_oauth_accessible_generator.rb
73
+ - lib/generators/templates/config/oauth_providers.yml
74
+ - lib/generators/templates/db/migration.rb
75
+ - lib/generators/templates/models/consumer_token.rb
76
+ - rails/init.rb
65
77
  - spec/acts_as_oauth_accessible_spec.rb
66
- - spec/spec.opts
67
78
  - spec/spec_helper.rb
68
79
  has_rdoc: true
69
80
  homepage: http://github.com/cesare/acts_as_oauth_accessible
@@ -75,6 +86,7 @@ rdoc_options:
75
86
  require_paths:
76
87
  - lib
77
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
78
90
  requirements:
79
91
  - - ">="
80
92
  - !ruby/object:Gem::Version
@@ -82,6 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
94
  - 0
83
95
  version: "0"
84
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
85
98
  requirements:
86
99
  - - ">="
87
100
  - !ruby/object:Gem::Version
@@ -91,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
104
  requirements: []
92
105
 
93
106
  rubyforge_project:
94
- rubygems_version: 1.3.6
107
+ rubygems_version: 1.3.7
95
108
  signing_key:
96
109
  specification_version: 3
97
110
  summary: enables your Rails models to OAuth-access
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color