Module: GoodGuide::Accounts::Profile

Included in:
Base
Defined in:
lib/goodguide/accounts/profile.rb

Instance Method Summary collapse

Instance Method Details

#facebook?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/goodguide/accounts/profile.rb', line 40

def facebook?
  with_profile(false) do |profile|
    profile["identifier"] && profile["identifier"].include?("facebook.com")
  end
end

#full_nameObject



24
25
26
27
28
29
30
# File 'lib/goodguide/accounts/profile.rb', line 24

def full_name
  with_profile do |profile|
    name = profile["name"]["formatted"]

    !name.blank? ? name.strip : "GoodGuide User"
  end
end

#given_nameObject



14
15
16
17
18
19
20
21
22
# File 'lib/goodguide/accounts/profile.rb', line 14

def given_name
  with_profile do |profile|
    name = profile["name"]["givenName"] ||
      profile["displayName"] ||
      profile["name"]["formatted"]

    !name.blank? ? name.strip : "GoodGuide User"
  end
end

#identifierObject



8
9
10
11
12
# File 'lib/goodguide/accounts/profile.rb', line 8

def identifier
  with_profile do |profile|
    profile['identifier']
  end
end

#profile_picture(size = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/goodguide/accounts/profile.rb', line 32

def profile_picture(size = nil)
  with_profile do |profile|
    photo = profile["photo"]
    photo.gsub!("=large", "=#{size}") if facebook? and size.present?
    photo
  end
end

#with_profile(default = nil, &block) ⇒ Object



4
5
6
# File 'lib/goodguide/accounts/profile.rb', line 4

def with_profile(default = nil, &block)
  profile? ? yield(profile) : default
end