< Summary

Class:WearablesAPIData
Assembly:WearablesFetching
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/Wearables/WearablesAPIData.cs
Covered lines:0
Uncovered lines:16
Coverable lines:16
Total lines:126
Line coverage:0% (0 of 16)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetWearableItems()0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/Wearables/WearablesAPIData.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4[Serializable]
 5public class WearablesAPIData
 6{
 7    [Serializable]
 8    public class Wearable
 9    {
 10        [Serializable]
 11        public class Data
 12        {
 13            [Serializable]
 14            public class Representation
 15            {
 16                [Serializable]
 17                public class Content
 18                {
 19                    public string key;
 20                    public string url;
 21                }
 22
 23                public string[] bodyShapes;
 24                public string mainFile;
 25                public string[] overrideReplaces;
 26                public string[] overrideHides;
 27                public Content[] contents;
 28            }
 29
 30            public string[] tags;
 31            public string category;
 32            public Representation[] representations;
 33        }
 34
 35        public string id;
 36        public string description;
 37        public string thumbnail;
 38        public string rarity;
 39        public Data data;
 40        public i18n[] i18n;
 41        public int createdAt;
 42        public int updatedAt;
 43    }
 44
 45    [Serializable]
 46    public class PaginationData
 47    {
 48        public int limit;
 49        public string next = null;
 50    }
 51
 52    // TODO: dinamically use ICatalyst.contentUrl, content server is not a const
 53    private const string WEARABLES_CONTENT_BASE_URL = "https://peer-lb.decentraland.org/content/contents/";
 54
 55    public List<Wearable> wearables;
 56    public PaginationData pagination;
 57    public List<WearableItem> GetWearableItems()
 58    {
 059        if (wearables == null || wearables.Count == 0)
 060            return null;
 61
 062        List<WearableItem> result = new List<WearableItem>();
 63
 064        foreach (var wearableData in wearables)
 65        {
 66            // Populate new WearableItem with fetched data
 067            WearableItem wearable = new WearableItem()
 68            {
 69                id = wearableData.id,
 70                baseUrl = WEARABLES_CONTENT_BASE_URL,
 71                thumbnail = wearableData.thumbnail,
 72                rarity = wearableData.rarity,
 73                description = wearableData.description,
 74                i18n = wearableData.i18n,
 75                data = new WearableItem.Data()
 76                {
 77                    category = wearableData.data.category,
 78                    tags = wearableData.data.tags
 79                }
 80            };
 81
 082            List<WearableItem.Representation> wearableRepresentations = new List<WearableItem.Representation>();
 083            foreach (var wearableDataRepresentation in wearableData.data.representations)
 84            {
 085                WearableItem.Representation wearableRepresentation = new WearableItem.Representation()
 86                {
 87                    bodyShapes = wearableDataRepresentation.bodyShapes,
 88                    overrideHides = wearableDataRepresentation.overrideHides,
 89                    overrideReplaces = wearableDataRepresentation.overrideReplaces,
 90                    mainFile = wearableDataRepresentation.mainFile
 91                };
 92
 093                List<WearableItem.MappingPair> contentMappingPairs = new List<WearableItem.MappingPair>();
 094                foreach (var content in wearableDataRepresentation.contents)
 95                {
 096                    contentMappingPairs.Add(new WearableItem.MappingPair()
 97                    {
 98                        key = content.key,
 99                        hash = content.url.Substring(content.url.LastIndexOf("/") + 1)
 100                    });
 101                }
 102
 0103                wearableRepresentation.contents = contentMappingPairs.ToArray();
 0104                wearableRepresentations.Add(wearableRepresentation);
 105            }
 106
 0107            wearable.data.representations = wearableRepresentations.ToArray();
 0108            result.Add(wearable);
 109        }
 110
 0111        return result;
 112    }
 113}
 114
 115[Serializable]
 116public class WearableCollectionsAPIData
 117{
 118    [Serializable]
 119    public class Collection
 120    {
 121        public string id;
 122        public string name;
 123    }
 124
 125    public Collection[] collections;
 126}

Methods/Properties

GetWearableItems()