Class: ADN::User
- Inherits:
-
Object
- Object
- ADN::User
- Defined in:
- lib/adn/user.rb
Instance Attribute Summary collapse
-
#app_data ⇒ Object
Returns the value of attribute app_data.
-
#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
-
#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.
-
#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
-
#follow(user) ⇒ Object
Followers/Users.
- #followers ⇒ Object
- #following ⇒ Object
-
#initialize(user_data = {}) ⇒ 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
- #valid_user? ⇒ Boolean
Constructor Details
#initialize(user_data = {}) ⇒ User
Returns a new instance of User.
22 23 24 |
# File 'lib/adn/user.rb', line 22 def initialize(user_data = {}) set_values(user_data) end |
Instance Attribute Details
#app_data ⇒ Object
Returns the value of attribute app_data.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def app_data @app_data end |
#avatar_image ⇒ Object
Returns the value of attribute avatar_image.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def avatar_image @avatar_image end |
#counts ⇒ Object
Returns the value of attribute counts.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def counts @counts end |
#cover_image ⇒ Object
Returns the value of attribute cover_image.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def cover_image @cover_image end |
#created_at ⇒ Object
26 27 28 |
# File 'lib/adn/user.rb', line 26 def created_at DateTime.parse(@created_at) end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def description @description end |
#follows_you ⇒ Object
Returns the value of attribute follows_you.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def follows_you @follows_you end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def id @id end |
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def locale @locale end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def name @name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def timezone @timezone end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/adn/user.rb', line 5 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.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def username @username end |
#you_follow ⇒ Object
Returns the value of attribute you_follow.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def you_follow @you_follow end |
#you_muted ⇒ Object
Returns the value of attribute you_muted.
5 6 7 |
# File 'lib/adn/user.rb', line 5 def you_muted @you_muted end |
Class Method Details
Instance Method Details
#follow(user) ⇒ Object
Followers/Users
32 33 34 35 |
# File 'lib/adn/user.rb', line 32 def follow(user) result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/follow") ADN.create_instance(result["data"], User) end |
#followers ⇒ Object
44 45 46 47 |
# File 'lib/adn/user.rb', line 44 def followers result = ADN::API::User.followers(user_id) ADN.create_collection(result["data"], User) end |
#following ⇒ Object
49 50 51 52 |
# File 'lib/adn/user.rb', line 49 def following result = ADN::API::User.following(user_id) ADN.create_collection(result["data"], User) end |
#mentions(params = nil) ⇒ Object
87 88 89 90 |
# File 'lib/adn/user.rb', line 87 def mentions(params = nil) result = ADN::API::Post.mentioning_user(user_id, params) ADN.create_collection(result["data"], Post) end |
#mute(user) ⇒ Object
Mute
56 57 58 59 60 61 |
# File 'lib/adn/user.rb', line 56 def mute(user) if user.valid_user? result = ADN.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute") ADN.create_instance(result["data"], User) end end |
#mute_list ⇒ Object
70 71 72 73 |
# File 'lib/adn/user.rb', line 70 def mute_list result = ADN.get("#{ADN::API_ENDPOINT_USERS}/me/muted") ADN.create_collection(result["data"], User) end |
#posts(params = nil) ⇒ Object
Posts
77 78 79 80 |
# File 'lib/adn/user.rb', line 77 def posts(params = nil) result = ADN::API::Post.by_user(user_id, params) ADN.create_collection(result["data"], Post) end |
#set_values(values) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/adn/user.rb', line 96 def set_values(values) if values.respond_to? :each_pair values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } self.user_id = id.to_s end end |
#stream(params = nil) ⇒ Object
82 83 84 85 |
# File 'lib/adn/user.rb', line 82 def stream(params = nil) result = ADN::API::Post.stream(params) ADN.create_collection(result["data"], Post) end |
#unfollow(user) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/adn/user.rb', line 37 def unfollow(user) if user.valid_user? result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/follow") ADN.create_instance(result["data"], User) end end |
#unmute(user) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/adn/user.rb', line 63 def unmute(user) if user.valid_user? result = ADN.delete("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute") ADN.create_instance(result["data"], User) end end |
#valid_user? ⇒ Boolean
92 93 94 |
# File 'lib/adn/user.rb', line 92 def valid_user? !!user_id.match(/^\d+$/) end |