spherebird 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/spherebird.rb +163 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/spherebird_spec.rb +7 -0
- data/spherebird.gemspec +60 -0
- metadata +106 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.3)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
faraday (0.8.0)
|
9
|
+
multipart-post (~> 1.1)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.6.0)
|
12
|
+
jeweler (1.8.3)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.1)
|
18
|
+
multi_json (1.3.4)
|
19
|
+
multipart-post (1.1.5)
|
20
|
+
oauth (0.4.6)
|
21
|
+
rake (0.9.2.2)
|
22
|
+
rdoc (3.12)
|
23
|
+
json (~> 1.4)
|
24
|
+
rspec (2.9.0)
|
25
|
+
rspec-core (~> 2.9.0)
|
26
|
+
rspec-expectations (~> 2.9.0)
|
27
|
+
rspec-mocks (~> 2.9.0)
|
28
|
+
rspec-core (2.9.0)
|
29
|
+
rspec-expectations (2.9.1)
|
30
|
+
diff-lcs (~> 1.1.3)
|
31
|
+
rspec-mocks (2.9.0)
|
32
|
+
simple_oauth (0.1.7)
|
33
|
+
twitter (2.2.8)
|
34
|
+
activesupport (>= 2.3.9, < 4)
|
35
|
+
faraday (~> 0.8)
|
36
|
+
multi_json (~> 1.3)
|
37
|
+
simple_oauth (~> 0.1.6)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
jeweler
|
44
|
+
oauth
|
45
|
+
rspec
|
46
|
+
twitter
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 AOKI Yuuto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= spherebird
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to spherebird
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 AOKI Yuuto. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "spherebird"
|
18
|
+
gem.homepage = "http://github.com/wneko/spherebird"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Twitter-OAuth on Rails"
|
21
|
+
gem.description = "Twitter-OAuth Sign On System on Rails"
|
22
|
+
gem.email = "wx.aoki@gmail.com"
|
23
|
+
gem.authors = ["AOKI Yuuto"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "spherebird #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/spherebird.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'twitter'
|
3
|
+
|
4
|
+
module Spherebird
|
5
|
+
|
6
|
+
def config_file_path
|
7
|
+
"config/twitter_oauth.yml"
|
8
|
+
end
|
9
|
+
|
10
|
+
def profile_cache_lifetime
|
11
|
+
1800
|
12
|
+
end
|
13
|
+
|
14
|
+
def twitter_oauth_config
|
15
|
+
if @twitter_oauth_config.nil?
|
16
|
+
if File.exists?(config_file_path)
|
17
|
+
twitter_oauth_configs = YAML::load_file(config_file_path)
|
18
|
+
@twitter_oauth_config = twitter_oauth_configs[Rails.env]
|
19
|
+
else
|
20
|
+
raise <<-EXCEPTION
|
21
|
+
Twitter-OAuth Configurate File (#{config_file_path}) is missing.
|
22
|
+
Example:
|
23
|
+
EXCEPTION
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@twitter_oauth_config
|
28
|
+
end
|
29
|
+
|
30
|
+
def twitter_oauth_consumer
|
31
|
+
options = {
|
32
|
+
:site => "http://twitter.com",
|
33
|
+
:request_token_url => "https://api.twitter.com/oauth/request_token",
|
34
|
+
:authorize_url => "https://api.twitter.com/oauth/authorize",
|
35
|
+
:access_token_url => "https://api.twitter.com/oauth/access_token",
|
36
|
+
}
|
37
|
+
if twitter_oauth_config['proxy']
|
38
|
+
options[:proxy] = twitter_oauth_config['proxy']
|
39
|
+
end
|
40
|
+
puts options
|
41
|
+
OAuth::Consumer.new(
|
42
|
+
twitter_oauth_config['consumer_token'],
|
43
|
+
twitter_oauth_config['consumer_secret'],
|
44
|
+
options
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def twitter_login_state
|
49
|
+
twitter_session_read(:oauth_state)
|
50
|
+
end
|
51
|
+
|
52
|
+
def twitter_logged_in?
|
53
|
+
twitter_login_state == "logged_in"
|
54
|
+
end
|
55
|
+
|
56
|
+
def twitter_authorized?
|
57
|
+
twitter_login_state == "authorized"
|
58
|
+
end
|
59
|
+
|
60
|
+
def twitter_oauth
|
61
|
+
if twitter_logged_in?
|
62
|
+
|
63
|
+
redirect_to twitter_oauth_config['logged_in_url']
|
64
|
+
|
65
|
+
elsif twitter_authorized?
|
66
|
+
|
67
|
+
@request_token = OAuth::RequestToken.new(twitter_oauth_consumer,
|
68
|
+
twitter_session_read(:request_token),
|
69
|
+
twitter_session_read(:request_token_secret))
|
70
|
+
|
71
|
+
begin
|
72
|
+
@access_token = @request_token.get_access_token()
|
73
|
+
rescue OAuth::Unauthorized => e
|
74
|
+
twitter_session_clear
|
75
|
+
redirect_to :controller => 'oauth',
|
76
|
+
:action => 'index'
|
77
|
+
return
|
78
|
+
rescue => e
|
79
|
+
raise e
|
80
|
+
end
|
81
|
+
|
82
|
+
twitter_session_write :access_token, @access_token.token
|
83
|
+
twitter_session_write :access_token_secret, @access_token.secret
|
84
|
+
|
85
|
+
twitter_session_write :oauth_state, "logged_in"
|
86
|
+
|
87
|
+
redirect_to :controller => 'users',
|
88
|
+
:action => 'profile'
|
89
|
+
|
90
|
+
else
|
91
|
+
|
92
|
+
request_token = twitter_oauth_consumer.get_request_token(
|
93
|
+
:oauth_callback => twitter_oauth_config['callback_url']
|
94
|
+
)
|
95
|
+
|
96
|
+
twitter_session_clear
|
97
|
+
twitter_session_write :request_token, request_token.token
|
98
|
+
twitter_session_write :request_token_secret, request_token.secret
|
99
|
+
|
100
|
+
redirect_to request_token.authorize_url
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def twitter_oauth_request (oauth_token = nil)
|
105
|
+
if oauth_token.nil? || oauth_token == twitter_session_read(:request_token)
|
106
|
+
twitter_session_write :oauth_state, "authorized"
|
107
|
+
end
|
108
|
+
twitter_oauth
|
109
|
+
end
|
110
|
+
|
111
|
+
def twitter
|
112
|
+
return @twitter if @twitter
|
113
|
+
|
114
|
+
Twitter.configure do |config|
|
115
|
+
config.consumer_key = twitter_oauth_config['consumer_token']
|
116
|
+
config.consumer_secret = twitter_oauth_config['consumer_secret']
|
117
|
+
|
118
|
+
config.oauth_token = twitter_session_read(:access_token)
|
119
|
+
config.oauth_token_secret = twitter_session_read(:access_token_secret)
|
120
|
+
|
121
|
+
if twitter_oauth_config['proxy']
|
122
|
+
config.proxy = twitter_oauth_config['proxy']
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
@twitter = Twitter::Client.new
|
127
|
+
end
|
128
|
+
|
129
|
+
# options:
|
130
|
+
# force_update (BOOL)
|
131
|
+
def twitter_profile(options = {})
|
132
|
+
profile = twitter_session_read(:profile)
|
133
|
+
expiry = twitter_session_read(:profile_expiry_date)
|
134
|
+
if options[:force_update] || profile.nil? || expiry.nil? || (expiry - Time.now).to_i < 0
|
135
|
+
twitter_session_write(:profile_expiry_date, Time.now + profile_cache_lifetime)
|
136
|
+
begin
|
137
|
+
profile = twitter.verify_credentials
|
138
|
+
rescue Twitter::Error::Unauthorized
|
139
|
+
return nil
|
140
|
+
end
|
141
|
+
twitter_session_write(:profile, profile)
|
142
|
+
on_twitter_profile_update
|
143
|
+
end
|
144
|
+
return profile
|
145
|
+
end
|
146
|
+
|
147
|
+
def twitter_session_read (key)
|
148
|
+
session[:twitter] ||= {}
|
149
|
+
session[:twitter][key]
|
150
|
+
end
|
151
|
+
|
152
|
+
def twitter_session_write (key, value)
|
153
|
+
session[:twitter] ||= {}
|
154
|
+
session[:twitter][key] = value
|
155
|
+
end
|
156
|
+
|
157
|
+
def twitter_session_clear
|
158
|
+
session[:twitter] = nil
|
159
|
+
end
|
160
|
+
|
161
|
+
def on_twitter_profile_update
|
162
|
+
end
|
163
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'spherebird'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/spherebird.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "spherebird"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["AOKI Yuuto"]
|
12
|
+
s.date = "2012-05-08"
|
13
|
+
s.description = "Twitter-OAuth Sign On System on Rails"
|
14
|
+
s.email = "wx.aoki@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/spherebird.rb",
|
29
|
+
"spec/spec_helper.rb",
|
30
|
+
"spec/spherebird_spec.rb",
|
31
|
+
"spherebird.gemspec"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/wneko/spherebird"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.11"
|
37
|
+
s.summary = "Twitter-OAuth on Rails"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<twitter>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
49
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
50
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
51
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
55
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spherebird
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- AOKI Yuuto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oauth
|
16
|
+
requirement: &2165804040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2165804040
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: twitter
|
27
|
+
requirement: &2165803540 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2165803540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2165802920 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2165802920
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &2165802380 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2165802380
|
58
|
+
description: Twitter-OAuth Sign On System on Rails
|
59
|
+
email: wx.aoki@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.rdoc
|
65
|
+
files:
|
66
|
+
- .document
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- VERSION
|
74
|
+
- lib/spherebird.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/spherebird_spec.rb
|
77
|
+
- spherebird.gemspec
|
78
|
+
homepage: http://github.com/wneko/spherebird
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: 3585084522378378174
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.11
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Twitter-OAuth on Rails
|
106
|
+
test_files: []
|