sociable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sociable/contacts/twitter/friends.rb +42 -0
- data/lib/sociable/contacts/twitter/rate_limits.rb +0 -0
- data/lib/sociable/controllers/omniauth_callbacks_controller.rb +12 -0
- data/lib/sociable/model/authorization.rb +15 -0
- data/lib/sociable/model/facebook.rb +9 -5
- data/lib/sociable/model/linkedin.rb +69 -0
- data/lib/sociable/model/twitter.rb +3 -1
- data/lib/sociable.rb +14 -4
- data/lib/version.rb +1 -1
- metadata +28 -3
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Sociable
|
5
|
+
module Friends
|
6
|
+
module Facebook
|
7
|
+
|
8
|
+
def load_friends(twitter_handle)
|
9
|
+
ids_response = get("1/friends/ids.json?cursor=-1&screen_name=#{twitter_handle}")
|
10
|
+
ids=JSON.parse(ids_response[:body])['ids']
|
11
|
+
rv=[]
|
12
|
+
ids.flatten.each_slice(100) do |ids|
|
13
|
+
users_response=get("1/friends/ids.json?cursor=-1&screen_name=#{twitter_handle}")
|
14
|
+
rv += JSON.parse(users_response[:body])
|
15
|
+
end
|
16
|
+
rv
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(path)
|
20
|
+
request(:get, path)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Perform an HTTP request
|
25
|
+
def request(method, path)
|
26
|
+
uri = 'http://api.twitter.com/'+path
|
27
|
+
connection.url_prefix = options[:endpoint] || @endpoint
|
28
|
+
connection.run_request(:get, path, nil, nil)
|
29
|
+
rescue Faraday::Error::ClientError
|
30
|
+
raise Sociable::Error::ClientError
|
31
|
+
end
|
32
|
+
|
33
|
+
def connection
|
34
|
+
@connection ||= Faraday.new(@endpoint)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
File without changes
|
@@ -26,5 +26,17 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
|
+
def linkedin
|
30
|
+
@user = resource_class.find_for_facebook_oauth(request.env["omniauth.auth"], request.ip)
|
31
|
+
|
32
|
+
if @user.persisted?
|
33
|
+
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Linkedin"
|
34
|
+
sign_in_and_redirect @user, event: :authentication
|
35
|
+
else
|
36
|
+
session["devise.linkedin_data"] = request.env["omniauth.auth"]
|
37
|
+
redirect_to new_user_registration_url
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
29
41
|
|
30
42
|
end
|
@@ -8,7 +8,7 @@ module Sociable
|
|
8
8
|
# facebook fields
|
9
9
|
field :facebook_user_name, :type => String
|
10
10
|
field :facebook_image_url, :type => String
|
11
|
-
field :facebook_data, :type =>
|
11
|
+
field :facebook_data, :type => Hash
|
12
12
|
field :facebook_token, :type => String
|
13
13
|
field :facebook_token_expiration, :type => String
|
14
14
|
attr_accessible :facebook_user_name, :facebook_image_url, :facebook_data, :current_sign_in_ip
|
@@ -19,25 +19,29 @@ module Sociable
|
|
19
19
|
|
20
20
|
def find_for_facebook_oauth(access_token, ip)
|
21
21
|
data = access_token.info
|
22
|
-
credentials=access_token.credentials
|
22
|
+
#credentials=access_token.credentials.merge(type: :facebook)
|
23
23
|
users_criteria = self.any_of({ facebook_user_name: data.nickname }, { last_sign_in_ip: ip, name: data.name })
|
24
24
|
if users_criteria.count > 0
|
25
25
|
user = users_criteria.first
|
26
|
+
user.credentials ||= {}
|
27
|
+
user.credentials.merge!(facebook: access_token.credentials)
|
26
28
|
user.update_attributes(facebook_user_name: data.nickname,
|
27
29
|
facebook_data: access_token.extra.raw_info,
|
28
30
|
facebook_image_url: data.image) unless (user.facebook_user_name)
|
29
31
|
user.update_attribute(email: data.email) unless user.email
|
30
32
|
user
|
31
33
|
else
|
32
|
-
self.create!(
|
34
|
+
user=self.create!(
|
33
35
|
password: Devise.friendly_token[0,20],
|
34
36
|
facebook_image_url: data.image,
|
35
37
|
facebook_user_name: data.nickname,
|
36
38
|
name: data.name,
|
37
39
|
email: data.email,
|
38
|
-
facebook_data: access_token.extra.raw_info
|
39
|
-
|
40
|
+
facebook_data: access_token.extra.raw_info,
|
41
|
+
credentials: credentials
|
40
42
|
)
|
43
|
+
user.save!
|
44
|
+
user
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Sociable
|
2
|
+
module Profile
|
3
|
+
module LinkedIn
|
4
|
+
module Mongoid
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# linkedin fields
|
9
|
+
field :linkedin_user_name, :type => String
|
10
|
+
field :linkedin_image_url, :type => String
|
11
|
+
field :linkedin_data, :type => Hash
|
12
|
+
field :linkedin_token, :type => String
|
13
|
+
field :linkedin_token_expiration, :type => String
|
14
|
+
attr_accessible :linkedin_user_name, :linkedin_image_url, :linkedin_data, :current_sign_in_ip
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
|
20
|
+
def find_for_linkedin_oauth(access_token, ip)
|
21
|
+
data = access_token.info
|
22
|
+
#credentials=access_token.credentials.merge(type: :linkedin)
|
23
|
+
users_criteria = self.any_of({ linkedin_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.credentials ||= {}
|
27
|
+
user.credentials.merge!(linkedin: access_token.credentials)
|
28
|
+
user.update_attributes(linkedin_user_name: data.nickname,
|
29
|
+
linkedin_data: access_token.extra.raw_info,
|
30
|
+
linkedin_image_url: data.image) unless (user.linkedin_user_name)
|
31
|
+
user.update_attribute(email: data.email) unless user.email
|
32
|
+
user
|
33
|
+
else
|
34
|
+
user=self.create!(
|
35
|
+
password: Devise.friendly_token[0,20],
|
36
|
+
linkedin_image_url: data.image,
|
37
|
+
linkedin_user_name: data.nickname,
|
38
|
+
name: data.name,
|
39
|
+
email: data.email,
|
40
|
+
linkedin_data: access_token.extra.raw_info,
|
41
|
+
credentials: credentials
|
42
|
+
)
|
43
|
+
user.save!
|
44
|
+
user
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module InstanceMethods
|
50
|
+
|
51
|
+
def new_with_session(params, session)
|
52
|
+
super.tap do |user|
|
53
|
+
if data = session["devise.linkedin_data"] && session["devise.linkedin_data"]["info"]
|
54
|
+
user.linkedin_user_name = data["nickname"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
module ActiveRecord
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -8,7 +8,7 @@ module Sociable
|
|
8
8
|
# twitter fields
|
9
9
|
field :twitter_handle, :type => String
|
10
10
|
field :twitter_profile_image_url, :type => String
|
11
|
-
field :twitter_data, :type =>
|
11
|
+
field :twitter_data, :type => Hash
|
12
12
|
attr_accessible :twitter_handle, :twitter_profile_image_url, :twitter_data, :current_sign_in_ip
|
13
13
|
|
14
14
|
end
|
@@ -20,6 +20,8 @@ module Sociable
|
|
20
20
|
users_criteria = self.any_of({ twitter_handle: data.nickname }, { last_sign_in_ip: ip, name: data.name })
|
21
21
|
if users_criteria.count > 0
|
22
22
|
user = users_criteria.first
|
23
|
+
user.credentials ||= {}
|
24
|
+
user.credentials.merge!(twitter: access_token.credentials)
|
23
25
|
user.update_attributes(twitter_handle: data.nickname,
|
24
26
|
twitter_data: access_token.extra.raw_info,
|
25
27
|
twitter_profile_image_url: data.image) unless (user.twitter_handle)
|
data/lib/sociable.rb
CHANGED
@@ -4,31 +4,41 @@ module Sociable
|
|
4
4
|
module Profile
|
5
5
|
autoload :Facebook, 'sociable/model/facebook'
|
6
6
|
autoload :Twitter, 'sociable/model/twitter'
|
7
|
+
autoload :LinkedIn, 'sociable/model/linkedin'
|
8
|
+
autoload :Authorization, 'sociable/model/authorization'
|
7
9
|
end
|
8
10
|
|
9
11
|
mattr_accessor :twitter_omniauth_settings
|
10
12
|
|
11
13
|
mattr_accessor :facebook_omniauth_settings
|
12
14
|
|
15
|
+
mattr_accessor :linkedin_omniauth_settings
|
16
|
+
|
13
17
|
def self.twitter (*args)
|
14
18
|
@twitter_omniauth_settings=["twitter"]
|
15
|
-
@twitter_omniauth_settings
|
19
|
+
@twitter_omniauth_settings+=args
|
16
20
|
end
|
17
21
|
|
18
22
|
def self.facebook (*args)
|
19
23
|
@facebook_omniauth_settings=["facebook"]
|
20
|
-
@facebook_omniauth_settings
|
24
|
+
@facebook_omniauth_settings+=args
|
21
25
|
end
|
22
26
|
|
27
|
+
def self.linkedin (*args)
|
28
|
+
@linkedin_omniauth_settings=["linkedin"]
|
29
|
+
@linkedin_omniauth_settings+=args
|
30
|
+
end
|
23
31
|
|
24
32
|
def self.setup
|
25
33
|
yield self
|
26
34
|
|
27
35
|
Devise.setup do |config|
|
28
36
|
|
29
|
-
config.send(:omniauth, *@twitter_omniauth_settings) unless @twitter_omniauth_settings.
|
37
|
+
config.send(:omniauth, *@twitter_omniauth_settings) unless @twitter_omniauth_settings.blank?
|
38
|
+
|
39
|
+
config.send(:omniauth, *@facebook_omniauth_settings) unless @facebook_omniauth_settings.blank?
|
30
40
|
|
31
|
-
config.send(:omniauth, *@
|
41
|
+
config.send(:omniauth, *@linkedin_omniauth_settings) unless @linkedin_omniauth_settings.blank?
|
32
42
|
|
33
43
|
end
|
34
44
|
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.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sergey Zelvenskiy
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-28 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: devise
|
@@ -45,6 +45,28 @@ dependencies:
|
|
45
45
|
version: 0.0.12
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: omniauth-linkedin
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.0.6
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: faraday
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0.8"
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
48
70
|
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."
|
49
71
|
email: sergey@actions.im
|
50
72
|
executables: []
|
@@ -55,8 +77,12 @@ extra_rdoc_files: []
|
|
55
77
|
|
56
78
|
files:
|
57
79
|
- README
|
80
|
+
- lib/sociable/contacts/twitter/friends.rb
|
81
|
+
- lib/sociable/contacts/twitter/rate_limits.rb
|
58
82
|
- lib/sociable/controllers/omniauth_callbacks_controller.rb
|
83
|
+
- lib/sociable/model/authorization.rb
|
59
84
|
- lib/sociable/model/facebook.rb
|
85
|
+
- lib/sociable/model/linkedin.rb
|
60
86
|
- lib/sociable/model/twitter.rb
|
61
87
|
- lib/sociable.rb
|
62
88
|
- lib/version.rb
|
@@ -89,4 +115,3 @@ specification_version: 3
|
|
89
115
|
summary: This gem will make your rails app social in 30 seconds or less.
|
90
116
|
test_files: []
|
91
117
|
|
92
|
-
has_rdoc: false
|