Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service.rb « models « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 590ceed48c128425a52507645dcf6e53b9417630 (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
57
58
# frozen_string_literal: true

#   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 < ApplicationRecord
  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
      find_by(type: service_type, uid: options[:uid])
    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