class BnetScraper::Starcraft2::Status

Ask the TL.net bot if Battle.Net is currently online for a given region. This page is updated every 5 minutes. Call fetch to refresh.

Examples:

BnetScraper::Starcraft2::Status.na  => 'Online'
BnetScraper::Starcraft2::Status.fea => 'Offline'
BnetScraper::Starcraft2::Status.cn  => nil (China is unsupported)
BnetScraper::Starcraft2::Status.fetch => [
  {:region=>"North America", :status=>"Online"},{:region=>"Europe", :status=>"Online"},
  {:region=>"Korea", :status=>"Online"}, {:region=>"South-East Asia", :status=>"Online"}
]

Constants

SOURCE

Public Class Methods

fetch() click to toggle source
# File lib/bnet_scraper/starcraft2/status_scraper.rb, line 19
def fetch
  response = Faraday.get SOURCE
  servers = Nokogiri::HTML(response.body).css('.forumPost').first.css('span').to_a
  servers.each_slice(2).map do |server_info| 
    { region: server_info[0].text, status: server_info[1].text }
  end
end
method_missing(sym) click to toggle source
# File lib/bnet_scraper/starcraft2/status_scraper.rb, line 27
def method_missing sym
  status? sym if REGIONS.reject { |r| r == 'cn' }.include?(sym.to_s)
end

Private Class Methods

status?(region) click to toggle source
# File lib/bnet_scraper/starcraft2/status_scraper.rb, line 32
def status? region
  @status ||= fetch
  region_status = @status.find do |r|
    r[:region] == REGIONS[region.to_s][:label]
  end

  region_status[:status]
end