Class: ADN::User
- Inherits:
-
Object
- Object
- ADN::User
- Defined in:
- lib/adn/user.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.
Class Method Summary collapse
Instance Method Summary collapse
- #details ⇒ Object
- #follow(user) ⇒ Object
- #followers ⇒ Object
- #following ⇒ Object
-
#get_user(user) ⇒ Object
Followers/Users.
- #has_error? ⇒ Boolean
-
#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.
- #set_values(values) ⇒ Object
- #stream(params = nil) ⇒ Object
- #unfollow(user) ⇒ Object
- #unmute(user) ⇒ Object
Constructor Details
#initialize(user) ⇒ User
Returns a new instance of User.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/adn/user.rb', line 16 def initialize(user) if user.respond_to?(:each_pair) set_values(user) self.user_id = id.to_s else self.user_id = user.to_s user_details = details if details.has_key? "data" set_values(user_details["data"]) end end end |
Instance Attribute Details
#avatar_image ⇒ Object
Returns the value of attribute avatar_image.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def avatar_image @avatar_image end |
#counts ⇒ Object
Returns the value of attribute counts.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def counts @counts end |
#cover_image ⇒ Object
Returns the value of attribute cover_image.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def cover_image @cover_image end |
#created_at ⇒ Object
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def description @description end |
#follows_you ⇒ Object
Returns the value of attribute follows_you.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def follows_you @follows_you end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def id @id end |
#is_follower ⇒ Object
Returns the value of attribute is_follower.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def is_follower @is_follower end |
#is_following ⇒ Object
Returns the value of attribute is_following.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def is_following @is_following end |
#is_muted ⇒ Object
Returns the value of attribute is_muted.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def is_muted @is_muted end |
#locale ⇒ Object
Returns the value of attribute locale.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def locale @locale end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def name @name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def timezone @timezone end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def type @type end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def user_id @user_id end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def username @username end |
#you_follow ⇒ Object
Returns the value of attribute you_follow.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def you_follow @you_follow end |
#you_muted ⇒ Object
Returns the value of attribute you_muted.
6 7 8 |
# File 'lib/adn/user.rb', line 6 def you_muted @you_muted end |
Class Method Details
Instance Method Details
#details ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/adn/user.rb', line 29 def details if id Hash[self.instance_variables.map { |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)]}] else ADN::API::User.retrieve(user_id) end end |
#follow(user) ⇒ Object
47 48 49 50 51 |
# File 'lib/adn/user.rb', line 47 def follow(user) user_id = get_user(user) result = ADN.post("/stream/0/users/#{user_id}/follow") ADN.create_instance(result["data"], User) end |
#followers ⇒ Object
59 60 61 62 |
# File 'lib/adn/user.rb', line 59 def followers result = ADN::API::User.followers(user_id) ADN.create_collection(result["data"], User) end |
#following ⇒ Object
64 65 66 67 |
# File 'lib/adn/user.rb', line 64 def following result = ADN::API::User.following(user_id) ADN.create_collection(result["data"], User) end |
#get_user(user) ⇒ Object
Followers/Users
43 44 45 |
# File 'lib/adn/user.rb', line 43 def get_user(user) user.is_a?(ADN::User) ? user.id : user end |
#has_error? ⇒ Boolean
109 110 111 |
# File 'lib/adn/user.rb', line 109 def has_error? self.id.nil? end |
#mentions(params = nil) ⇒ Object
100 101 102 103 |
# File 'lib/adn/user.rb', line 100 def mentions(params = nil) result = ADN::API::Post.mentioning_user(user_id, params) ADN.create_collection(result["data"], Post) end |
#mute(user) ⇒ Object
Mute
71 72 73 74 75 |
# File 'lib/adn/user.rb', line 71 def mute(user) user_id = get_user(user) result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute") ADN.create_instance(result["data"], User) end |
#mute_list ⇒ Object
83 84 85 86 |
# File 'lib/adn/user.rb', line 83 def mute_list result = ADN.get("#{ADN::API_ENDPOINT_USERS}/me/muted") ADN.create_collection(result["data"], User) end |
#posts(params = nil) ⇒ Object
Posts
90 91 92 93 |
# File 'lib/adn/user.rb', line 90 def posts(params = nil) result = ADN::API::Post.by_user(user_id, params) ADN.create_collection(result["data"], Post) end |
#set_values(values) ⇒ Object
105 106 107 |
# File 'lib/adn/user.rb', line 105 def set_values(values) values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } end |
#stream(params = nil) ⇒ Object
95 96 97 98 |
# File 'lib/adn/user.rb', line 95 def stream(params = nil) result = ADN::API::Post.stream(params) ADN.create_collection(result["data"], Post) end |
#unfollow(user) ⇒ Object
53 54 55 56 57 |
# File 'lib/adn/user.rb', line 53 def unfollow(user) user_id = get_user(user) result = ADN.delete("/stream/0/users/#{user_id}/follow") ADN.create_instance(result["data"], User) end |
#unmute(user) ⇒ Object
77 78 79 80 81 |
# File 'lib/adn/user.rb', line 77 def unmute(user) user_id = get_user(user) result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user_id}/mute") ADN.create_instance(result["data"], User) end |