sociable 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -1
- data/lib/sociable.rb +36 -0
- data/lib/sociable/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/sociable/model/facebook.rb +65 -0
- data/lib/sociable/model/twitter.rb +59 -0
- data/lib/version.rb +1 -1
- metadata +41 -4
data/README
CHANGED
@@ -8,4 +8,5 @@ Sociable gem provides abilities to share various user actions happening in your
|
|
8
8
|
5. Follow friends activities.
|
9
9
|
6. Present configurable newsfeed, which shows timeline of events happening in the app.
|
10
10
|
|
11
|
-
With these features you can focus on core user experience and use Sociable gem as a shell to enable social interactions in your app.
|
11
|
+
With these features you can focus on core user experience and use Sociable gem as a shell to enable social interactions in your app.
|
12
|
+
|
data/lib/sociable.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Sociable
|
3
|
+
|
4
|
+
module Profile
|
5
|
+
autoload :Facebook, 'sociable/model/facebook'
|
6
|
+
autoload :Twitter, 'sociable/model/twitter'
|
7
|
+
end
|
8
|
+
|
9
|
+
mattr_accessor :twitter_omniauth_settings
|
10
|
+
|
11
|
+
mattr_accessor :facebook_omniauth_settings
|
12
|
+
|
13
|
+
def self.twitter (*args)
|
14
|
+
@twitter_omniauth_settings=["twitter"]
|
15
|
+
@twitter_omniauth_settings<<args
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.facebook (*args)
|
19
|
+
@facebook_omniauth_settings=["facebook"]
|
20
|
+
@facebook_omniauth_settings<<args
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.setup
|
25
|
+
yield self
|
26
|
+
|
27
|
+
Devise.setup do |config|
|
28
|
+
|
29
|
+
config.send(:omniauth, *@twitter_omniauth_settings) unless @twitter_omniauth_settings.empty?
|
30
|
+
|
31
|
+
config.send(:omniauth, *@facebook_omniauth_settings) unless @facebook_omniauth_settings.empty?
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
2
|
+
|
3
|
+
def twitter
|
4
|
+
|
5
|
+
@user = resource_class.find_for_twitter_oauth(request.env["omniauth.auth"], request.ip)
|
6
|
+
|
7
|
+
if @user.persisted?
|
8
|
+
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Twitter"
|
9
|
+
sign_in_and_redirect @user, event: :authentication
|
10
|
+
else
|
11
|
+
session["devise.twitter_data"] = request.env["omniauth.auth"]
|
12
|
+
redirect_to new_user_registration_url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def facebook
|
17
|
+
@user = resource_class.find_for_facebook_oauth(request.env["omniauth.auth"], request.ip)
|
18
|
+
|
19
|
+
if @user.persisted?
|
20
|
+
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Facebook"
|
21
|
+
sign_in_and_redirect @user, event: :authentication
|
22
|
+
else
|
23
|
+
session["devise.facebook_data"] = request.env["omniauth.auth"]
|
24
|
+
redirect_to new_user_registration_url
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Sociable
|
2
|
+
module Profile
|
3
|
+
module Facebook
|
4
|
+
module Mongoid
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# facebook fields
|
9
|
+
field :facebook_user_name, :type => String
|
10
|
+
field :facebook_image_url, :type => String
|
11
|
+
field :facebook_data, :type => String
|
12
|
+
field :facebook_token, :type => String
|
13
|
+
field :facebook_token_expiration, :type => String
|
14
|
+
attr_accessible :facebook_user_name, :facebook_image_url, :facebook_data, :current_sign_in_ip
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
|
20
|
+
def find_for_facebook_oauth(access_token, ip)
|
21
|
+
data = access_token.info
|
22
|
+
credentials=access_token.credentials
|
23
|
+
users_criteria = self.any_of({ facebook_user_name: data.nickname }, { last_sign_in_ip: ip, name: data.name })
|
24
|
+
if users_criteria.count > 0
|
25
|
+
user = users_criteria.first
|
26
|
+
user.update_attributes(facebook_user_name: data.nickname,
|
27
|
+
facebook_data: access_token.extra.raw_info,
|
28
|
+
facebook_image_url: data.image) unless (user.facebook_user_name)
|
29
|
+
user.update_attribute(email: data.email) unless user.email
|
30
|
+
user
|
31
|
+
else
|
32
|
+
self.create!(
|
33
|
+
password: Devise.friendly_token[0,20],
|
34
|
+
facebook_image_url: data.image,
|
35
|
+
facebook_user_name: data.nickname,
|
36
|
+
name: data.name,
|
37
|
+
email: data.email,
|
38
|
+
facebook_data: access_token.extra.raw_info
|
39
|
+
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module InstanceMethods
|
46
|
+
|
47
|
+
def new_with_session(params, session)
|
48
|
+
super.tap do |user|
|
49
|
+
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["info"]
|
50
|
+
user.facebook_user_name = data["nickname"]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
module ActiveRecord
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Sociable
|
2
|
+
module Profile
|
3
|
+
module Twitter
|
4
|
+
module Mongoid
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# twitter fields
|
9
|
+
field :twitter_handle, :type => String
|
10
|
+
field :twitter_profile_image_url, :type => String
|
11
|
+
field :twitter_data, :type => String
|
12
|
+
attr_accessible :twitter_handle, :twitter_profile_image_url, :twitter_data, :current_sign_in_ip
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
|
18
|
+
def find_for_twitter_oauth(access_token, ip)
|
19
|
+
data = access_token.info
|
20
|
+
users_criteria = self.any_of({ twitter_handle: data.nickname }, { last_sign_in_ip: ip, name: data.name })
|
21
|
+
if users_criteria.count > 0
|
22
|
+
user = users_criteria.first
|
23
|
+
user.update_attributes(twitter_handle: data.nickname,
|
24
|
+
twitter_data: access_token.extra.raw_info,
|
25
|
+
twitter_profile_image_url: data.image) unless (user.twitter_handle)
|
26
|
+
user
|
27
|
+
else
|
28
|
+
self.create!(
|
29
|
+
password: Devise.friendly_token[0,20],
|
30
|
+
twitter_profile_image_url: data.image,
|
31
|
+
twitter_handle: data.nickname,
|
32
|
+
name: data.name,
|
33
|
+
twitter_data: access_token.extra.raw_info
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module InstanceMethods
|
40
|
+
|
41
|
+
def new_with_session(params, session)
|
42
|
+
super.tap do |user|
|
43
|
+
if data = session["devise.twitter_data"] && session["devise.twitter_data"]["info"]
|
44
|
+
user.twitter_handle = data["nickname"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
module ActiveRecord
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sociable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sergey Zelvenskiy
|
@@ -10,9 +10,41 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-06-
|
14
|
-
dependencies:
|
15
|
-
|
13
|
+
date: 2012-06-27 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: devise
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.2
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: omniauth-facebook
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.4.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: omniauth-twitter
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.12
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
16
48
|
description: "\n Sociable gem provides abilities to share various user actions happening in your app and present these on custom newsfeed.\n The following features can be seamlessly added to your app.\n 1. Create user account using Facebook or Twitter profiles.\n 2. Invite friends from email address book, facebook, twitter.\n 3. Track various events happening in your application.\n It can be anything from uploading new picture to installing new plug-in.\n 4. Present user activities on user profile page.\n 5. Follow friends activities.\n 6. Present configurable newsfeed, which shows timeline of events happening in the app."
|
17
49
|
email: sergey@actions.im
|
18
50
|
executables: []
|
@@ -23,6 +55,10 @@ extra_rdoc_files: []
|
|
23
55
|
|
24
56
|
files:
|
25
57
|
- README
|
58
|
+
- lib/sociable/controllers/omniauth_callbacks_controller.rb
|
59
|
+
- lib/sociable/model/facebook.rb
|
60
|
+
- lib/sociable/model/twitter.rb
|
61
|
+
- lib/sociable.rb
|
26
62
|
- lib/version.rb
|
27
63
|
homepage: https://github.com/actions/sociable
|
28
64
|
licenses: []
|
@@ -53,3 +89,4 @@ specification_version: 3
|
|
53
89
|
summary: This gem will make your rails app social in 30 seconds or less.
|
54
90
|
test_files: []
|
55
91
|
|
92
|
+
has_rdoc: false
|