Ruhrpottpatriot on ServiceClient
Remove superfluous compression … Add simple caching to Core proj… Move files into different folde… and 8 more (compare)
Ruhrpottpatriot on ServiceClient
Add fluent api to create HttpRe… Fix Stylecop errors Remove dead code and 3 more (compare)
Ruhrpottpatriot on NetCore2.0
Remove disabled and superseded … Delete unused leftover code fro… Move V1.Guild test to appropria… and 8 more (compare)
Ruhrpottpatriot on NetCore2.0
Update .gitignore to exclude St… Add Api builder class (compare)
Ruhrpottpatriot on master
Refactorize ServiceClient.GetHt… Merge pull request #57 from Kor… (compare)
[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; }
}
{
id: "aloha",
url: "https://static.staticwars.com/quaggans/aloha.jpg"
}
var data = new QuagganDTO
{
Id = "aloha",
Url = "https://static.staticwars.com/quaggans/aloha.jpg"
};
QuagganDTO
to Quaggan
is really just mapping properties
var quaggan = new Quaggan
{
Id = data.Id,
Url = new Uri(data.Url);
}
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)
};
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; }
}
}
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
}