These are chat archives for Ruhrpottpatriot/GW2.NET

30th
Jun 2016
shurne
@SamHurne
Jun 30 2016 00:56
Hey guys! In case it wasn't obvious, I've been away. I'm finally working on a maintenance release of the PAO... the whole thing is a mess, and I kind of want to just re-write the thing with a proper plugin system, but I don't want to jump into that yet. It looks like the latest release of GW2.Net is 1.4.0? Sounds like there's not much active development going on for GW2.Net? Just wanted to check in on the state of everything... thanks!
Steven Liekens
@StevenLiekens
Jun 30 2016 07:54
@SamHurne I've been away from GW2 too so that's why there is little motivation from my end
from what I remember, the current state is that we all agreed that we have to switch out the WebRequest/WebResponse APIs for HttpClient
so that's still ongoing
and then there was some talk about converting from PCLs to netstandard packages
but netstandard doesn't even support WebRequest/WebResponse anymore so that will have to wait until all the code uses HttpClient instead
Steven Liekens
@StevenLiekens
Jun 30 2016 08:00
the 1.4 release is stable and it was 100% up to date with the API at the time the package was pushed
any API changes after december 2015 are not supported
by the way I'm only speaking for APIs that are actually implemented
that excludes all of the APIs that require authentication
and also some newer ones like /v2/achievements
the list of endpoints has grown quite a bit in 2016
@Seeker1437 sure
Steven Liekens
@StevenLiekens
Jun 30 2016 08:05
the json is first converted to a class that is a 1-to-1 mapping of the json schema
so you get a .NET object with all the same fields as the json object
in GW2.NET these are the xxxDTO classes
like QuagganDTO
[DataContract]
public sealed class QuagganDTO
{
    [DataMember(Name = "id", Order = 0)]
    public string Id { get; set; }

    [DataMember(Name = "url", Order = 1)]
    public string Url { get; set; }
}
so for example
{
  id: "aloha",
  url: "https://static.staticwars.com/quaggans/aloha.jpg"
}
Steven Liekens
@StevenLiekens
Jun 30 2016 08:11
is the same as
var data = new QuagganDTO
{
    Id = "aloha",
    Url = "https://static.staticwars.com/quaggans/aloha.jpg"
};
and then there is a whole bunch of custom code to convert from DTO classes to one of the Core classes
converting from QuagganDTO to Quaggan is really just mapping properties
var quaggan = new Quaggan
{
    Id = data.Id,
    Url = new Uri(data.Url);
}
Steven Liekens
@StevenLiekens
Jun 30 2016 08:16
for Quaggans there is only one conversion: string to Uri
for other types, converting might be more complicated
Steven Liekens
@StevenLiekens
Jun 30 2016 10:19
so to summarize...
these are the conversions from json to final object
string json = @"
{
  id: ""aloha"",
  url: ""https://static.staticwars.com/quaggans/aloha.jpg""
}";
QuagganDTO dto = JsonConvert.DeserializeObject<QuagganDTO>(json);
Quaggan quaggan = new Quaggan
{
    Id = dto.Id,
    Url = new Uri(dto.Url)
};
Darnell Williams
@Seeker1437
Jun 30 2016 13:16
gottcha
for me atm I only hever have to deal with a little bit of pagination and converting from string to Enum
Steven Liekens
@StevenLiekens
Jun 30 2016 13:19
pagination is one of the parts that GW2.NET does really well
it can run multiple requests in parallel, retry failed requests with a configurable max retry count
Darnell Williams
@Seeker1437
Jun 30 2016 13:20
I could not think of a good way to handle pagination to be honest, it's newer to me. The last API I worked with just gave all entries.
Yeah I do like that!
Steven Liekens
@StevenLiekens
Jun 30 2016 13:20
there's an extension method called FindAllPagesAsync
Darnell Williams
@Seeker1437
Jun 30 2016 13:23
CHecking it out
Steven Liekens
@StevenLiekens
Jun 30 2016 13:23
you have to pass two parameters: the page size, and the number of pages to get (starting from the first page)
Darnell Williams
@Seeker1437
Jun 30 2016 13:25
AH I realize I don't get that freedom
I know it's weird but I am trying to get a good feel for this library by borrowing it's concepts and putting it to use so I understand a bit better
Steven Liekens
@StevenLiekens
Jun 30 2016 13:26
:)
ok
Darnell Williams
@Seeker1437
Jun 30 2016 13:33

My next question I guess it regarding the converters

for example

with a simple object like this

this would instead be the MoneyDTO

the money class with then have the real documentation in it

I would not need to convert anything with this

However I am in charge of how ToString returns the value based of the currency

using Newtonsoft.Json;

