Class: SocialProfile::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/social_profile/providers/base.rb

Direct Known Subclasses

Facebook, Instagram, Odnoklassniki, Twitter, Vkontakte

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, options) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/social_profile/providers/base.rb', line 9

def initialize(hash, options)
  @auth_hash = hash
  @options = options
end

Instance Attribute Details

#auth_hashObject (readonly)

Returns the value of attribute auth_hash.



7
8
9
# File 'lib/social_profile/providers/base.rb', line 7

def auth_hash
  @auth_hash
end

Instance Method Details

#access_tokenObject



81
82
83
# File 'lib/social_profile/providers/base.rb', line 81

def access_token
  @access_token ||= credentials['token']
end

#avatar_urlObject



62
63
64
# File 'lib/social_profile/providers/base.rb', line 62

def avatar_url
  @avatar_url ||= info('image')
end

#birthdayObject



102
103
104
# File 'lib/social_profile/providers/base.rb', line 102

def birthday
  nil
end

#city_nameObject



74
75
76
77
78
79
# File 'lib/social_profile/providers/base.rb', line 74

def city_name
  @city_name ||= begin
    loc = info('location')
    loc.nil? ? nil : loc.split(',').pop().strip
  end
end

#credentialsObject



85
86
87
# File 'lib/social_profile/providers/base.rb', line 85

def credentials
  @credentials ||= (auth_hash['credentials'] || {})
end

#emailObject



94
95
96
# File 'lib/social_profile/providers/base.rb', line 94

def email
  @email ||= info('email')
end

#extra(key) ⇒ Object



44
45
46
47
48
# File 'lib/social_profile/providers/base.rb', line 44

def extra(key)
  if extra? && Utils.exists?(auth_hash['extra'][key])
    auth_hash['extra'][key]
  end
end

#extra?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/social_profile/providers/base.rb', line 50

def extra?
  auth_hash['extra'] && auth_hash['extra'].is_a?(Hash)
end

#first_nameObject



26
27
28
# File 'lib/social_profile/providers/base.rb', line 26

def first_name
  @first_name ||= (info('first_name') || name)
end

#genderObject

Возвращаемые значения: 1 - женский, 2 - мужской, 0 - без указания пола.



90
91
92
# File 'lib/social_profile/providers/base.rb', line 90

def gender
  0
end

#info(key) ⇒ Object



38
39
40
41
42
# File 'lib/social_profile/providers/base.rb', line 38

def info(key)
  if info? && Utils.exists?(auth_hash['info'][key])
    auth_hash['info'][key]
  end
end

#info?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/social_profile/providers/base.rb', line 54

def info?
  auth_hash['info'] && auth_hash['info'].is_a?(Hash)
end

#last_nameObject



30
31
32
# File 'lib/social_profile/providers/base.rb', line 30

def last_name
  @last_name ||= info('last_name')
end

#nameObject



22
23
24
# File 'lib/social_profile/providers/base.rb', line 22

def name
  @name ||= info('name')
end

#nicknameObject



34
35
36
# File 'lib/social_profile/providers/base.rb', line 34

def nickname
  @nickname ||= info('nickname')
end

#picture_urlObject



66
67
68
# File 'lib/social_profile/providers/base.rb', line 66

def picture_url
  nil
end

#profile_urlObject



70
71
72
# File 'lib/social_profile/providers/base.rb', line 70

def profile_url
  nil
end

#providerObject



18
19
20
# File 'lib/social_profile/providers/base.rb', line 18

def provider
  @provider ||= auth_hash['provider']
end

#token_expires_atObject



98
99
100
# File 'lib/social_profile/providers/base.rb', line 98

def token_expires_at
  @token_expires_at ||= parse_datetime(credentials['expires_at'])
end

#uidObject



14
15
16
# File 'lib/social_profile/providers/base.rb', line 14

def uid
  @uid ||= auth_hash['uid']  
end

#works?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/social_profile/providers/base.rb', line 58

def works?
  false
end