Class: XboxLive::AchievementsPage

Inherits:
Object
  • Object
show all
Defined in:
lib/xbox_live/achievements_page.rb

Overview

Each AchievementsPage tracks and makes available the data contianed in an Xbox Live “Compare Game” page. This can be used to determine which achievements a player has unlocked in a game.

Example: live.xbox.com/en-US/Activity/Details?titleId=1161890128&compareTo=someone

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gamertag, game_id) ⇒ AchievementsPage

Create a new AchievementsPage for the provided gamertag. Retrieve the html compare achievements page from the Xbox Live web site for analysis. To prevent multiple instances for the same gamertag, this method is marked as private. The AchievementsPage.find() method should be used to find an existing instance or create a new one if needed.



18
19
20
21
22
# File 'lib/xbox_live/achievements_page.rb', line 18

def initialize(gamertag, game_id)
  @gamertag = gamertag
  @game_id = game_id
  refresh
end

Instance Attribute Details

#achievementsObject

Returns the value of attribute achievements.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def achievements
  @achievements
end

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def data
  @data
end

#game_idObject

Returns the value of attribute game_id.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def game_id
  @game_id
end

#gamertagObject

Returns the value of attribute gamertag.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def gamertag
  @gamertag
end

#pageObject

Returns the value of attribute page.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def page
  @page
end

#updated_atObject

Returns the value of attribute updated_at.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def updated_at
  @updated_at
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/xbox_live/achievements_page.rb', line 10

def url
  @url
end

Instance Method Details

#refreshObject

Force a reload of the AchievementsPage data from the Xbox Live web site.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xbox_live/achievements_page.rb', line 26

def refresh
  url = XboxLive.options[:url_prefix] + '/en-US/Activity/Details?' +
    Mechanize::Util.build_query_string(titleId: @game_id, compareTo: @gamertag)
  @page = XboxLive::Scraper::get_page url
  return false if page.nil?

  @url = url
  @updated_at = Time.now
  @data = retrieve_achievement_data
  @gamertag = find_gamertag
  @achievements = find_achievements

  true
end