Class: XblGamercard::LiveProfile

Inherits:
Object
  • Object
show all
Includes:
MicroScraper
Defined in:
lib/xbl_gamercard/live_profile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MicroScraper

included

Constructor Details

#initialize(html) ⇒ LiveProfile

Returns a new instance of LiveProfile.



12
13
14
# File 'lib/xbl_gamercard/live_profile.rb', line 12

def initialize(html)
  @element = Nokogiri::HTML(html)
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



10
11
12
# File 'lib/xbl_gamercard/live_profile.rb', line 10

def element
  @element
end

Class Method Details

.fetch(gamertag) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/xbl_gamercard/live_profile.rb', line 30

def self.fetch(gamertag)
  uri = URI(self.url_for(gamertag))
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.request_uri)

  response = http.request(request)
  return self.new(response.body)
end

.url_for(gamertag) ⇒ Object



41
42
43
# File 'lib/xbl_gamercard/live_profile.rb', line 41

def self.url_for(gamertag)
  return "https://live.xbox.com/en-US/Profile?Gamertag=#{CGI.escape(gamertag)}"
end

Instance Method Details

#avatar_image_urlObject



26
27
28
# File 'lib/xbl_gamercard/live_profile.rb', line 26

def avatar_image_url
  "https://avatar-ssl.xboxlive.com/avatar/#{URI.escape(gamertag)}/avatar-body.png"
end