User:Bandlero

From Guild Wars 2 Wiki
Jump to: navigation, search


Bandlero

PvX This user plays PvE and PvP.
From
North America
Age
30+ years old
World
Ferguson's Crossing (US)
API This user develops applications using the API
North America 70x40.png This user plays for the territory of North America.
FC This user is a proud member of Ferguson's Crossing.
User Galerian Family.png This user plays with its whole family.
User Madhatter Image caution.png This user is a mature gamer and wont take your drama
User Demonthorn Gwlogo.jpg This user played the original Guild Wars.

About[edit]

I am a veteran Guild Wars and Guild Wars 2 player and a veteran MMO/MMORPG gamer. I have 20+ characters; at least one of each class at level 80 (most classes I have two or more characters at level 80) and I have a maxed crafter of every type. I prefer Sylvari. I PvP. I PvE. I WvW. I created and run the Original WvW Guild [WvW] - created way back in 2012/2013. I am proud to be an original member of Fergusons Crossing and have never transferred servers. I am a World vs. World Commander; though I do not command much anymore, especially after the server merges and pairings, etc. I play at random, sporadic times; you can find me online at almost any hour of the day through-out all playtimes. Lately I have been spending more time out-of-game developing more, new tools for Guild Wars 2, and working, than I have been logged into the game, but I am always willing to login when asked.

GW2 Command[edit]

I am the developer/creator of GW2 Command and other products using the Guild Wars 2 API.

GW2 Command for Windows 10[edit]

GW2 Command & Tools For Windows 10 is available to Beta testers in the Windows Store. If you would like to join the Beta test, and receive a free-for-life copy of the application(s), please message me with your Windows Store Id (email) and your Discord Id.

GW2 Command for Windows 10 supports and utilizes Uri resource linking; using the following scheme: guildwars2.x:y When clicking a guildwars2.x:y link, Windows will launch your default program if it is not already open, and process the data y.

Items:

guildwars2.item:itemId - Opens and/or navigates GW2 Command to the appropriate Item Details page for the supplied Item Id; ex: [guildwars2.item:30698 The Bifrost]
guildwars2.item.track:itemId - Opens and/or navigates GW2 Command to the Item Tracking page and begins tracking the indicated Item; ex: [guildwars2.item.track:30698 The Bifrost]
guildwars2.skin:skinId - Skins
guildwars2.finisher:finisherId - Finishers
guildwars2.itemstat:itemstatId - Item Stats
guildwars2.material:materialId - Materials
guildwars2.amulet:amuletId - PvP Amulets
guildwars2.recipe:recipeId - Recipes
guildwars2.outfit:outfitId
guildwars2.color:colorId
guildwars2.minipet:minipetId
guildwars2.dye:dyeId

Trading Post:

guildwars2.listing:listingId
guildwars2.listing.item:itemId
guildwars2.price:itemId 
guildwars2.current:currenyId

Game Mechanics

guildwars2.mastery:masteryId
guildwars2.skill:skillId
guildwars2.pet:petId
guildwars2.profession:professionId
guildwars2.race:raceId
guildwars2.specialization:specializationId
guildwars2.trait:traitId
guildwars2.legend:legendId

Guild

guildwars2.guild:guildId

Worlds

guildwars2.server:serverId

Achievements

guildwars2.achievement:achievementId
guildwars2.title:titleId

Working With JSON[edit]

For Microsoft .NET (Windows) developers and others wishing to use the Guild Wars 2 API or work with JSON data, I strongly suggest using JSON.Net (I am not affiliated with or employed by Newtonsoft.) JSON.Net has low overhead, quick response, and a simple implementation into projects that need to deal with JSON data. JSON.Net is seriously easy to implement and use.

