blob: 57322ce8c9e422d4c4970dd2c523c17dddddfea4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service < ActiveRecord::Base
attr_accessor :provider, :info, :access_level
belongs_to :user
validates_uniqueness_of :uid, :scope => :type
def profile_photo_url
nil
end
def post_opts(post)
# don't do anything (should be overridden by service extensions)
end
class << self
def titles(service_strings)
service_strings.map {|s| "Services::#{s.titleize}"}
end
def first_from_omniauth( auth_hash )
@@auth = auth_hash
where( type: service_type, uid: options[:uid] ).first
end
def initialize_from_omniauth( auth_hash )
@@auth = auth_hash
service_type.constantize.new( options )
end
def auth
@@auth
end
def service_type
"Services::#{options[:provider].camelize}"
end
def options
{
nickname: auth['info']['nickname'],
access_token: auth['credentials']['token'],
access_secret: auth['credentials']['secret'],
uid: auth['uid'],
provider: auth['provider'],
info: auth['info']
}
end
private :auth, :service_type, :options
end
end
|