Class: SocialNet::Instagram::Models::User
- Inherits:
-
Object
- Object
- SocialNet::Instagram::Models::User
- Defined in:
- lib/social_net/instagram/models/user.rb
Instance Attribute Summary collapse
-
#follower_count ⇒ Object
readonly
Returns the value of attribute follower_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.find_by(params = {}) ⇒ SocialNet::Instagram::Models::User?
Returns the existing Instagram user matching the provided attributes or nil when the user is not found.
-
.find_by!(params = {}) ⇒ SocialNet::Instagram::Models::User
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.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ User
constructor
A new instance of User.
-
#videos ⇒ SocialNet::Instagram::Models::Video
Returns the existing Instagram user’s most recent videos.
Constructor Details
#initialize(attrs = {}) ⇒ User
Returns a new instance of User.
11 12 13 14 15 |
# 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 |
Instance Attribute Details
#follower_count ⇒ Object (readonly)
Returns the value of attribute follower_count.
9 10 11 |
# File 'lib/social_net/instagram/models/user.rb', line 9 def follower_count @follower_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/social_net/instagram/models/user.rb', line 9 def id @id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/social_net/instagram/models/user.rb', line 9 def username @username end |
Class Method Details
.find_by(params = {}) ⇒ SocialNet::Instagram::Models::User?
Returns the existing Instagram user matching the provided attributes or nil when the user is not found.
38 39 40 41 42 |
# 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 |
.find_by!(params = {}) ⇒ SocialNet::Instagram::Models::User
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.
54 55 56 57 58 59 60 |
# 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 |
Instance Method Details
#videos ⇒ SocialNet::Instagram::Models::Video
Returns the existing Instagram user’s most recent videos
20 21 22 23 24 25 26 27 28 |
# 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 |