Class: Net::Twitter::Models::User
- Inherits:
-
Object
- Object
- Net::Twitter::Models::User
- Defined in:
- lib/net/twitter/models/user.rb
Instance Attribute Summary collapse
-
#followers_count ⇒ Object
readonly
Returns the value of attribute followers_count.
-
#screen_name ⇒ Object
readonly
Returns the value of attribute screen_name.
Class Method Summary collapse
-
.find_by(params = {}) ⇒ Net::Twitter::Models::User?
Returns the existing Twitter user matching the provided attributes or nil when the user is not found.
-
.find_by!(params = {}) ⇒ Net::Twitter::Models::User
Returns the existing Twitter user matching the provided attributes or raises an error when the user is not found or suspended.
- .to_where_params(conditions = {}) ⇒ Object
-
.where(conditions = {}) ⇒ Array<Net::Twitter::Models::User>
The Twitter users.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(attrs = {}) ⇒ User
Returns a new instance of User.
10 11 12 |
# File 'lib/net/twitter/models/user.rb', line 10 def initialize(attrs = {}) attrs.each{|k, v| instance_variable_set("@#{k}", v) unless v.nil?} end |
Instance Attribute Details
#followers_count ⇒ Object (readonly)
Returns the value of attribute followers_count.
8 9 10 |
# File 'lib/net/twitter/models/user.rb', line 8 def followers_count @followers_count end |
#screen_name ⇒ Object (readonly)
Returns the value of attribute screen_name.
8 9 10 |
# File 'lib/net/twitter/models/user.rb', line 8 def screen_name @screen_name end |
Class Method Details
.find_by(params = {}) ⇒ Net::Twitter::Models::User?
Returns the existing Twitter user matching the provided attributes or nil when the user is not found.
22 23 24 25 26 |
# File 'lib/net/twitter/models/user.rb', line 22 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser, Errors::SuspendedUser nil end |
.find_by!(params = {}) ⇒ Net::Twitter::Models::User
Returns the existing Twitter user matching the provided attributes or raises an error when the user is not found or suspended.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/net/twitter/models/user.rb', line 37 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 |
.to_where_params(conditions = {}) ⇒ Object
72 73 74 75 76 |
# File 'lib/net/twitter/models/user.rb', line 72 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 |
.where(conditions = {}) ⇒ Array<Net::Twitter::Models::User>
Returns the Twitter users.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/net/twitter/models/user.rb', line 58 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 |