Class: Evri::RPX::User
- Inherits:
-
Object
- Object
- Evri::RPX::User
- Defined in:
- lib/evri/rpx/user.rb
Defined Under Namespace
Classes: InvalidUserJsonError
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns a Credentials object for this user, or nil.
-
#json ⇒ Object
(also: #raw)
readonly
Returns the raw JSON returned by RPX, in case you want it.
Instance Method Summary collapse
-
#display_name ⇒ Object
Returns a name that should be displayed for this user.
-
#email ⇒ Object
Returns a user’s email.
-
#facebook? ⇒ Boolean
Returns true if this is a Facebook login.
-
#google? ⇒ Boolean
Returns true if this is a Google login.
-
#identifier ⇒ Object
Returns a unique identifier for this user.
-
#initialize(json) ⇒ User
constructor
A new instance of User.
-
#name ⇒ Object
Returns the person’s full name (aka David Balatero).
-
#other? ⇒ Boolean
Returns true if this provider is unknown / doesn’t have a specific name in the RPX system.
-
#photo ⇒ Object
Returns a photo URL for a user if they have one.
-
#primary_key ⇒ Object
Returns the primary key for this user, if they have been mapped already.
-
#profile_url ⇒ Object
Returns a URL to a person’s profile on the 3rd-party site.
-
#provider_name ⇒ Object
Returns the provider name for this user, aka “Twitter”, “Google”.
-
#twitter? ⇒ Boolean
Returns true if this is a Twitter login.
-
#username ⇒ Object
Returns a username for this user.
-
#windows_live? ⇒ Boolean
Returns true if this is a Windows Live login.
-
#yahoo? ⇒ Boolean
Returns true if this is a Yahoo! login.
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
#credentials ⇒ Object (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 |
#json ⇒ Object (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_name ⇒ Object
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 |
#email ⇒ Object
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.
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.
79 80 81 |
# File 'lib/evri/rpx/user.rb', line 79 def google? provider_name == 'Google' end |
#identifier ⇒ Object
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 |
#name ⇒ Object
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.
100 101 102 |
# File 'lib/evri/rpx/user.rb', line 100 def other? provider_name == 'Other' end |
#photo ⇒ Object
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_key ⇒ Object
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_url ⇒ Object
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_name ⇒ Object
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.
74 75 76 |
# File 'lib/evri/rpx/user.rb', line 74 def twitter? provider_name == 'Twitter' end |
#username ⇒ Object
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.
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.
89 90 91 |
# File 'lib/evri/rpx/user.rb', line 89 def yahoo? provider_name == 'Yahoo!' end |