Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 24 18:06
    StevenLiekens commented #59
  • Mar 24 18:05
    StevenLiekens closed #59
  • Mar 24 18:05
    StevenLiekens commented #59
  • Mar 24 17:47
    StevenLiekens closed #58
  • Mar 24 17:47
    StevenLiekens commented #58
  • Mar 19 13:02
    Friesinator edited #59
  • Mar 19 13:01
    Friesinator opened #59
  • Mar 18 12:38
    StevenLiekens commented #58
  • Mar 15 15:19
    GHOSCHT commented #58
  • Mar 14 22:01
    Seeker1437 commented #58
  • Mar 14 20:08
    GHOSCHT commented #58
  • Mar 12 15:40
    StevenLiekens commented #58
  • Mar 10 15:46
    GHOSCHT opened #58
  • Apr 15 2018 16:43

    Ruhrpottpatriot on ServiceClient

    Remove superfluous compression … Add simple caching to Core proj… Move files into different folde… and 8 more (compare)

  • Apr 10 2018 21:09

    Ruhrpottpatriot on ServiceClient

    Add fluent api to create HttpRe… Fix Stylecop errors Remove dead code and 3 more (compare)

  • Mar 29 2018 13:11

    Ruhrpottpatriot on NetCore2.0

    Remove disabled and superseded … Delete unused leftover code fro… Move V1.Guild test to appropria… and 8 more (compare)

  • Mar 29 2018 12:17

    Ruhrpottpatriot on NetCore2.0

    Update .gitignore to exclude St… Add Api builder class (compare)

  • Feb 01 2018 09:33

    Ruhrpottpatriot on master

    Refactorize ServiceClient.GetHt… Merge pull request #57 from Kor… (compare)

  • Feb 01 2018 09:33
    Ruhrpottpatriot closed #57
  • Dec 27 2017 17:37
    Korjam opened #57
Steven Liekens
@StevenLiekens
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
for Quaggans there is only one conversion: string to Uri
for other types, converting might be more complicated
Steven Liekens
@StevenLiekens
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
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
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
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
there's an extension method called FindAllPagesAsync
Darnell Williams
@Seeker1437
CHecking it out
Steven Liekens
@StevenLiekens
you have to pass two parameters: the page size, and the number of pages to get (starting from the first page)
Darnell Williams
@Seeker1437
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
:)
ok
Darnell Williams
@Seeker1437

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
was that the question? :)
Darnell Williams
@Seeker1437
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
I'd handle it the same way
Darnell Williams
@Seeker1437

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
oh jeez please don't use restsharp :D
it's actually really bad
Darnell Williams
@Seeker1437
it's actually my own torn down version x3
Steven Liekens
@StevenLiekens
you forked restsharp?
Darnell Williams
@Seeker1437
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
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
same difference?
I don't understand the question :)
Darnell Williams
@Seeker1437
It's basically the upgraded version of HttpWebRequest
Steven Liekens
@StevenLiekens
what is
Darnell Williams
@Seeker1437
HttpRequestMessage
Steven Liekens
@StevenLiekens
that's part of the HttpClient API
Darnell Williams
@Seeker1437
Hmm I think it's very weird :(
Steven Liekens
@StevenLiekens
what is?
Darnell Williams
@Seeker1437

System.Web.Http

System.Net.Http

the idea of there being basically similar things in different namespaces

Steven Liekens
@StevenLiekens
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