namespace SquareConnect.V1.Types
{
    /// <summary>
    /// Represents an amount of money.
    /// </summary>
    public class Money
    {
        public Money(int amount, string currencyCode = "USD")
        {
            Amount = amount;
            CurrencyCode = currencyCode;
        }

        /// <summary>
        /// The amount of money, in the smallest unit of the applicable currency. For US dollars, this value is in cents. This value is always an integer.
        /// </summary>
        [JsonProperty("amount")]
        public int Amount { get; set; }

        /// <summary>
        /// The type of currency involved in the current payment. The currency code for US dollars is USD.
        /// </summary>
        [JsonProperty("currency_code")]
        public string CurrencyCode { get; set; }
    }
}
Steven Liekens
@StevenLiekens
Jun 30 2016 13:36
was that the question? :)
Darnell Williams
@Seeker1437
Jun 30 2016 13:36
in the case where a user could do new Money() the converters also handle converting from Money to MoneyDTO when being sent or would it be handled differently
sorry this is the question x3
Steven Liekens
@StevenLiekens
Jun 30 2016 13:37
I'd handle it the same way
Darnell Williams
@Seeker1437
Jun 30 2016 13:50

when I was playing with the v2/account endpoint I wrote a micro library to just pull minute details from it

using Newtonsoft.Json;


namespace DangerBot.GW2.V2.Account.Objects
{
    /// <summary>This class describes a player account.</summary>
    public class Account
    {
        /// <summary>Gets or sets the accounts id.</summary>
        [JsonProperty("id")]
        public string Id { get; set; }

        /// <summary>Gets or sets the guild ids the character is in.</summary>
        [JsonProperty("guilds")]
        public string[] Guilds { get; set; }
    }
}

when I wanted to pull information about it I did

using DangerBot.GW2.V2.Account.Rest;
using System.Threading.Tasks;

namespace DangerBot.GW2.V2.Account.Client
{
    public partial class GW2ClientReduced
    {
        public async Task<Objects.Account> GetAccountAsync()
        {
            RestRequest restRequest = _client.Create("v2/account");

            RestResponse<Objects.Account> restResponse = await restRequest.ExecuteGet<Objects.Account>().ConfigureAwait(false);

            Objects.Account account = await restResponse.GetDataObject().ConfigureAwait(false);

            return account;
        }
    }
}

in practice:

var service = GW2.V1.Guilds;
 var guild = service.FindByName("The Zone of Danger");

// Too lazy to convert v2 responce to GUID...
var guildId = guild.GuildId.ToString().ToUpper();

var gw2CustomClient = new GW2ClientReduced(e.GetArg("api-key"));

var account = await gw2CustomClient.GetAccountAsync();

if (account.Guilds.Contains(guildId))
{
    // blah
}
Steven Liekens
@StevenLiekens
Jun 30 2016 13:52
oh jeez please don't use restsharp :D
it's actually really bad
Darnell Williams
@Seeker1437
Jun 30 2016 13:52
it's actually my own torn down version x3
Steven Liekens
@StevenLiekens
Jun 30 2016 13:53
you forked restsharp?
Darnell Williams
@Seeker1437
Jun 30 2016 13:53
not exactly, I got the flow of it and just wrote a reduced but functional version
it's just 3 classes and an enum now
normally images show :O
Darnell Williams
@Seeker1437
Jun 30 2016 14:00
I noticed in one of the issues you expressed that you guys use WebRequest/Response I was curious of the use of that over an Http (Request/Response) Message
Steven Liekens
@StevenLiekens
Jun 30 2016 14:00
same difference?
I don't understand the question :)
Darnell Williams
@Seeker1437
Jun 30 2016 14:03
It's basically the upgraded version of HttpWebRequest
Steven Liekens
@StevenLiekens
Jun 30 2016 14:03
what is
Darnell Williams
@Seeker1437
Jun 30 2016 14:04
HttpRequestMessage
Steven Liekens
@StevenLiekens
Jun 30 2016 14:04
that's part of the HttpClient API
Darnell Williams
@Seeker1437
Jun 30 2016 14:06
Hmm I think it's very weird :(
Steven Liekens
@StevenLiekens
Jun 30 2016 14:06
what is?
Darnell Williams
@Seeker1437
Jun 30 2016 14:07

System.Web.Http

System.Net.Http

the idea of there being basically similar things in different namespaces

Steven Liekens
@StevenLiekens
Jun 30 2016 14:08
that's because one is for ASP.NET and the other is for all purposes
avoid System.Web if you're not creating a web application
by web app I mean website
Darnell Williams
@Seeker1437
Jun 30 2016 14:10
Right, like ASP.NET style stuff
Steven Liekens
@StevenLiekens
Jun 30 2016 14:10
yea
Darnell Williams
@Seeker1437
Jun 30 2016 14:11
gottcha sorry for the offtopicness