class SocialNet::Facebook::Models::User
Attributes
Public Class Methods
Returns the existing Facebook
user matching the provided attributes or nil when the user is not found.
@return [SocialNet::Facebook::Models::User] the Facebook
user. @ return [nil] when the user cannot be found. @param [Hash] params the attributes to find a user by. @option params [String] :username The Facebook
user's username
(case-insensitive).
@option params [String] :access_token The Facebook
user's access_token
(case-insensitive).
# File lib/social_net/facebook/models/user.rb, line 49 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser nil end
Returns the existing Facebook
user matching the provided attributes or raises an error when the user is not found.
@return [SocialNet::Facebook::Models::User] the Facebook
user. @param [Hash] params the attributes to find a user by. @option params [String] :username The Facebook
user's username
(case-insensitive).
@option params [String] :access_token The Facebook
user's access_token
(case-insensitive).
@raise [SocialNet::Errors::UnknownUser] if the user cannot be found.
# 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
# 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
Public Instance Methods
# 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
# File lib/social_net/facebook/models/user.rb, line 22 def pages request = Api::Request.new access_token: @access_token, path: "/v2.3/#{@id}/accounts" page_json = request.run page_json['data'].map { |h| h.slice("name", "id") } if page_json['data'].any? end