class Net::Twitter::Models::User
Attributes
Public Class Methods
Returns the existing Twitter
user matching the provided attributes or nil when the user is not found.
@return [Net::Twitter::Models::User] when the user is found. @return [nil] when the user is not found or suspended. @param [Hash] params the attributes to find a user by. @option params [String] :screen_name The Twitter
user’s screen name
(case-insensitive).
# File lib/net/twitter/models/user.rb, line 23 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser, Errors::SuspendedUser nil end
Returns the existing Twitter
user matching the provided attributes or raises an error when the user is not found or suspended.
@return [Net::Twitter::Models::User] the Twitter
user. @param [Hash] params the attributes to find a user by. @option params [String] :screen_name The Twitter
user’s screen name
(case-insensitive).
@raise [Net::Errors::UnknownUser] if the user cannot be found. @raise [Net::Errors::SuspendedUser] if the user account is suspended.
# File lib/net/twitter/models/user.rb, line 38 def self.find_by!(params = {}) request = Api::Request.new endpoint: 'users/show', params: params user_data = request.run new user_data rescue Errors::ResponseError => error case error.response when Net::HTTPNotFound then raise Errors::UnknownUser when Net::HTTPForbidden then raise Errors::SuspendedUser end end
# File lib/net/twitter/models/user.rb, line 10 def initialize(attrs = {}) attrs.each{|k, v| instance_variable_set("@#{k}", v) unless v.nil?} @follower_count = attrs['followers_count'] end
@return [Array<Net::Twitter::Models::User>] the Twitter
users. @param [Hash] conditions The attributes to find users by. @option conditions [Array<String>] screen_name
The Twitter
user’s
screen names (case-insensitive).
@raise [Net::Errors::TooManyUsers] when more than 100 Twitter
users
match the provided attributes.
# File lib/net/twitter/models/user.rb, line 59 def self.where(conditions = {}) params = to_where_params conditions request = Api::Request.new endpoint: 'users/lookup', params: params users_data = request.run users_data.map{|user_data| new user_data} rescue Errors::ResponseError => error case error.response when Net::HTTPNotFound then [] when Net::HTTPForbidden then raise Errors::TooManyUsers end end
Private Class Methods
# File lib/net/twitter/models/user.rb, line 73 def self.to_where_params(conditions = {}) conditions.dup.tap do |params| params.each{|k,v| params[k] = v.join(',') if v.is_a?(Array)} end end