< Summary

Class:DCL.Helpers.NFT.Markets.OpenSea_Internal.SingleAssetRequestHandler
Assembly:OpenSea_Internal
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/OpenSea/RequestHandlers/SingleAssetRequestHandler.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:72
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SingleAssetRequestHandler(...)0%2100%
get_schedulableRequestHandler()0%2100%
GetUrl()0%2100%
SetApiResponse(...)0%20400%
SetApiResponseError(...)0%2100%
CanRetry()0%2100%
Retry()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/OpenSea/RequestHandlers/SingleAssetRequestHandler.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Helpers.NFT.Markets.OpenSea_Internal
 5{
 6    internal class SingleAssetRequestHandler : IRequestHandler
 7    {
 8        const bool VERBOSE = false;
 9
 010        private readonly SchedulableRequestHandler schedulableHandler = new SchedulableRequestHandler();
 11        private readonly RequestAssetSingle request;
 12        private readonly RequestController requestController;
 13
 14        private int retryCount = 0;
 15
 016        SchedulableRequestHandler IRequestHandler.schedulableRequestHandler => schedulableHandler;
 17
 018        public SingleAssetRequestHandler(RequestAssetSingle request, RequestController requestController)
 19        {
 20            if (VERBOSE)
 21                Debug.Log($"SingleAssetRequestHandler: ({GetHashCode()}) {request.requestId} created");
 22
 023            this.request = request;
 024            this.requestController = requestController;
 025            schedulableHandler.SetReadyToBeScheduled(this);
 026        }
 27
 028        string IRequestHandler.GetUrl() { return $"{Constants.SINGLE_ASSET_URL}/{request.contractAddress}/{request.token
 29
 30        void IRequestHandler.SetApiResponse(string responseJson, Action onSuccess, Action<string> onError)
 31        {
 032            SingleAssetResponse response = null;
 33
 34            try
 35            {
 036                response = Utils.FromJsonWithNulls<SingleAssetResponse>(responseJson);
 037            }
 038            catch (Exception e)
 39            {
 040                onError?.Invoke(e.Message);
 041            }
 42
 043            if (response == null)
 044                return;
 45
 46            if (VERBOSE)
 47                Debug.Log($"SingleAssetRequestHandler: ({GetHashCode()}) {request.requestId} resolved");
 48
 049            request.Resolve(response);
 050            onSuccess?.Invoke();
 051        }
 52
 53        void IRequestHandler.SetApiResponseError(string error)
 54        {
 55            if (VERBOSE)
 56                Debug.Log($"SingleAssetRequestHandler: ({GetHashCode()}) {request.requestId} rejected {error}");
 57
 058            request.Reject(error);
 059        }
 60
 061        bool IRequestHandler.CanRetry() { return retryCount < Constants.REQUESTS_RETRY_ATTEMPS; }
 62
 63        void IRequestHandler.Retry()
 64        {
 65            if (VERBOSE)
 66                Debug.Log($"SingleAssetRequestHandler: ({GetHashCode()}) {request.requestId} retry {retryCount}");
 67
 068            requestController.requestScheduler.EnqueueRequest(this);
 069            retryCount ++;
 070        }
 71    }
 72}