Class: Evri::RPX::User

Inherits:
Object
  • Object
show all
Defined in:
lib/evri/rpx/user.rb

Defined Under Namespace

Classes: InvalidUserJsonError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ User

Returns a new instance of User.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/evri/rpx/user.rb', line 13

def initialize(json)
  if json.nil? or !json['profile']
    raise InvalidUserJsonError,
          'The JSON passed in is invalid!'
  end

  @json = json

  if @json['accessCredentials']
    @credentials = Credentials.new(@json['accessCredentials'])
  end
end

Instance Attribute Details

#credentialsObject (readonly)

Returns a Credentials object for this user, or nil.



7
8
9
# File 'lib/evri/rpx/user.rb', line 7

def credentials
  @credentials
end

#jsonObject (readonly) Also known as: raw

Returns the raw JSON returned by RPX, in case you want it.



10
11
12
# File 'lib/evri/rpx/user.rb', line 10

def json
  @json
end

Instance Method Details

#display_nameObject

Returns a name that should be displayed for this user.



32
33
34
# File 'lib/evri/rpx/user.rb', line 32

def display_name
  @json['profile']['displayName'] rescue nil
end

#emailObject

Returns a user’s email.



63
64
65
# File 'lib/evri/rpx/user.rb', line 63

def email
  @json['profile']['email'] rescue nil
end

#facebook?Boolean

Returns true if this is a Facebook login.

Returns:

  • (Boolean)


84
85
86
# File 'lib/evri/rpx/user.rb', line 84

def facebook?
  provider_name == 'Facebook'
end

#google?Boolean

Returns true if this is a Google login.

Returns:

  • (Boolean)


79
80
81
# File 'lib/evri/rpx/user.rb', line 79

def google?
  provider_name == 'Google'
end

#identifierObject

Returns a unique identifier for this user.



42
43
44
# File 'lib/evri/rpx/user.rb', line 42

def identifier
  @json['profile']['identifier'] rescue nil
end

#nameObject

Returns the person’s full name (aka David Balatero)



27
28
29
# File 'lib/evri/rpx/user.rb', line 27

def name
  @json['profile']['name']['formatted'] rescue nil
end

#other?Boolean

Returns true if this provider is unknown / doesn’t have a specific name in the RPX system.

Returns:

  • (Boolean)


100
101
102
# File 'lib/evri/rpx/user.rb', line 100

def other?
  provider_name == 'Other'
end

#photoObject

Returns a photo URL for a user if they have one.



53
54
55
# File 'lib/evri/rpx/user.rb', line 53

def photo
  @json['profile']['photo'] rescue nil
end

#primary_keyObject

Returns the primary key for this user, if they have been mapped already.



48
49
50
# File 'lib/evri/rpx/user.rb', line 48

def primary_key
  @json['profile']['primaryKey'] rescue nil
end

#profile_urlObject

Returns a URL to a person’s profile on the 3rd-party site.



58
59
60
# File 'lib/evri/rpx/user.rb', line 58

def profile_url
  @json['profile']['url'] rescue nil
end

#provider_nameObject

Returns the provider name for this user, aka “Twitter”, “Google”. Also, see convenience methods such as #google?, #twitter?



69
70
71
# File 'lib/evri/rpx/user.rb', line 69

def provider_name
  @json['profile']['providerName'] rescue nil
end

#twitter?Boolean

Returns true if this is a Twitter login.

Returns:

  • (Boolean)


74
75
76
# File 'lib/evri/rpx/user.rb', line 74

def twitter?
  provider_name == 'Twitter'
end

#usernameObject

Returns a username for this user.



37
38
39
# File 'lib/evri/rpx/user.rb', line 37

def username
  @json['profile']['preferredUsername'] rescue nil
end

#windows_live?Boolean

Returns true if this is a Windows Live login.

Returns:

  • (Boolean)


94
95
96
# File 'lib/evri/rpx/user.rb', line 94

def windows_live?
  provider_name == 'Windows Live'
end

#yahoo?Boolean

Returns true if this is a Yahoo! login.

Returns:

  • (Boolean)


89
90
91
# File 'lib/evri/rpx/user.rb', line 89

def yahoo?
  provider_name == 'Yahoo!'
end