async Task <RadarrGrabbedHistoryRecord> GetHistory(int movieId, int attempts = 0) { var url = apiUrl + $"/history/movie?movieId={movieId}&eventType={1}"; // 1=grabbed Program.LogMsg($"GET{attempts} {url}", LogSeverity.Info, "RadarrGetHistory"); var response = await HTTP.GetAsync(url); var content = await response.Content.ReadAsStringAsync(); var array = JsonConvert.DeserializeObject <List <RadarrHistoryRecord> >(content); Program.LogMsg($"GET {url} :: {response.StatusCode}, {(array?.Count ?? -1)} items", LogSeverity.Info, "RadarrGetHistory"); foreach (var record in array.OrderByDescending(x => x.Date)) { if (record is RadarrGrabbedHistoryRecord gh) { return(gh); } } Program.LogMsg($"Failed to find history for {movieId}, waiting then retrying.", LogSeverity.Info, "RadarrGetHistory"); if (attempts > 10) { Program.LogMsg($"{movieId} not retrying - too many attempts.", LogSeverity.Info, "RadarrGetHistory"); return(null); } Thread.Sleep(1000 * attempts); return(await GetHistory(movieId, attempts + 1)); }
async Task <string> GetTagLabel(int id) { if (TagsCache.TryGetValue(id, out var s)) { return(s); } var response = await HTTP.GetAsync(apiUrl + $"/tag/{id}"); var jobj = JObject.Parse(await response.Content.ReadAsStringAsync()); var l = jobj["label"].ToObject <string>(); TagsCache[id] = l; return(l); }
public IActionResult Index(CallModel model) { // Apply input history from cookie var cu = ControllerUtils.From(this); cu.PersistInput("Uri", model, CallModel.Default.Uri); cu.PersistInput("Method", model, CallModel.Default.Method); cu.PersistInput("Body", model, CallModel.Default.Body); model.SampleUri = $"{Request.Scheme}://{Request.Host}/api/Dummy?a=11&b=22"; if (!model.SkipCall) { Task <HttpResponseMessage> task = null; switch (model.Method) { case "(unknown)": case "GET": task = HTTP.GetAsync(model.Uri); model.Method = "GET"; break; case "POST": task = HTTP.PostAsync(model.Uri, new StringContent(model.Body)); break; default: var req = new HttpRequestMessage { Method = GetMethod(model.Method), RequestUri = new Uri(model.Uri), Content = new StringContent(model.Body), }; task = HTTP.SendAsync(req); break; } model.Set(task); } model.SkipCall = false; return(View(model)); }