Class: ADN::User
- Inherits:
-
Object
- Object
- ADN::User
- Defined in:
- lib/adnruby.rb
Instance Attribute Summary collapse
-
#avatar_image ⇒ Object
Returns the value of attribute avatar_image.
-
#counts ⇒ Object
Returns the value of attribute counts.
-
#cover_image ⇒ Object
Returns the value of attribute cover_image.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#follows_you ⇒ Object
Returns the value of attribute follows_you.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_follower ⇒ Object
Returns the value of attribute is_follower.
-
#is_following ⇒ Object
Returns the value of attribute is_following.
-
#is_muted ⇒ Object
Returns the value of attribute is_muted.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#name ⇒ Object
Returns the value of attribute name.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#username ⇒ Object
Returns the value of attribute username.
-
#you_follow ⇒ Object
Returns the value of attribute you_follow.
-
#you_muted ⇒ Object
Returns the value of attribute you_muted.
Instance Method Summary collapse
- #details ⇒ Object
-
#follow(user) ⇒ Object
Followers/Users.
- #followers ⇒ Object
- #following ⇒ Object
-
#has_error? ⇒ Boolean
Errors.
-
#initialize(user) ⇒ User
constructor
A new instance of User.
- #mentions(params = nil) ⇒ Object
-
#mute(user) ⇒ Object
Mute.
- #mute_list ⇒ Object
-
#posts(params = nil) ⇒ Object
Posts.
- #stream(params = nil) ⇒ Object
- #unfollow(user) ⇒ Object
- #unmute(user) ⇒ Object
Constructor Details
#initialize(user) ⇒ User
Returns a new instance of User.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/adnruby.rb', line 47 def initialize(user) if user.is_a? Hash user.each do |k, v| self.instance_variable_set "@#{k}", v end @user_id = self.id else @user_id = user details = self.details if details.has_key? "data" details["data"].each do |k, v| self.instance_variable_set "@#{k}", v end end end end |
Instance Attribute Details
#avatar_image ⇒ Object
Returns the value of attribute avatar_image.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def avatar_image @avatar_image end |
#counts ⇒ Object
Returns the value of attribute counts.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def counts @counts end |
#cover_image ⇒ Object
Returns the value of attribute cover_image.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def cover_image @cover_image end |
#created_at ⇒ Object
Returns the value of attribute created_at.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def description @description end |
#follows_you ⇒ Object
Returns the value of attribute follows_you.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def follows_you @follows_you end |
#id ⇒ Object
Returns the value of attribute id.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def id @id end |
#is_follower ⇒ Object
Returns the value of attribute is_follower.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def is_follower @is_follower end |
#is_following ⇒ Object
Returns the value of attribute is_following.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def is_following @is_following end |
#is_muted ⇒ Object
Returns the value of attribute is_muted.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def is_muted @is_muted end |
#locale ⇒ Object
Returns the value of attribute locale.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def locale @locale end |
#name ⇒ Object
Returns the value of attribute name.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def name @name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def timezone @timezone end |
#type ⇒ Object
Returns the value of attribute type.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def type @type end |
#user_id ⇒ Object
Returns the value of attribute user_id.
44 45 46 |
# File 'lib/adnruby.rb', line 44 def user_id @user_id end |
#username ⇒ Object
Returns the value of attribute username.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def username @username end |
#you_follow ⇒ Object
Returns the value of attribute you_follow.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def you_follow @you_follow end |
#you_muted ⇒ Object
Returns the value of attribute you_muted.
45 46 47 |
# File 'lib/adnruby.rb', line 45 def you_muted @you_muted end |
Instance Method Details
#details ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/adnruby.rb', line 64 def details if self.id h = {} self.instance_variables.each { |iv| h[iv.to_s.gsub(/[^a-zA-Z0-9_]/, '')] = self.instance_variable_get(iv) } h else ADN::API::User.retrieve(@user_id) end end |
#follow(user) ⇒ Object
Followers/Users
77 78 79 80 81 |
# File 'lib/adnruby.rb', line 77 def follow(user) user_id = user.is_a?(ADN::User) ? user.id : user result = ADN.post("/stream/0/users/#{user_id}/follow") User.new(result["data"]) unless result.has_error? end |
#followers ⇒ Object
89 90 91 92 |
# File 'lib/adnruby.rb', line 89 def followers result = ADN::API::User.followers(@user_id) result["data"].collect { |u| User.new(u) } unless result.has_error? end |
#following ⇒ Object
94 95 96 97 |
# File 'lib/adnruby.rb', line 94 def following result = ADN::API::User.following(@user_id) result["data"].collect { |u| User.new(u) } unless result.has_error? end |
#has_error? ⇒ Boolean
Errors
139 140 141 |
# File 'lib/adnruby.rb', line 139 def has_error? self.id.nil? end |
#mentions(params = nil) ⇒ Object
132 133 134 135 |
# File 'lib/adnruby.rb', line 132 def mentions(params = nil) result = ADN::API::Post.mentioning_user(@user_id, params) result["data"].collect { |p| Post.new(p) } unless result.has_error? end |
#mute(user) ⇒ Object
Mute
102 103 104 105 106 |
# File 'lib/adnruby.rb', line 102 def mute(user) user_id = user.is_a?(ADN::User) ? user.id : user result = ADN.post("/stream/0/users/#{user_id}/mute") User.new(result["data"]) unless result.has_error? end |
#mute_list ⇒ Object
114 115 116 117 |
# File 'lib/adnruby.rb', line 114 def mute_list result = ADN.get("/stream/0/users/me/muted") result["data"].collect { |u| User.new(u) } unless result.has_error? end |
#posts(params = nil) ⇒ Object
Posts
122 123 124 125 |
# File 'lib/adnruby.rb', line 122 def posts(params = nil) result = ADN::API::Post.by_user(@user_id, params) result["data"].collect { |p| Post.new(p) } unless result.has_error? end |
#stream(params = nil) ⇒ Object
127 128 129 130 |
# File 'lib/adnruby.rb', line 127 def stream(params = nil) result = ADN::API::Post.stream(params) result["data"].collect { |p| Post.new(p) } unless result.has_error? end |
#unfollow(user) ⇒ Object
83 84 85 86 87 |
# File 'lib/adnruby.rb', line 83 def unfollow(user) user_id = user.is_a?(ADN::User) ? user.id : user result = ADN.delete("/stream/0/users/#{user_id}/follow") User.new(result["data"]) unless result.has_error? end |
#unmute(user) ⇒ Object
108 109 110 111 112 |
# File 'lib/adnruby.rb', line 108 def unmute(user) user_id = user.is_a?(ADN::User) ? user.id : user result = ADN.delete("/stream/0/users/#{user_id}/mute") User.new(result["data"]) unless result.has_error? end |