Skip to content

Instantly share code, notes, and snippets.

@chrisfried
Last active November 5, 2015 11:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisfried/ae016f1300232279a01d to your computer and use it in GitHub Desktop.
Save chrisfried/ae016f1300232279a01d to your computer and use it in GitHub Desktop.
'use strict'
var https = require('https'),
devKey = 'YOUR-API-KEY';
var h5 = exports = module.exports = {};
h5.callback = function callback(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
});
}
h5.imageCallback = function imageCallback(response) {
console.log(response.headers.location);
}
// METADATA
// Campaign Missions
h5.campaignMissions = function campaignMissions(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/campaign-missions',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Commendations
h5.commendations = function commendations(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/commendations',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// CSR Designations
h5.csrDesignations = function csrDesignations(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/csr-designations',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Enemies
h5.enemies = function enemies(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/csr-designations',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Flexible Stats
h5.flexibleStats = function flexibleStats(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/flexible-stats',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Game Base Variants
h5.gameBaseVariants = function gameBaseVariants(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/game-base-variants',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Game Variants
h5.gameVariants = function gameVariants(title, id) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/game-variants/' + id,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Impulses
h5.impulses = function impulses(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/impulses',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Map Variants
h5.mapVariants = function mapVariants(title, id) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/map-variants/' + id,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Maps
h5.maps = function maps(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/maps',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Medals
h5.medals = function medals(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/medals',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Playlists
h5.playlists = function playlists(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/playlists',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Requisition Packs
h5.requisitionPacks = function requisitionPacks(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/requisition-packs',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Requisitions
h5.requisitions = function requisitions(title, id) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/requisitions/' + id,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Skulls
h5.skulls = function skulls(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/skulls',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Spartan Ranks
h5.spartanRanks = function spartanRanks(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/spartan-ranks',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Team Colors
h5.teamColors = function teamColors(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/team-colors',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Vehicles
h5.vehicles = function vehicles(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/vehicles',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Weapons
h5.weapons = function weapons(title) {
var options = {
host: 'www.haloapi.com',
path: '/metadata/' + title + '/metadata/weapons',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// PROFILE
// Emblem Image
h5.emblemImage = function emblemImage(player, size) {
var options = {
host: 'www.haloapi.com',
path: '/profile/h5/profiles/' + player + '/emblem',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
if (size) options.path += '?size=' + size;
var req = https.request(options, h5.imageCallback);
req.end();
}
// Spartan Image
h5.spartanImage = function spartanImage(player, size, crop) {
var options = {
host: 'www.haloapi.com',
path: '/profile/h5/profiles/' + player + '/spartan?',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
if (size) options.path += 'size=' + size + '&';
if (crop) options.path += 'crop=' + crop;
var req = https.request(options, h5.imageCallback);
req.end();
}
// STATS
// Matches for Player
h5.matchesForPlayer = function matchesForPlayer(player, modes, start, count) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/players/' + player + '/matches?',
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
if (modes) options.path += 'modes=' + modes + '&';
if (start) options.path += 'start=' + start + '&';
if (count) options.path += 'count=' + count;
var req = https.request(options, h5.callback);
req.end();
}
// Post-Game Carnage Report: Arena
h5.postGameCarnageReportArena = function postGameCarnageReportArena(matchId) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/arena/matches/' + matchId,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Post-Game Carnage Report: Campaign
h5.postGameCarnageReportCampaign = function postGameCarnageReportCampaign(matchId) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/campaign/matches/' + matchId,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Post-Game Carnage Report: Custom
h5.postGameCarnageReportCustom = function postGameCarnageReportCustom(matchId) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/custom/matches/' + matchId,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Post-Game Carnage Report: Warzone
h5.postGameCarnageReportWarzone = function postGameCarnageReportWarzone(matchId) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/warzone/matches/' + matchId,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Service Record: Arena
h5.serviceRecordArena = function serviceRecordArena(players) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/servicerecords/arena?players=' + players,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Service Record: Campaign
h5.serviceRecordCampaign = function serviceRecordCampaign(players) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/servicerecords/campaign?players=' + players,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Service Record: Custom
h5.serviceRecordCustom = function serviceRecordCustom(players) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/servicerecords/custom?players=' + players,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
// Service Record: Warzone
h5.serviceRecordWarzone = function serviceRecordWarzone(players) {
var options = {
host: 'www.haloapi.com',
path: '/stats/h5/servicerecords/warzone?players=' + players,
method: 'GET',
headers: {'Ocp-Apim-Subscription-Key': devKey}
};
var req = https.request(options, h5.callback);
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment