/// <summary>
        /// Implements <see cref="IUserComicsHttpRepository.CreateUserComic"/>.
        /// </summary>
        public async Task <UserComic> CreateUserComic(
            Comic comic,
            StorageContainer storageContainer,
            string userId)
        {
            var fullUrl = $"{_comicApiConfig.ClientBaseUrl}/{EndpointsV1.UserComicsEndpointBase}/{userId}";

            Logger.LogDebug("Making request to: {endpoint}", fullUrl);
            CreateUserComicRequest createUserComicRequest = new CreateUserComicRequest()
            {
                StorageContainer = storageContainer,
                Comic            = comic
            };

            var client = new HttpRequestClientBuilder <object>()
                         .WithAbsoluteUrl(fullUrl)
                         .WithRequestBody(createUserComicRequest)
                         .WithRequestMethod(HttpMethod.Post)
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithTokenClientSettings(_tokenClientSettings)
                         .Build();

            object response = await client.Send();

            var comicResponse = JsonConvert.DeserializeObject <UserComic>(response.ToString());

            Logger.LogDebug("Response returned: {response}", comicResponse);

            return(comicResponse);
        }
Example #2
0
        public async Task <StorageContainer> CreateStorageContainer(StorageContainer storageContainer)
        {
            var fullUrl = $"{_comicApiConfig.ClientBaseUrl}/{EndpointsV1.StorageContainerEndpointBase}";

            Logger.LogDebug("Making request to: {endpoint}", fullUrl);

            var client = new HttpRequestClientBuilder <StorageContainer>()
                         .WithAbsoluteUrl(fullUrl)
                         .WithRequestBody(storageContainer)
                         .WithRequestMethod(HttpMethod.Post)
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithTokenClientSettings(_tokenClientSettings)
                         .Build();

            var savedStorageContainer = await client.Send();

            if (savedStorageContainer is null)
            {
                throw new Exception("Something went wrong during save process.");
            }

            Logger.LogDebug("Response returned: {response}", savedStorageContainer);

            return(savedStorageContainer);
        }
        /// <summary>
        /// Sends an HTTP request to get comic(s)
        /// </summary>
        /// <returns></returns>
        public async Task <MarvelResponse> RequestComic(string route, string query)
        {
            string url = CreateRequestUrl(route, query);

            _logger.LogDebug("Making request to marvel url: {url}", url);

            var client = new HttpRequestClientBuilder <MarvelResponse>()
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithRequestMethod(HttpMethod.Get)
                         .WithAbsoluteUrl(url)
                         .Build();

            var response = await client.Send();

            return(response);
        }
        /// <summary>
        /// Implements <see cref="IUserComicsHttpRepository.DeleteUserComic"/>
        /// </summary>
        public async Task <bool> DeleteUserComic(string userComicId, string userId)
        {
            var fullUrl = $"{_comicApiConfig.ClientBaseUrl}/{EndpointsV1.UserComicsEndpointBase}/{userId}/comic/{userComicId}";

            Logger.LogDebug("Making request to: {endpoint}", fullUrl);

            var client = new HttpRequestClientBuilder <bool>()
                         .WithAbsoluteUrl(fullUrl)
                         .WithRequestMethod(HttpMethod.Delete)
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithTokenClientSettings(_tokenClientSettings)
                         .Build();

            var isComicDeleted = await client.Send();

            return(isComicDeleted);
        }
        /// <summary>
        /// Retrieves all comics associated with a user.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <UserComic> > RequestAllUserComics(string userId)
        {
            var fullUrl = $"{_comicApiConfig.ClientBaseUrl}/{EndpointsV1.UserComicsEndpointBase}/{userId}";

            Logger.LogDebug("Making request to: {endpoint}", fullUrl);

            var client = new HttpRequestClientBuilder <object>()
                         .WithRequestMethod(HttpMethod.Get)
                         .WithAbsoluteUrl(fullUrl)
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithTokenClientSettings(_tokenClientSettings)
                         .Build();

            var response = await client.Send();

            var comicResponseString = response.ToString();
            var comicResponse       = JsonConvert
                                      .DeserializeObject <IEnumerable <UserComic> >(comicResponseString);

            Logger.LogDebug("Response returned: {response}", comicResponse);

            return(comicResponse);
        }
