private static string FieldsFromEnum2(GuildFields flagsEnum) { int flagsValue = Convert.ToInt32(flagsEnum); var values = Enum.GetValues(flagsEnum.GetType()).Cast <int>().Where(x => (flagsValue & x) == x) .Except(new[] { 0x0, 0x3, 0x7FFFFFFF }).Select(x => Enum.GetName(flagsEnum.GetType(), x).ToString()).ToArray(); return(string.Join(",", values).ToLowerInvariant()); }
public Guild GetGuild(string name, string realm, GuildFields fields = GuildFields.None) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name"); if (string.IsNullOrWhiteSpace(realm)) throw new ArgumentNullException("realm"); return this.Get<Guild>(string.Format("guild/{0}/{1}", realm, name), fields: fields); }
public Guild GetGuildProfile(string realm, string guild, GuildFields field) { string fieldInput = field.ToString(); Request request = new Request(User_Agent); request.Get($"{Api_Url}wow/guild/{realm}/{guild}?fields={fieldInput}&locale={Locale}&apikey={Api_Key}"); return(new Guild(JObject.Parse(request.Response))); }
public Task <Guild> GetGuildAsync(string realm, string guildName, GuildFields fieldsToRetrieve) { string[] fields = EnumHelper <GuildFields> .GetNames().Where( name => name != "All" && (fieldsToRetrieve & (GuildFields)Enum.Parse(typeof(GuildFields), name, true)) != 0).Select( name => name.ToLowerInvariant()).ToArray(); string queryString = fields.Length == 0 ? "" : "?fields=" + string.Join(",", fields); return(GetAsync <Guild>( "/api/wow/guild/" + GetRealmSlug(realm) + "/" + Uri.EscapeUriString(guildName) + queryString, null)); }
public GuildRoot GetGuild(string name, GuildOptions guildOptions, string realm) { var guild = new GuildRoot(); var url = string.Format(@"{0}/wow/guild/{1}/{2}?{3}&locale={4}&apikey={5}", _Host, realm, name, GuildFields.BuildOptionalFields(guildOptions), _Locale, _APIKey); guild = json.GetDataFromURL <GuildRoot>(url); return(guild); }
public static string BuildQueryString(this GuildFields fields) { switch (fields) { case GuildFields.All: return("&fields=members,achievements,news,challenge"); case GuildFields.None: return(string.Empty); default: var flags = fields.ToString().ToLower(); return($"&fields={flags}"); } }
//realm in getGuildAsync does not work (404 not found), why? setting realm in apiclient constructor works. public async Task <GuildRoot> GetGuildAsync(string name, GuildOptions guildOptions, string realm) { var guild = new GuildRoot(); var url = string.Format( @"{0}/wow/guild/{1}/{2}?{3}&locale={4}&apikey={5}", _Host, realm, name, GuildFields.BuildOptionalFields(guildOptions), _Locale, _APIKey); guild = await this.jsonUtility.GetDataFromURLAsync <GuildRoot>(url); return(guild); }
public static string BuildQueryString(this GuildFields fields) { // The Blizzard API only accepts lowercase fields. string flags = fields.ToString().ToLower(); if (flags == "all") { return("&fields=members,achievements,news,challenge"); } if (flags == "none") { return(string.Empty); } return($"&fields={flags}"); }
public static IEnumerable <string> GetFieldsAsStrings(this GuildFields fields) { return(GetFieldsAsStrings <GuildFields>((int)fields)); }
//realm in getGuildAsync does not work (404 not found), why? setting realm in apiclient constructor works. public async Task <GuildRoot> GetGuildAsync(string name, GuildOptions guildOptions, string realm) { var url = $"{Host}/wow/guild/{realm}/{name}?{GuildFields.BuildOptionalFields(guildOptions)}&locale={Locale}&apikey={APIKey}"; return(await this._jsonUtility.GetDataFromURLAsync <GuildRoot>(url)); }
/// <summary> /// The guild profile API is the primary way to access guild information. This API can fetch a single /// guild at a time through an HTTP GET request to a URL describing the guild profile resource. By default, /// these requests return a basic dataset and each request can retrieve zero or more additional fields. /// Although this endpoint has no required query string parameters, requests can optionally pass the fields /// query string parameter to indicate that one or more of the optional datasets is to be retrieved. /// Those additional fields are listed in the method titled "Optional Fields". /// </summary> /// <param name="realm">The guild's realm.</param> /// <param name="guildName">The name of the guild to query.</param> /// <param name="fields"> /// The optional data to retrieve about the guild. Each field value is explained in more detail in the /// following methods. If no fields are specified the API will only return basic guild data. /// <seealso cref="GuildFields" /> /// </param> /// <returns> /// The specified guild profile and additional data. /// </returns> public async Task <RequestResult <Guild> > GetGuildAsync(string realm, string guildName, GuildFields fields = GuildFields.None) { var queryStringFields = fields.BuildQueryString(); return(await Get <Guild>($"{Host}/wow/guild/{realm}/{Uri.EscapeUriString(guildName)}?locale={Locale}{queryStringFields}")); }
public Task<Guild> GetGuildAsync(string realm, string guildName, GuildFields fieldsToRetrieve) { string[] fields = EnumHelper<GuildFields>.GetNames().Where( name => name != "All" && (fieldsToRetrieve & (GuildFields)Enum.Parse(typeof(GuildFields), name, true)) != 0).Select( name => name.ToLowerInvariant()).ToArray(); string queryString = fields.Length == 0 ? "" : "?fields=" + string.Join(",", fields); return GetAsync<Guild>( "/wow/guild/" + GetRealmSlug(realm) + "/" + Uri.EscapeUriString(guildName) + queryString + "&locale=" + _locale + "&apikey=" + _publicKey, null); }
/// <summary> /// Builds the guild fields query string from the specified fields object. /// </summary> /// <param name="fields">The guild fields object to build the query string from.</param> /// <returns> /// The guild fields query string from the specified fields object. /// </returns> internal string BuildGuildFieldsQueryString(GuildFields fields) { var fieldQueryString = fields.GetValues().Cast<GuildFields>().Where(value => value != GuildFields.All && (fields & value) == value).Aggregate(String.Empty, (current, value) => String.Format("{0}{1}{2}", current, !String.IsNullOrEmpty(current) ? "," : String.Empty, EnumHelper.GetApiUrlFieldName(value))); return !String.IsNullOrEmpty(fieldQueryString) ? String.Format("?fields={0}", fieldQueryString) : String.Empty; }
/// <summary> /// Gets the guild information for the specified realm and guild name. /// </summary> /// <param name="realmName">The name of the realm.</param> /// <param name="guildName">The name of the guild.</param> /// <param name="fields">Specifies the information to retrieve for this guild.</param> /// <param name="action">The action to execute once the response was received.</param> public void GetGuildAsync(string realmName, string guildName, GuildFields fields, Action<Guild> action) { try { var fieldsQueryString = BuildGuildFieldsQueryString(fields); var apiMethod = new Uri(BattleNetBaseUri, String.Format(BattleNetSettings.BattleNet_Api_Guild, realmName, guildName, fieldsQueryString)).ToString(); CallApiMethodAsync(apiMethod, jsonResult => { try { var guild = JsonConvert.DeserializeObject<Guild>(jsonResult); if (guild != null) { guild.Region = Region; } action(guild); } catch (Exception ex) { action(null); } }); } catch (Exception ex) { action(null); } }
public async Task <Guild> GetGuildAsync(string realm, string guildName, GuildOptions guildOptions = GuildOptions.None) { string query = $"/wow/guild/{realm}/{guildName}"; return(await reader.GetAsync <Guild>(query, GuildFields.BuildOptionalFields(guildOptions))); }