< Summary

Class:DCL.ABConverter.WearablesCollectionClient
Assembly:WearablesFetchingHelper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/WearablesHelper/WearablesCollectionClient.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:55
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BuildWearableCollectionFetchingURL(...)0%2100%
GetBaseWearableCollections()0%2100%
GetWearableItems(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/WearablesHelper/WearablesCollectionClient.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Helpers;
 5using Newtonsoft.Json;
 6using UnityEditor;
 7using UnityEngine;
 8using UnityEngine.Networking;
 9
 10namespace DCL.ABConverter
 11{
 12    public static class WearablesCollectionClient
 13    {
 14        private static WearableCollectionsAPIData.Collection[] wearableCollections;
 15        private static double wearablesCollectionDumpStartTime;
 16
 17        public static string BuildWearableCollectionFetchingURL(string targetCollectionId) =>
 018            WearablesFetchingHelper.GetWearablesFetchURL() + "collectionId=" + targetCollectionId;
 19
 20        public static List<WearableItem> GetBaseWearableCollections() =>
 021            GetWearableItems(BuildWearableCollectionFetchingURL(WearablesFetchingHelper.BASE_WEARABLES_COLLECTION_ID));
 22
 23        /// <summary>
 24        /// Given a base-url to fetch wearables collections, returns a list of all the WearableItems
 25        /// </summary>
 26        /// <param name="url">base-url to fetch the wearables collections</param>
 27        /// <returns>A list of all the WearableItems found</returns>
 28        private static List<WearableItem> GetWearableItems(string url)
 29        {
 030            UnityWebRequest w = UnityWebRequest.Get(url);
 031            w.SendWebRequest();
 32
 033            while (!w.isDone) { }
 34
 035            if (!w.WebRequestSucceded())
 36            {
 037                Debug.LogError($"Request error! Wearable at '{url}' couldn't be fetched! -- {w.error}");
 038                return null;
 39            }
 40
 041            var wearablesApiData = JsonConvert.DeserializeObject<WearablesAPIData>(w.downloadHandler.text);
 042            var resultList = wearablesApiData.GetWearableItems();
 43
 44            // Since the wearables deployments response returns only a batch of elements, we need to fetch all the
 45            // batches sequentially
 046            if (!string.IsNullOrEmpty(wearablesApiData.pagination.next))
 47            {
 048                var nextPageResults = GetWearableItems(WearablesFetchingHelper.GetWearablesFetchURL() + wearablesApiData
 049                resultList.AddRange(nextPageResults);
 50            }
 51
 052            return resultList;
 53        }
 54    }
 55}