Class: ADN::User

Inherits:
Object
  • Object
show all
Defined in:
lib/adn/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_dataObject

Returns the value of attribute app_data.



5
6
7
# File 'lib/adn/user.rb', line 5

def app_data
  @app_data
end

#avatar_imageObject

Returns the value of attribute avatar_image.



5
6
7
# File 'lib/adn/user.rb', line 5

def avatar_image
  @avatar_image
end

#countsObject

Returns the value of attribute counts.



5
6
7
# File 'lib/adn/user.rb', line 5

def counts
  @counts
end

#cover_imageObject

Returns the value of attribute cover_image.



5
6
7
# File 'lib/adn/user.rb', line 5

def cover_image
  @cover_image
end

#created_atObject



26
27
28
# File 'lib/adn/user.rb', line 26

def created_at
  DateTime.parse(@created_at)
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/adn/user.rb', line 5

def description
  @description
end

#follows_youObject

Returns the value of attribute follows_you.



5
6
7
# File 'lib/adn/user.rb', line 5

def follows_you
  @follows_you
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/adn/user.rb', line 5

def id
  @id
end

#localeObject

Returns the value of attribute locale.



5
6
7
# File 'lib/adn/user.rb', line 5

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/adn/user.rb', line 5

def name
  @name
end

#timezoneObject

Returns the value of attribute timezone.



5
6
7
# File 'lib/adn/user.rb', line 5

def timezone
  @timezone
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/adn/user.rb', line 5

def type
  @type
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'lib/adn/user.rb', line 5

def user_id
  @user_id
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/adn/user.rb', line 5

def username
  @username
end

#you_followObject

Returns the value of attribute you_follow.



5
6
7
# File 'lib/adn/user.rb', line 5

def you_follow
  @you_follow
end

#you_mutedObject

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

.find(user_id) ⇒ Object



18
19
20
# File 'lib/adn/user.rb', line 18

def self.find(user_id)
  new ADN::API::User.retrieve(user_id)['data']
end

.meObject



14
15
16
# File 'lib/adn/user.rb', line 14

def self.me
  new ADN::API::Token.current["user"]
end

Instance Method Details

#follow(user) ⇒ Object

Followers/Users



32
33
34
35
# File 'lib/adn/user.rb', line 32

def follow(user)
  result = ADN::API.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/follow")
  ADN.create_instance(result["data"], User)
end

#followersObject



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

#followingObject



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::API.post("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute")
    ADN.create_instance(result["data"], User)
  end
end

#mute_listObject



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::API.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::API.delete("#{ADN::API_ENDPOINT_USERS}/#{user.user_id}/mute")
    ADN.create_instance(result["data"], User)
  end
end

#valid_user?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/adn/user.rb', line 92

def valid_user?
  !!user_id.match(/^\d+$/)
end