Class: SocialNet::Byte::Models::User
- Inherits:
-
Object
- Object
- SocialNet::Byte::Models::User
- Defined in:
- lib/social_net/byte/models/user.rb
Instance Attribute Summary collapse
-
#avatar_url ⇒ Object
readonly
Returns the value of attribute avatar_url.
-
#bio ⇒ Object
readonly
Returns the value of attribute bio.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#follower_count ⇒ Object
readonly
Returns the value of attribute follower_count.
-
#following_count ⇒ Object
readonly
Returns the value of attribute following_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#registration_date ⇒ Object
readonly
Returns the value of attribute registration_date.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.find_by(params = {}) ⇒ SocialNet::Byte::Models::User?
Returns the existing Byte user matching the provided attributes or nil when the user is not found.
-
.find_by!(params = {}) ⇒ SocialNet::Byte::Models::User
Returns the existing Byte 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.
-
#posts(opts = {}) ⇒ SocialNet::Byte::Models::Post
Returns the existing Byte user’s most recent posts.
Constructor Details
#initialize(attrs = {}) ⇒ User
Returns a new instance of User.
17 18 19 |
# File 'lib/social_net/byte/models/user.rb', line 17 def initialize(attrs = {}) attrs.each{|k, v| instance_variable_set("@#{k}", v) unless v.nil?} end |
Instance Attribute Details
#avatar_url ⇒ Object (readonly)
Returns the value of attribute avatar_url.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def avatar_url @avatar_url end |
#bio ⇒ Object (readonly)
Returns the value of attribute bio.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def bio @bio end |
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def display_name @display_name end |
#follower_count ⇒ Object (readonly)
Returns the value of attribute follower_count.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def follower_count @follower_count end |
#following_count ⇒ Object (readonly)
Returns the value of attribute following_count.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def following_count @following_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def id @id end |
#registration_date ⇒ Object (readonly)
Returns the value of attribute registration_date.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def registration_date @registration_date end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
8 9 10 |
# File 'lib/social_net/byte/models/user.rb', line 8 def username @username end |
Class Method Details
.find_by(params = {}) ⇒ SocialNet::Byte::Models::User?
Returns the existing Byte user matching the provided attributes or nil when the user is not found.
51 52 53 54 55 |
# File 'lib/social_net/byte/models/user.rb', line 51 def self.find_by(params = {}) find_by! params rescue Errors::UnknownUser nil end |
.find_by!(params = {}) ⇒ SocialNet::Byte::Models::User
Returns the existing Byte user matching the provided attributes or nil when the user is not found, and raises an error when the user account is private.
67 68 69 70 71 72 73 |
# File 'lib/social_net/byte/models/user.rb', line 67 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
#posts(opts = {}) ⇒ SocialNet::Byte::Models::Post
Returns the existing Byte user’s most recent posts
@ param [Hash] params the attributes to find paginated posts by.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/social_net/byte/models/user.rb', line 26 def posts(opts={}) params = {endpoint: "/account/id/#{@id}/posts"}.merge! opts request = Api::Request.new params posts_data = request.run {}.tap do |k,v| k[:posts] = posts_data['data']['posts'].map{|post| Post.new post.deep_transform_keys { |key| key.underscore.to_sym }} k[:next_page] = posts_data['data']['cursor'] end rescue Errors::ResponseError => error case error.response when Net::HTTPBadRequest then raise Errors::UnknownUser when Net::HTTPNotFound then raise Errors::UnknownUser end end |