Class: SocialNet::Twitter::Models::User
- Inherits:
-
Object
- Object
- SocialNet::Twitter::Models::User
- Defined in:
- lib/social_net/twitter/models/user.rb
Instance Attribute Summary collapse
-
#follower_count ⇒ Object
readonly
Returns the value of attribute follower_count.
-
#screen_name ⇒ Object
readonly
Returns the value of attribute screen_name.
Class Method Summary collapse
-
.find_by(params = {}) ⇒ SocialNet::Twitter::Models::User?
Returns the existing Twitter user matching the provided attributes or nil when the user is not found.
-
.find_by!(params = {}) ⇒ SocialNet::Twitter::Models::User
Returns the existing Twitter user matching the provided attributes or raises an error when the user is not found or suspended.
-
.where(conditions = {}) ⇒ Array<SocialNet::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 13 |
# File 'lib/social_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 |
Instance Attribute Details
#follower_count ⇒ Object (readonly)
Returns the value of attribute follower_count.
8 9 10 |
# File 'lib/social_net/twitter/models/user.rb', line 8 def follower_count @follower_count end |
#screen_name ⇒ Object (readonly)
Returns the value of attribute screen_name.
8 9 10 |
# File 'lib/social_net/twitter/models/user.rb', line 8 def screen_name @screen_name end |
Class Method Details
.find_by(params = {}) ⇒ SocialNet::Twitter::Models::User?
Returns the existing Twitter user matching the provided attributes or nil when the user is not found.
23 24 25 26 27 |
# File 'lib/social_net/twitter/models/user.rb', line 23 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser, Errors::SuspendedUser nil end |
.find_by!(params = {}) ⇒ SocialNet::Twitter::Models::User
Returns the existing Twitter user matching the provided attributes or raises an error when the user is not found or suspended.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/social_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 |
.where(conditions = {}) ⇒ Array<SocialNet::Twitter::Models::User>
Returns the Twitter users.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/social_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 |