Class: Halo::Reach::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/version.rb,
lib/halo-reach-api.rb

Constant Summary collapse

VERSION =
'1.0.5'.freeze
API_URL =
'http://www.bungie.net/api/reach/reachapijson.svc/'
DEFAULT_HEADERS =
{
  'User-Agent' => "Halo:Reach API gem #{VERSION}"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, api_url = API_URL) ⇒ API

Create a new Halo::Reach::API class with your token



25
26
27
28
# File 'lib/halo-reach-api.rb', line 25

def initialize(token, api_url = API_URL)
  @token = token
  @api_url = api_url
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



21
22
23
# File 'lib/halo-reach-api.rb', line 21

def api_url
  @api_url
end

#tokenObject

Returns the value of attribute token.



22
23
24
# File 'lib/halo-reach-api.rb', line 22

def token
  @token
end

Instance Method Details

#debug(location = $stderr) ⇒ Object

Set a new location for debug output



31
32
33
# File 'lib/halo-reach-api.rb', line 31

def debug(location = $stderr)
  self.class.debug_output(location)
end

#get_current_challengesObject

The “GetCurrentChallenges” method returns the currently active weekly and daily challenges.

www.haloreachapi.net/wiki/GetCurrentChallenges



58
59
60
61
# File 'lib/halo-reach-api.rb', line 58

def get_current_challenges
  current_challenges_uri = "game/challenges/#{@token}"
  self.class.get(@api_url + current_challenges_uri)        
end

#get_file_details(file_id) ⇒ Object

The “GetFileDetails” method returns the file details for a single file.

www.haloreachapi.net/wiki/GetFileDetails



115
116
117
118
# File 'lib/halo-reach-api.rb', line 115

def get_file_details(file_id)
  get_file_details_uri = "file/details/#{@token}/#{file_id}"
  self.class.get(@api_url + get_file_details_uri)                
end

#get_game_details(game_id) ⇒ Object

The “GetGameDetails” method returns detailed information for a given game ID.

www.haloreachapi.net/wiki/GetGameDetails



66
67
68
69
# File 'lib/halo-reach-api.rb', line 66

def get_game_details(game_id)
  get_game_details_uri = "game/details/#{@token}/#{game_id}"
  self.class.get(@api_url + get_game_details_uri)        
end

#get_game_history(gamertag, variant_class = 'Unknown', page = 0) ⇒ Object

The “GetGameHistory” method returns a players list of games, in chronological reverse over. Returned games is paginated, and you can specific which game variant, (Invasion, Campaign, for example), or Unknown for all games.

www.haloreachapi.net/wiki/GetGameHistory



75
76
77
78
# File 'lib/halo-reach-api.rb', line 75

def get_game_history(gamertag, variant_class = 'Unknown', page = 0)
  get_game_history_uri = "player/gamehistory/#{@token}/#{msftize(gamertag)}/#{variant_class}/#{page}"
  self.class.get(@api_url + get_game_history_uri)        
end

#get_game_metadataObject

The “GetGameMetadata” method returns several dictionaries so that resource ids can be translated into their more detailed versions. For example, this method can be used to associate a medal resource id with its representative medal (say, a killing spree).

www.haloreachapi.net/wiki/GetGameMetadata



50
51
52
53
# File 'lib/halo-reach-api.rb', line 50

def 
   = "game/metadata/#{@token}"        
  self.class.get(@api_url + )        
end

#get_player_details_with_no_stats(gamertag) ⇒ Object

The “GetPlayerDetailsWithNoStats” method returns basic information about a player.

www.haloreachapi.net/wiki/GetPlayerDetailsWithNoStats



99
100
101
102
# File 'lib/halo-reach-api.rb', line 99

def get_player_details_with_no_stats(gamertag)
  get_player_details_with_no_stats_uri = "player/details/nostats/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_details_with_no_stats_uri)        
end

#get_player_details_with_stats_by_map(gamertag) ⇒ Object



83
84
85
86
# File 'lib/halo-reach-api.rb', line 83

def get_player_details_with_stats_by_map(gamertag)
  get_player_details_with_stats_by_map_uri = "player/details/bymap/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_details_with_stats_by_map_uri)        
end

#get_player_details_with_stats_by_playlist(gamertag) ⇒ Object

