Class: SocialNet::Facebook::Models::User
- Inherits:
-
Object
- Object
- SocialNet::Facebook::Models::User
- Defined in:
- lib/social_net/facebook/models/user.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
Class Method Summary collapse
-
.find_by(params = {}) ⇒ SocialNet::Facebook::Models::User
Returns the existing Facebook user matching the provided attributes or nil when the user is not found.
-
.find_by!(params = {}) ⇒ SocialNet::Facebook::Models::User
Returns the existing Facebook user matching the provided attributes or raises an error when the user is not found.
Instance Method Summary collapse
- #find_video(id) ⇒ Object
-
#initialize(attrs = {}) ⇒ User
constructor
A new instance of User.
- #pages ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ User
Returns a new instance of User.
12 13 14 15 16 17 18 19 20 |
# File 'lib/social_net/facebook/models/user.rb', line 12 def initialize(attrs = {}) @id = attrs['id'] @email = attrs['email'] @gender = attrs['gender'] @user_name = attrs[:user_name] @first_name = attrs['first_name'] @last_name = attrs['last_name'] @access_token = attrs['access_token'] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def access_token @access_token end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def email @email end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def first_name @first_name end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def gender @gender end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def id @id end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def last_name @last_name end |
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
10 11 12 |
# File 'lib/social_net/facebook/models/user.rb', line 10 def user_name @user_name end |
Class Method Details
.find_by(params = {}) ⇒ SocialNet::Facebook::Models::User
Returns the existing Facebook user matching the provided attributes or nil when the user is not found.
@ return [nil] when the user cannot be found.
49 50 51 52 53 |
# File 'lib/social_net/facebook/models/user.rb', line 49 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser nil end |
.find_by!(params = {}) ⇒ SocialNet::Facebook::Models::User
Returns the existing Facebook user matching the provided attributes or raises an error when the user is not found.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/social_net/facebook/models/user.rb', line 65 def self.find_by!(params = {}) request = Api::Request.new params if params[:access_token] new request.run.merge!({"access_token" => params[:access_token]}) else new request.run end rescue Errors::ResponseError => error case error.response when Net::HTTPNotFound then raise Errors::UnknownUser end end |
Instance Method Details
#find_video(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/social_net/facebook/models/user.rb', line 28 def find_video(id) request = Api::ScrapeRequest.new video_id: id, username: @user_name video = request.run Models::Video.new video rescue Errors::ResponseError => error case error.response when Net::HTTPBadRequest then raise Errors::UnknownVideo when Net::HTTPNotFound then raise Errors::UnknownVideo end end |