Class: ADN::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id) ⇒ User

Returns a new instance of User.



46
47
48
49
50
51
52
53
54
# File 'lib/adnruby.rb', line 46

def initialize(user_id)
  @user_id = user_id
  details = self.details
  if details.has_key? "data"
    details["data"].each do |k, v|
      self.instance_variable_set "@#{k}", v
    end
  end
end

Instance Attribute Details

#avatar_imageObject

Returns the value of attribute avatar_image.



44
45
46
# File 'lib/adnruby.rb', line 44

def avatar_image
  @avatar_image
end

#countsObject

Returns the value of attribute counts.



44
45
46
# File 'lib/adnruby.rb', line 44

def counts
  @counts
end

#cover_imageObject

Returns the value of attribute cover_image.



44
45
46
# File 'lib/adnruby.rb', line 44

def cover_image
  @cover_image
end

#created_atObject

Returns the value of attribute created_at.



44
45
46
# File 'lib/adnruby.rb', line 44

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



44
45
46
# File 'lib/adnruby.rb', line 44

def description
  @description
end

#follows_youObject

Returns the value of attribute follows_you.



44
45
46
# File 'lib/adnruby.rb', line 44

def follows_you
  @follows_you
end

#idObject

Returns the value of attribute id.



44
45
46
# File 'lib/adnruby.rb', line 44

def id
  @id
end

#is_followerObject

Returns the value of attribute is_follower.



44
45
46
# File 'lib/adnruby.rb', line 44

def is_follower
  @is_follower
end

#is_followingObject

Returns the value of attribute is_following.



44
45
46
# File 'lib/adnruby.rb', line 44

def is_following
  @is_following
end

#is_mutedObject

Returns the value of attribute is_muted.



44
45
46
# File 'lib/adnruby.rb', line 44

def is_muted
  @is_muted
end

#localeObject

Returns the value of attribute locale.



44
45
46
# File 'lib/adnruby.rb', line 44

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



44
45
46
# File 'lib/adnruby.rb', line 44

def name
  @name
end

#timezoneObject

Returns the value of attribute timezone.



44
45
46
# File 'lib/adnruby.rb', line 44

def timezone
  @timezone
end

#typeObject

Returns the value of attribute type.



44
45
46
# File 'lib/adnruby.rb', line 44

def type
  @type
end

#user_idObject

Returns the value of attribute user_id.



43
44
45
# File 'lib/adnruby.rb', line 43

def user_id
  @user_id
end

#usernameObject

Returns the value of attribute username.



44
45
46
# File 'lib/adnruby.rb', line 44

def username
  @username
end

#you_followObject

Returns the value of attribute you_follow.



44
45
46
# File 'lib/adnruby.rb', line 44

def you_follow
  @you_follow
end

#you_mutedObject

Returns the value of attribute you_muted.



44
45
46
# File 'lib/adnruby.rb', line 44

def you_muted
  @you_muted
end

Instance Method Details

#detailsObject



56
57
58
59
60
61
62
63
64
# File 'lib/adnruby.rb', line 56

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::Users.retrieve(@user_id)
  end
end

#follow(user) ⇒ Object

Followers/Users



69
70
71
72
73
# File 'lib/adnruby.rb', line 69

def follow(user)
  user_id = user.is_a?(ADN::User) ? user.id : user
  result = ADN.post("/stream/0/users/#{user_id}/follow")
  result["data"] unless result.has_error?
end

#followersObject



81
82
83
84
# File 'lib/adnruby.rb', line 81

def followers
  result = ADN::Users.followers(@user_id)
  result["data"] unless result.has_error?
end

#followingObject



86
87
88
89
# File 'lib/adnruby.rb', line 86

def following
  result = ADN::Users.following(@user_id)
  result["data"] unless result.has_error?
end

#has_error?Boolean

Errors

Returns:

  • (Boolean)


131
132
133
# File 'lib/adnruby.rb', line 131

def has_error?
  self.id.nil?
end

#mentions(params = nil) ⇒ Object



124
125
126
127
# File 'lib/adnruby.rb', line 124

def mentions(params = nil)
  result = ADN::Post.mentioning_user(@user_id, params)
  result["data"] unless result.has_error?
end

#mute(user) ⇒ Object

Mute



94
95
96
97
98
# File 'lib/adnruby.rb', line 94

def mute(user)
  user_id = user.is_a?(ADN::User) ? user.id : user
  result = ADN.post("/stream/0/users/#{user_id}/mute")
  result["data"] unless result.has_error?
end

#mute_listObject



106
107
108
109
# File 'lib/adnruby.rb', line 106

def mute_list
  result = ADN.get("/stream/0/users/me/muted")
  result["data"] unless result.has_error?
end

#posts(params = nil) ⇒ Object

Posts



114
115
116
117
# File 'lib/adnruby.rb', line 114

def posts(params = nil)
  result = ADN::Post.by_user(@user_id, params)
  result["data"] unless result.has_error?
end

#stream(params = nil) ⇒ Object



119
120
121
122
# File 'lib/adnruby.rb', line 119

def stream(params = nil)
  result = ADN::Post.stream(params)
  result["data"] unless result.has_error?
end

#unfollow(user) ⇒ Object



75
76
77
78
79
# File 'lib/adnruby.rb', line 75

def unfollow(user)
  user_id = user.is_a?(ADN::User) ? user.id : user
  result = ADN.delete("/stream/0/users/#{user_id}/follow")
  result["data"] unless result.has_error?
end

#unmute(user) ⇒ Object



100
101
102
103
104
# File 'lib/adnruby.rb', line 100

def unmute(user)
  user_id = user.is_a?(ADN::User) ? user.id : user
  result = ADN.delete("/stream/0/users/#{user_id}/mute")
  result["data"] unless result.has_error?
end