The “GetPlayerDetailsWithStatsByPlaylist” method Returns detailed aggregate information on a player, including arena information.

www.haloreachapi.net/wiki/GetPlayerDetailsWithStatsByPlaylist



91
92
93
94
# File 'lib/halo-reach-api.rb', line 91

def get_player_details_with_stats_by_playlist(gamertag)
  get_player_details_with_stats_by_playlist_uri = "player/details/byplaylist/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_details_with_stats_by_playlist_uri)        
end

#get_player_file_set_files(gamertag, file_set_id) ⇒ Object

The “GetPlayerFileSetFiles” method returns a listing of files in the specified file set.

www.haloreachapi.net/wiki/GetPlayerFileSetFiles



139
140
141
142
# File 'lib/halo-reach-api.rb', line 139

def get_player_file_set_files(gamertag, file_set_id)
  get_player_file_set_files_uri = "file/sets/files/#{@token}/#{msftize(gamertag)}/#{file_set_id}"
  self.class.get(@api_url + get_player_file_set_files_uri)        
end

#get_player_file_sets(gamertag) ⇒ Object

The “GetPlayerFileSets” method returns a listing of file sets created by the player.

www.haloreachapi.net/wiki/GetPlayerFileSets



131
132
133
134
# File 'lib/halo-reach-api.rb', line 131

def get_player_file_sets(gamertag)
  get_player_file_sets_uri = "file/sets/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_file_sets_uri)        
end

#get_player_file_share(gamertag) ⇒ Object

The “GetPlayerFileShare” method returns a listing of files in a player’s file share.

www.haloreachapi.net/wiki/GetPlayerFileShare



107
108
109
110
# File 'lib/halo-reach-api.rb', line 107

def get_player_file_share(gamertag)
  get_player_file_share_uri = "file/share/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_file_share_uri)        
end

#get_player_recent_screenshots(gamertag) ⇒ Object

The “GetPlayerRecentScreenshots” method returns a list of the player’s recent screenshots.

www.haloreachapi.net/wiki/GetPlayerRecentScreenshots



123
124
125
126
# File 'lib/halo-reach-api.rb', line 123

def get_player_recent_screenshots(gamertag)
  get_player_recent_screenshots_uri = "file/screenshots/#{@token}/#{msftize(gamertag)}"
  self.class.get(@api_url + get_player_recent_screenshots_uri)        
end

#get_player_rendered_videos(gamertag, page = 0) ⇒ Object

The “GetPlayerRenderedVideos” method returns a listing of rendered videos created by a player.

www.haloreachapi.net/wiki/GetPlayerRenderedVideos



147
148
149
150
# File 'lib/halo-reach-api.rb', line 147

def get_player_rendered_videos(gamertag, page = 0)
  get_player_rendered_videos_uri = "file/videos/#{@token}/#{msftize(gamertag)}/#{page}"
  self.class.get(@api_url + get_player_rendered_videos_uri)        
end

#reach_file_search(file_category, map_filter, engine_filter, date_filter, sort_filter, tags, page = 0) ⇒ Object

The “ReachFileSearch” method returns a listing of files matching the specified criteria.

www.haloreachapi.net/wiki/ReachFileSearch



155
156
157
158
159
160
161
162
# File 'lib/halo-reach-api.rb', line 155

def reach_file_search(file_category, map_filter, engine_filter, date_filter, sort_filter, tags, page = 0)
  reach_file_search_uri = "file/search/#{@token}/#{file_category}/#{map_filter}/#{engine_filter}/#{date_filter}/#{sort_filter}/#{page}"
  unless tags.nil?
    reach_file_search_uri += "?tags=#{CGI.escape(tags)}"
  end
  
  self.class.get(@api_url + reach_file_search_uri)        
end

#set_http_headers(http_headers = {}) ⇒ Object

Set new HTTP headers



36
37
38
39
# File 'lib/halo-reach-api.rb', line 36

def set_http_headers(http_headers = {})
  http_headers.merge!(DEFAULT_HEADERS)
  headers(http_headers)
end

#set_timeout(timeout) ⇒ Object

Set a new default HTTP timeout



42
43
44
# File 'lib/halo-reach-api.rb', line 42

def set_timeout(timeout)
  default_timeout(timeout)
end