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) ⇒ 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_imageObject

Returns the value of attribute avatar_image.



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

def avatar_image
  @avatar_image
end

#countsObject

Returns the value of attribute counts.



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

def counts
  @counts
end

#cover_imageObject

Returns the value of attribute cover_image.



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

def cover_image
  @cover_image
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#follows_youObject

Returns the value of attribute follows_you.



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

def follows_you
  @follows_you
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#is_followerObject

Returns the value of attribute is_follower.



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

def is_follower
  @is_follower
end

#is_followingObject

Returns the value of attribute is_following.



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

def is_following
  @is_following
end

#is_mutedObject

Returns the value of attribute is_muted.



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

def is_muted
  @is_muted
end

#localeObject

Returns the value of attribute locale.



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

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#timezoneObject

Returns the value of attribute timezone.



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

def timezone
  @timezone
end

#typeObject

Returns the value of attribute type.



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

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.



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

def username
  @username
end

#you_followObject

Returns the value of attribute you_follow.



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

def you_follow
  @you_follow
end

#you_mutedObject

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

.meObject



12
13
14
# File 'lib/adn/user.rb', line 12

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

Instance Method Details

#detailsObject



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

#followersObject



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

#followingObject



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

Returns:

  • (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_listObject



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