class SocialNet::Instagram::Models::User
Attributes
Public Class Methods
Returns the existing Instagram
user matching the provided attributes or nil when the user is not found.
@return [SocialNet::Instagram::Models::User] when the user is found. @return [nil] when the user is not found or has a private account. @param [Hash] params the attributes to find a user by. @option params [String] :username The Instagram
user’s username
(case-insensitive).
# File lib/social_net/instagram/models/user.rb, line 38 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser, Errors::PrivateUser nil end
Returns the existing Instagram
user matching the provided attributes or nil when the user is not found, and raises an error when the user account is private.
@return [SocialNet::Instagram::Models::User] the Instagram
user. @param [Hash] params the attributes to find a user by. @option params [String] :username The Instagram
user’s username
(case-insensitive).
@option params [String] :id The Instagram
user’s id
(case-insensitive).
@raise [SocialNet::Errors::PrivateUser] if the user account is private.
# File lib/social_net/instagram/models/user.rb, line 54 def self.find_by!(params = {}) if params[:username] find_by_username! params[:username] elsif params[:id] find_by_id! params[:id] end end
# File lib/social_net/instagram/models/user.rb, line 11 def initialize(attrs = {}) @id = attrs['id'] @username = attrs[:username] @follower_count = attrs['counts']['followed_by'] if attrs['counts'] end
Private Class Methods
# File lib/social_net/instagram/models/user.rb, line 74 def self.find_by_id!(id) request = Api::Request.new endpoint: "users/#{id}" new request.run rescue Errors::ResponseError => error case error.response when Net::HTTPBadRequest then raise Errors::PrivateUser end end
# File lib/social_net/instagram/models/user.rb, line 64 def self.find_by_username!(username) request = Api::Request.new endpoint: "users/search", params: {q: username} users = Array.wrap request.run if user = users.find{|u| u['username'].casecmp(username).zero?} find_by_id! user['id'] else raise Errors::UnknownUser end end
Public Instance Methods
Returns the existing Instagram
user's most recent videos
@return [SocialNet::Instagram::Models::Video] when the videos are found.
# File lib/social_net/instagram/models/user.rb, line 20 def videos request = Api::ScrapeUserVideosRequest.new username: @username request.run rescue Errors::ResponseError => error case error.response when Net::HTTPBadRequest then raise Errors::UnknownUser when Net::HTTPNotFound then raise Errors::UnknownUser end end