Exemplo n.º 1
0
        private bool ProcessAlbums(RequestedModel model, HeadphonesSettings hp)
        {
            try
            {
                if (hp.Enabled)
                {
                    var sender = new HeadphonesSender(HpApi, hp, RequestService);
                    var result = sender.AddAlbum(model).Result;

                    if (result)
                    {
                        if (ShouldAutoApprove(model.Type, PrSettings, model.RequestedUsers))
                        {
                            // Approve it now
                            model.Approved = true;
                        }
                        RequestService.UpdateRequest(model);
                    }
                    ;

                    return(result);
                }
                return(false);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(false); // It fails so it will get added back into the queue
            }
        }
Exemplo n.º 2
0
        private async Task <Response> RequestAlbumAndUpdateStatus(RequestedModel request)
        {
            var hpSettings = await HeadphonesSettings.GetSettingsAsync();

            Log.Info("Adding album to Headphones : {0}", request.Title);
            if (!hpSettings.Enabled)
            {
                // Approve it
                request.Approved = true;
                Log.Warn("We approved Album: {0} but could not add it to Headphones because it has not been setup", request.Title);

                // Update the record
                var inserted = await Service.UpdateRequestAsync(request);

                return(Response.AsJson(inserted
                    ? new JsonResponseModel {
                    Result = true, Message = "This has been approved, but It has not been sent to Headphones because it has not been configured."
                }
                    : new JsonResponseModel
                {
                    Result = false,
                    Message = "We could not approve this request. Please try again or check the logs."
                }));
            }

            var sender = new HeadphonesSender(HeadphoneApi, hpSettings, Service);
            var result = sender.AddAlbum(request);


            return(Response.AsJson(new JsonResponseModel {
                Result = true, Message = "We have sent the approval to Headphones for processing, This can take a few minutes."
            }));
        }
Exemplo n.º 3
0
        public void SaveBadHeadphonesSettings()
        {
            var model = new HeadphonesSettings
            {
                Ip  = "q",
                Ssl = true,
            };
            var browser = new Browser(Bootstrapper);
            var result  = browser.Post("/api/settings/headphones", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.Query("apikey", "api");
                with.JsonBody(model);
            });

            var body = JsonConvert.DeserializeObject <ApiModel <bool> >(result.Body.AsString());

            Assert.That(body.Data, Is.EqualTo(false));
            Assert.That(body.Error, Is.True);
            Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
        }
Exemplo n.º 4
0
 public HeadphonesSender(IHeadphonesApi api, HeadphonesSettings settings, IRequestService request)
 {
     Api            = api;
     Settings       = settings;
     RequestService = request;
 }
Exemplo n.º 5
0
        public void SetUp()
        {
            _settings = new HeadphonesSettings();

            _caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml");
        }