public static string ToApiString(this OMDbQueryType type) { return(type switch { OMDbQueryType.Id => "i", OMDbQueryType.Title => "t", _ => "", });
public static string ToApiString(this OMDbQueryType type) { switch (type) { case OMDbQueryType.Id: return("i"); case OMDbQueryType.Title: return("t"); default: return(""); } }
private async Task SearchAndSendResultAsync(CommandContext ctx, OMDbQueryType type, string query) { MovieInfo?info = await this.Service.SearchSingleAsync(type, query); if (info is null) { await ctx.FailAsync("cmd-err-res-none"); return; } await ctx.RespondWithLocalizedEmbedAsync(emb => this.AddToEmbed(emb, info)); }
public async Task <MovieInfo?> SearchSingleAsync(OMDbQueryType type, string query) { if (this.IsDisabled) { return(null); } string url = $"{Endpoint}?apikey={this.key}&{type.ToApiString()}={WebUtility.UrlEncode(query)}"; string response = await _http.GetStringAsync(url).ConfigureAwait(false); MovieInfo data = JsonConvert.DeserializeObject <MovieInfo>(response); return(data.Success ? data : null); }
public async Task <MovieInfo> GetSingleResultAsync(OMDbQueryType type, string query) { if (this.IsDisabled()) { return(null); } if (string.IsNullOrWhiteSpace(query)) { throw new ArgumentException("Query missing!", nameof(query)); } string response = await _http.GetStringAsync($"{_url}?apikey={this.key}&{type.ToApiString()}={query}").ConfigureAwait(false); MovieInfo data = JsonConvert.DeserializeObject <MovieInfo>(response); return(data.Success ? data : null); }
private async Task SearchAndSendResultAsync(CommandContext ctx, OMDbQueryType type, string query) { if (this.Service.IsDisabled()) { throw new ServiceDisabledException(); } MovieInfo info = await this.Service.GetSingleResultAsync(type, query); if (info == null) { await this.InformFailureAsync(ctx, "No results found!"); return; } await ctx.RespondAsync(embed : info.ToDiscordEmbed(this.ModuleColor)); }