Class: Snooby::User

Inherits:
Object
  • Object
show all
Includes:
About, Comments, Compose, Posts
Defined in:
lib/snooby/user.rb

Instance Method Summary collapse

Methods included from About

#about

Methods included from Posts

#posts

Methods included from Comments

#comments

Methods included from Compose

#compose

Constructor Details

#initialize(name) ⇒ User



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

def initialize(name)
  @name = name
  @kind = 'user'
end

Instance Method Details

#disliked(count = 25) ⇒ Object



31
32
33
# File 'lib/snooby/user.rb', line 31

def disliked(count = 25)
  Snooby.build Post, :disliked, @name, count
end

#friend(un = '') ⇒ Object



39
40
41
42
# File 'lib/snooby/user.rb', line 39

def friend(un = '')
  data = {:name => @name, :type => 'friend', :container => Snooby.active.id}
  Snooby.request Paths[:"#{un}friend"], data
end

#hidden(count = 25) ⇒ Object



35
36
37
# File 'lib/snooby/user.rb', line 35

def hidden(count = 25)
  Snooby.build Post, :hidden, @name, count
end

#karma_breakdownObject



21
22
23
24
25
# File 'lib/snooby/user.rb', line 21

def karma_breakdown
  html = Snooby.request(Paths[:user] % @name + '?limit=1', 'html')
  rx = /h>(.+?)<.+?(\d+).+?(\d+)/
  Hash[html.split('y>')[2].scan(rx).map { |r| [r.shift, r.map(&:to_i)] }]
end

#liked(count = 25) ⇒ Object



27
28
29
# File 'lib/snooby/user.rb', line 27

def liked(count = 25)
  Snooby.build Post, :liked, @name, count
end

#trophiesObject

Returns an array of arrays containing the user’s trophy information in the form of [name, description], the latter containing the empty string if inapplicable.



14
15
16
17
18
19
# File 'lib/snooby/user.rb', line 14

def trophies
  # Only interested in trophies; request the minimum amount of content.
  html = Snooby.request(Paths[:user] % @name + '?limit=1', 'html')
  # Entry-level black magic.
  html.scan /"trophy-name">(.+?)<.+?"\s?>([^<]*)</
end

#unfriendObject



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

def unfriend
  friend 'un'
end