I am willing to answer a few questions here and there about programming (but I won't earn your paycheck for you.) I am a professional programmer using c#, VB, and c++ (also all in .Net); xhtml, js, css, xml, ASP.Net, et al.; SQL and MSSQL; etc. VB.Net is my language of choice anymore these days (I know a lot can be debated and discussed on that); I am also a proficient translator for many languages.

GW2 API & JSON[edit]

When making requests from the GW2 API server, how you request the data will determine what sort of JSON object gets returned to you.

When accessing a root endpoint (like https://api.guildwars2.com/v2/professions), you will receive an array of objects (usually simple-objects such as integer, strings, etc.)

When accessing an endpoint that specifies an id (like https://api.guildwars2.com/v2/professions/Warrior), you will receive a singular JSON object.

When accessing a root endpoint and providing the ids parameter (like https://api.guildwars2.com/professions?ids=Warrior), you will receive an array of JSON objects regardless of how many ids you provide via the parameter. When accessing the root endpoint with a parameter, you will always have to handle/deserialize the returned data as an array of JSON objects.

Accessing With JavaScript[edit]

The following is the most simple method to retrieve data from the API and to process/display it client-side:

First you will want to include JQuery in the <head> of your page using. Microsoft or Google, it does not matter which one you use. Do not use JQuery Slim.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

You will want to place this script as close to the <title> tags as possible, as you want JQuery to be one of the first things your page loads.

Using the guild end-point as an example below, you can then access and work with the data using the following code anywhere in your document after the inclusion of JQuery. If you need to provide an API Key for Authentication, you can do so via query string on the parameter "access_token". Replace "guildID" with the ID of the guild you wish to retrieve data for.

$.getJSON("https://api.guildwars2.com/v2/guild/guildID?access_token=", function (data) {
    var j = eval(data);
});

Using the above code that retrieves guild details, you can access the retrieved data via the variable j or whatever you name the variable. The data is accessible through properties of this variable, via the same names as what's been retrieved in the JSON and what's provided by the API.

j.level   Guild Level
j.name    Guild Name
j.tag     Guild Tag (ex: [WvW])
j.id      Guild ID (should be the same as the guild ID you supplied to the API)
j.emblem  Guild Emblem Object

If you Authenticated:
j.motd, j.influence, j.aetherium, j.resonance, j.favor, j.member_count, j.member_capacity

How you process and display the retrieved data is up to you. Happy JavaScripting.

Accessing with ASP.NET[edit]

Working with the API data server-side is a lot more powerful and flexible than doing it client-side with JavaScript. However; server-side processing is more complex, comes with more overhead, and slows pages down massively due to the nature of accessing an HTTP API like the one ArenaNet provides. I will provide my examples using VisualBasic.NET - Visual Basic is good, old plain English and easy for all levels of programmers to read and understand (and it translates to other spoken languages nicely too.) If you need your code examples in C# or another ASP.NET language - Happy Learning!

This example is only ONE way of doing this - I do not claim it is the best way - but I am saying this is one of the easiest, most un-elegant, brute-force methods of doing this.

First, you will want to make sure you have Newtonsoft.JSON referenced by your project and correctly configured, installed, set-up and whatever your project needs.

On your code-behind, you will want to make the following include statements:

Imports Newtonsoft.Json
Imports System.Net

Now to download the data from the API server you can use the following code. If you need to Authenticate, replace the "YourAPIKeyHere" with your API Key. If you do not need to Authenticate, remove that line of code. Accept-Language is where you can direct the API as to which language you want the data localized for. Replace address with the API end-point you wish to access.

Using w As New WebClient()
  w.Encoding = System.Text.Encoding.UTF8
  w.Credentials = New NetworkCredential("", "")
  w.CachePolicy = New Net.Cache.RequestCachePolicy(Net.Cache.RequestCacheLevel.CacheIfAvailable)
  w.Headers.Item("User-Agent") = "API Data Retrieval Example"
  w.Headers.Add("Developer", "David M. Bandler (david.bandler@davidbandler.com); Bandler Media Productions")
  w.Headers.Add("Authorization", "Bearer YourAPIKeyHere")
  w.Headers.Add("Accept-Language", "en")
  Return w.DownloadString(address)
End Using

You have now successfully downloaded the data from the API server as a JSON formatted string. Now how do you work with this data? If you want to work with it as JSON, then use:

JsonConvert.DeserializeObject(Of type)(string)

Type can be anything from a strongly-typed Class, a List(of Object), or pretty much whatever you want to cast the data as.

But what if you want to work with the data as something other than JSON? Like for example, maybe you want to use the XMLDataSource or use XPath & XML to process the data? It's pretty simple and straight-forward, though there is some trial and error because ArenaNet isn't serving properly formatted JSON from every end-point. The following are a few example methods to convert the JSON to XML; use of each depends on the validity of the JSON you receive from the server:

JsonConvert.DeserializeXmlNode(string).InnerXml
JsonConvert.DeserializeXmlNode("{""" & nodeName & """: " & string & "}").InnerXml
JsonConvert.DeserializeXmlNode(string, rootElementName).InnerXml
JsonConvert.DeserializeXmlNode("{""" & nodeName & """:" & string & "}", rootElementName).InnerXml

I find that the 3rd and 4th Deserialization methods are most useful when working with the data retrieved from the API. The 4th method works best for instances when the API is returning you an array of integers or a list of objects. The 3rd method is useful when the API returns "whole" JSON objects.

Now you have converted the JSON to XML; how do you feed it to your XMLDataSource? Easy:

XMLDataSource.Data = "<xml>" & string & "</xml>"
XMLDataSource.DataBind()

And now your XMLDataSource is ready to use with the Repeater or other data controls. Most often you do have to wrap the XML with the <xml> tags as most JSON will not fully, properly convert and format to XML. I'm not going to write about and teach how to use XPath - I will only mention that the structure of the data from the API can be tricky and the XPath isn't always as obvious.

Accessing with .NET[edit]

Pretty much little different than via ASP.NET. A lot quicker, more powerful, and more efficient as an application instead of a web page or web application.