Class: SocialPlus::WebApi::User
- Inherits:
-
Object
- Object
- SocialPlus::WebApi::User
- Defined in:
- lib/social_plus/web_api/user.rb
Overview
A class which represents a user of Social Plus
Instance Attribute Summary collapse
-
#followers ⇒ Integer
readonly
The number of user’s followers(reaches).
-
#identifier ⇒ String
readonly
The user’s Social Plus ID.
-
#last_logged_in_provider ⇒ ActiveSupport::StringInquirer
readonly
The provider which the user has logged in most recently.
-
#profile ⇒ Profile
readonly
The user’s profile.
-
#providers ⇒ Array
readonly
The Providers which the user has logged in.
Class Method Summary collapse
-
.authenticate(api_client, token) ⇒ User
Fetch information of a user using a given one time token.
Instance Method Summary collapse
-
#initialize(params) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(params) ⇒ User
Returns a new instance of User.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/social_plus/web_api/user.rb', line 32 def initialize(params) raise ArgumentError, %q|missing 'user'| unless params.key?('user') user = params['user'] raise ArgumentError, %q|missing 'user/identifier'| unless user.key?('identifier') @identifier = user['identifier'] last_logged_in_provider = user['last_logged_in_provider'] || '' @last_logged_in_provider = last_logged_in_provider.inquiry.freeze @profile = SocialPlus::WebApi::Profile.new(params.slice('profile', 'email')).freeze @followers = params.key?('follow') && params['follow'].key?('followed_by') ? params['follow']['followed_by'] : 0 @providers = params['providers'] end |
Instance Attribute Details
#followers ⇒ Integer (readonly)
Returns The number of user’s followers(reaches).
53 54 55 |
# File 'lib/social_plus/web_api/user.rb', line 53 def followers @followers end |
#identifier ⇒ String (readonly)
Returns The user’s Social Plus ID.
47 48 49 |
# File 'lib/social_plus/web_api/user.rb', line 47 def identifier @identifier end |
#last_logged_in_provider ⇒ ActiveSupport::StringInquirer (readonly)
Returns The provider which the user has logged in most recently.
49 50 51 |
# File 'lib/social_plus/web_api/user.rb', line 49 def last_logged_in_provider @last_logged_in_provider end |
#profile ⇒ Profile (readonly)
Returns The user’s profile.
51 52 53 |
# File 'lib/social_plus/web_api/user.rb', line 51 def profile @profile end |
#providers ⇒ Array (readonly)
Returns The Providers which the user has logged in.
55 56 57 |
# File 'lib/social_plus/web_api/user.rb', line 55 def providers @providers end |
Class Method Details
.authenticate(api_client, token) ⇒ User
Fetch information of a user using a given one time token
16 17 18 19 20 |
# File 'lib/social_plus/web_api/user.rb', line 16 def authenticate(api_client, token) result = api_client.execute('authenticated_user', token: token, add_profile: true) result['providers'] = api_client.execute('providers_of_user', identifier: result['user']['identifier'])['providers'] new(result) end |