Class: Cinch::Plugins::Starcraft::User

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
lib/cinch/plugins/starcraft/user.rb

Instance Method Summary collapse

Instance Method Details

#get_characterObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/cinch/plugins/starcraft/user.rb', line 14

def get_character
  begin
    sc2ranks = SC2Ranks::API.new('logankoester.com')
    sc2ranks.get_team_info(self.username, self.bnetid)
  rescue SC2Ranks::API::NoCharacterError => e
    m.reply "Character not found: #{e}"
  rescue Exception => e
    m.reply "Failed to fetch SC2Ranks data: #{e}"
  end
end

#queue_refresh!Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/cinch/plugins/starcraft/user.rb', line 36

def queue_refresh!
  url = "http://sc2ranks.com/char/refresh/#{self.region}/#{self.bnetid}/#{self.username}"
  doc = Nokogiri::HTML(open(url))
  resp = doc.css("html body div.charprofile div.w960 div.profile div.updated-container div.lastupdated div.refresh span.green").first.content
  if ( resp.is_a?(String) and resp.size < 140 ) 
    resp
  else
    "Unexpected response, try clicking #{url}"
  end
end

#update_from_url(url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cinch/plugins/starcraft/user.rb', line 25

def update_from_url(url)
  split = url.split(/.*sc2ranks.com\/(.+)\/(.+)\/(.+)/)
  self.url = url
  self.region = split[1]
  self.bnetid = split[2]
  self.username = split[3]

  doc = Nokogiri::HTML(open(url))
  self.feed = doc.xpath("//link/@href")[3].value
end