Example #6
0
        /// <summary>
        /// Makes a request to Marvel api, to find all comics matching title/issue number.
        /// </summary>
        /// <param name="title">The <see cref="Comic"/> title.</param>
        /// <param name="issueNumber">The <see cref="Comic"/> issue number.</param>
        /// <returns><see cref="IEnumerable{Comic}"/></returns>
        public async Task <IEnumerable <Comic> > RequestMarvelComicsByParameters(
            string title, string issueNumber
            )
        {
            var endpoint   = $"{EndpointsV1.MarvelComicsSearchEndpoint}";
            var parameters = $"title={title}&issueNumber={issueNumber}";

            Logger.LogDebug(
                "Making request to: {endpoint} with parameters: {parameters}",
                endpoint,
                parameters);

            try
            {
                var absoluteUrl = $"{_comicApiConfig.ClientBaseUrl}/{endpoint}?{parameters}";
                Logger.LogDebug("making request to {endpoint}", absoluteUrl);
                var client = new HttpRequestClientBuilder <IEnumerable <Comic> >()
                             .WithRequestMethod(HttpMethod.Get)
                             .WithAbsoluteUrl(absoluteUrl)
                             .WithHttpContextAccessor(_httpContextAccessor)
                             .WithTokenClientSettings(_tokenClientSettings)
                             .Build();

                var comics = await client.Send();

                Logger.LogDebug("{endpoint} response: {response}", absoluteUrl, comics);

                return(comics);
            }
            catch (Exception e)
            {
                Logger.LogDebug(e,
                                "Exception thrown while trying to make request to {comicEngineUri}.",
                                _comicApiConfig.ClientBaseUrl);
                throw;
            }
        }
Example #7
0
        public async Task <IEnumerable <StorageContainer> > GetStorageContainers(string subject)
        {
            var fullUrl = $"{_comicApiConfig.ClientBaseUrl}/{EndpointsV1.StorageContainerEndpointBase}/{subject}";

            Logger.LogDebug("Making request to: {endpoint}", fullUrl);

            var client = new HttpRequestClientBuilder <IEnumerable <StorageContainer> >()
                         .WithAbsoluteUrl(fullUrl)
                         .WithRequestMethod(HttpMethod.Get)
                         .WithHttpContextAccessor(_httpContextAccessor)
                         .WithTokenClientSettings(_tokenClientSettings)
                         .Build();

            var getStorageContainers = await client.Send();

            if (getStorageContainers is null)
            {
                throw new Exception("Something went wrong during get process.");
            }

            Logger.LogDebug("Response returned: {response}", getStorageContainers);

            return(getStorageContainers);
        }
Example #8
0
        /// <summary>
        /// Sends UPC barcode value to marvel api, and returns matching comic.
        /// </summary>
        /// <param name="upc">The value in upc format, obtained from barcode.</param>
        /// <returns><see cref="Comic"/></returns>
        public async Task <Comic> RequestMarvelComicByUpc(
            string upc
            )
        {
            var parameters = $"upc={upc}";

            Logger.LogDebug(
                "Making request to: {endpoint}, with parameters: {parameters}",
                EndpointsV1.MarvelComicsUpcEndpoint, parameters);
            try
            {
                var absoluteUrl = $"{_comicApiConfig.ClientBaseUrl}/{_comicApiConfig.ClientBaseUrl}?{parameters}";

                Logger.LogDebug("making request to {endpoint}", absoluteUrl);

                var client = new HttpRequestClientBuilder <Comic>()
                             .WithRequestMethod(HttpMethod.Get)
                             .WithAbsoluteUrl(absoluteUrl)
                             .WithHttpContextAccessor(_httpContextAccessor)
                             .WithTokenClientSettings(_tokenClientSettings)
                             .Build();

                var comics = await client.Send();

                Logger.LogDebug("{endpoint} response: {response}", absoluteUrl, comics);

                return(comics);
            }
            catch (Exception e)
            {
                Logger.LogDebug(e,
                                "Exception thrown while trying to make request to {comicEngineUri}.",
                                _comicApiConfig.ClientBaseUrl);
                throw;
            }
        }