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

Returns a new instance of User.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/adnruby.rb', line 47

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

Instance Attribute Details

#avatar_imageObject

Returns the value of attribute avatar_image.



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

def avatar_image
  @avatar_image
end

#countsObject

Returns the value of attribute counts.



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

def counts
  @counts
end

#cover_imageObject

Returns the value of attribute cover_image.



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

def cover_image
  @cover_image
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#follows_youObject

Returns the value of attribute follows_you.



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

def follows_you
  @follows_you
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#is_followerObject

Returns the value of attribute is_follower.



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

def is_follower
  @is_follower
end

#is_followingObject

Returns the value of attribute is_following.



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

def is_following
  @is_following
end

#is_mutedObject

Returns the value of attribute is_muted.



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

def is_muted
  @is_muted
end

#localeObject

Returns the value of attribute locale.



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

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#timezoneObject

Returns the value of attribute timezone.



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

def timezone
  @timezone
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#user_idObject

Returns the value of attribute user_id.



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

def user_id
  @user_id
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

#you_followObject

Returns the value of attribute you_follow.



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

def you_follow
  @you_follow
end

#you_mutedObject

Returns the value of attribute you_muted.



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

def you_muted
  @you_muted
end

Instance Method Details

#detailsObject



64
65
66
67
68
69
70
71
72
# File 'lib/adnruby.rb', line 64

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

#follow(user) ⇒ Object

Followers/Users



77
78
79
80
81
# File 'lib/adnruby.rb', line 77

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

#followersObject



89
90
91
92
# File 'lib/adnruby.rb', line 89

def followers
  result = ADN::API::User.followers(@user_id)
  result["data"].collect { |u| User.new(u) } unless result.has_error?
end

#followingObject



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

def following
  result = ADN::API::User.following(@user_id)
  result["data"].collect { |u| User.new(u) } unless result.has_error?
end

#has_error?Boolean

Errors

Returns:

  • (Boolean)


139
140
141
# File 'lib/adnruby.rb', line 139

def has_error?
  self.id.nil?
end

#mentions(params = nil) ⇒ Object



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

def mentions(params = nil)
  result = ADN::API::Post.mentioning_user(@user_id, params)
  result["data"].collect { |p| Post.new(p) } unless result.has_error?
end

#mute(user) ⇒ Object

Mute



102
103
104
105
106
# File 'lib/adnruby.rb', line 102

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

#mute_listObject



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

def mute_list
  result = ADN.get("/stream/0/users/me/muted")
  result["data"].collect { |u| User.new(u) } unless result.has_error?
end

#posts(params = nil) ⇒ Object

Posts



122
123
124
125
# File 'lib/adnruby.rb', line 122

def posts(params = nil)
  result = ADN::API::Post.by_user(@user_id, params)
  result["data"].collect { |p| Post.new(p) } unless result.has_error?
end

#stream(params = nil) ⇒ Object



127
128
129
130
# File 'lib/adnruby.rb', line 127

def stream(params = nil)
  result = ADN::API::Post.stream(params)
  result["data"].collect { |p| Post.new(p) } unless result.has_error?
end

#unfollow(user) ⇒ Object



83
84
85
86
87
# File 'lib/adnruby.rb', line 83

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

#unmute(user) ⇒ Object



108
109
110
111
112
# File 'lib/adnruby.rb', line 108

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