Bladeren bron

initial progress

Karathan 6 jaren geleden
bovenliggende
commit
c29b9b4b29
7 gewijzigde bestanden met toevoegingen van 362 en 0 verwijderingen
  1. 13
    0
      BlizzSharp.csproj
  2. 77
    0
      BlizzSharpClient.cs
  3. 34
    0
      Data/Auction.cs
  4. 22
    0
      Data/AuctionLocator.cs
  5. 14
    0
      Data/AuctionRealm.cs
  6. 14
    0
      Data/AuctionResponse.cs
  7. 188
    0
      Data/Item.cs

+ 13
- 0
BlizzSharp.csproj Bestand weergeven

@@ -0,0 +1,13 @@
1
+<Project Sdk="Microsoft.NET.Sdk">
2
+
3
+  <PropertyGroup>
4
+    <TargetFramework>netstandard2.0</TargetFramework>
5
+    <LangVersion>7.1</LangVersion> 
6
+  </PropertyGroup>
7
+
8
+  <ItemGroup>
9
+    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
10
+    
11
+  </ItemGroup>
12
+
13
+</Project>

+ 77
- 0
BlizzSharpClient.cs Bestand weergeven

@@ -0,0 +1,77 @@
1
+using System;
2
+using System.Net;
3
+using System.Net.Http;
4
+using System.Net.Http.Headers;
5
+using System.Threading.Tasks;
6
+using Newtonsoft.Json;
7
+using BlizzSharp.Data;
8
+using System.Collections.Generic;
9
+
10
+namespace BlizzSharp
11
+{
12
+    public class BlizzSharpClient
13
+    {
14
+        private readonly Dictionary<long, Item> _itemLookup;
15
+        private string _key;
16
+        private HttpClient _http;
17
+        private JsonSerializer _serializer;
18
+        private long _latestTimeStamp;
19
+        public AuctionResponse CurrentAuctionResponse {get;set;}
20
+        public AuctionResponse PreviousAuctionResponse {get;set;}
21
+
22
+        public BlizzSharpClient(string key)
23
+        {
24
+            _itemLookup = new Dictionary<long, Item>();
25
+            _serializer = new JsonSerializer();
26
+            _http = new HttpClient();
27
+            _http.BaseAddress = new Uri("https://eu.api.battle.net/wow/");
28
+            _http.DefaultRequestHeaders.Accept.Clear();
29
+            _http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
30
+            _key = key;
31
+            _latestTimeStamp = -1;
32
+        }
33
+
34
+        //TODO: Exception handling
35
+        public async Task<AuctionResponse> GetAuctionsAsync(string realm, string locale)
36
+        {
37
+            HttpResponseMessage response = await _http.GetAsync($"auction/data/{realm}?locale={locale}&apikey={_key}");
38
+            if(response.IsSuccessStatusCode)
39
+            {
40
+                string auctionsLocatorResponse = await response.Content.ReadAsStringAsync();
41
+                AuctionLocator locator = JsonConvert.DeserializeObject<Data.AuctionLocatorList>(auctionsLocatorResponse).Locators[0];
42
+                if((locator.Timestamp > _latestTimeStamp) || CurrentAuctionResponse == null)
43
+                {
44
+                    using(HttpClient auctionClient = new HttpClient())
45
+                    {
46
+                        HttpResponseMessage auctionResponse = await auctionClient.GetAsync(locator.Url);
47
+                        if(auctionResponse.IsSuccessStatusCode)
48
+                        {
49
+                            string auctionsResponse = await auctionResponse.Content.ReadAsStringAsync();
50
+                            PreviousAuctionResponse = CurrentAuctionResponse;
51
+                            CurrentAuctionResponse = JsonConvert.DeserializeObject<AuctionResponse>(auctionsResponse);
52
+                            return CurrentAuctionResponse;
53
+                        }
54
+                    }
55
+
56
+                }
57
+            }
58
+                
59
+            return null;
60
+        }
61
+
62
+        public async Task<Item> GetItemInfoAsync(long itemId, string locale)
63
+        {
64
+            if(_itemLookup.ContainsKey(itemId))
65
+                return _itemLookup[itemId];
66
+            HttpResponseMessage response = await _http.GetAsync($"item/{itemId}?locale={locale}&apikey={_key}");
67
+            if(response.IsSuccessStatusCode)
68
+            {
69
+                string itemResponse = await response.Content.ReadAsStringAsync();
70
+                Item item = JsonConvert.DeserializeObject<Item>(itemResponse);
71
+                _itemLookup[itemId] = item;
72
+                return item;
73
+            }
74
+            return null;
75
+        }
76
+    }
77
+}

+ 34
- 0
Data/Auction.cs Bestand weergeven

@@ -0,0 +1,34 @@
1
+using Newtonsoft.Json;
2
+
3
+namespace BlizzSharp.Data
4
+{
5
+    //	{"auc":527048554,"item":152507,"owner":"Fîrî","ownerRealm":"Arygos","bid":800100,"buyout":835000,"quantity":1,"timeLeft":"VERY_LONG","rand":0,"seed":0,"context":0}
6
+
7
+    public class Auction
8
+    {
9
+        [JsonProperty("auc")]
10
+        public long Id {get;set;}
11
+        [JsonProperty("item")]
12
+        
13
+        public long Item{get;set;}
14
+
15
+        [JsonProperty("owner")]
16
+        public string Owner {get;set;}
17
+
18
+        [JsonProperty("ownerRealm")]
19
+        public string OwnerRealm {get;set;}
20
+
21
+        [JsonProperty("bid")]
22
+        public long Bid {get;set;}
23
+
24
+        [JsonProperty("buyout")]
25
+        public long Buyout {get;set;}
26
+
27
+        [JsonProperty("quantity")]
28
+        public int quantity {get;set;}
29
+
30
+        [JsonProperty("timeLeft")]
31
+        public string TimeLeft {get;set;}
32
+    }
33
+
34
+}

+ 22
- 0
Data/AuctionLocator.cs Bestand weergeven

@@ -0,0 +1,22 @@
1
+using System.Collections.Generic;
2
+using Newtonsoft.Json;
3
+
4
+namespace BlizzSharp.Data
5
+{
6
+    //	{"files":[{"url":"http://auction-api-eu.worldofwarcraft.com/auction-data/1488d9d770f41c6da8a4dcaed7138eab/auctions.json","lastModified":1534800577000}]}
7
+
8
+    public class AuctionLocatorList
9
+    {
10
+        [JsonProperty("files")]
11
+        public AuctionLocator[] Locators;
12
+    }
13
+
14
+    public class AuctionLocator
15
+    {
16
+        [JsonProperty("url")]
17
+        public string Url {get;set;}
18
+
19
+        [JsonProperty("lastModified")]
20
+        public long Timestamp {get;set;} 
21
+    }
22
+}

+ 14
- 0
Data/AuctionRealm.cs Bestand weergeven

@@ -0,0 +1,14 @@
1
+using System.Collections.Generic;
2
+using Newtonsoft.Json;
3
+
4
+namespace BlizzSharp.Data
5
+{
6
+    public class AuctionRealm
7
+    {
8
+        [JsonProperty("name")]
9
+        public string Name {get;set;}
10
+
11
+        [JsonProperty("slug")]
12
+        public string Slug {get;set;}
13
+    }
14
+}

+ 14
- 0
Data/AuctionResponse.cs Bestand weergeven

@@ -0,0 +1,14 @@
1
+using System.Collections.Generic;
2
+using Newtonsoft.Json;
3
+
4
+namespace BlizzSharp.Data
5
+{
6
+    public class AuctionResponse
7
+    {
8
+        [JsonProperty("realms")]
9
+        public AuctionRealm[] Realms{get;set;}
10
+
11
+        [JsonProperty("auctions")]
12
+        public Auction[] Auctions{get;set;}
13
+    }
14
+}

+ 188
- 0
Data/Item.cs Bestand weergeven

@@ -0,0 +1,188 @@
1
+using Newtonsoft.Json;
2
+
3
+namespace BlizzSharp.Data
4
+{
5
+    public class Item
6
+    {
7
+        [JsonProperty("id")]
8
+        public long Id { get; set; }
9
+
10
+        [JsonProperty("disenchantingSkillRank")]
11
+        public long DisenchantingSkillRank { get; set; }
12
+
13
+        [JsonProperty("description")]
14
+        public string Description { get; set; }
15
+
16
+        [JsonProperty("name")]
17
+        public string Name { get; set; }
18
+
19
+        [JsonProperty("icon")]
20
+        public string Icon { get; set; }
21
+
22
+        [JsonProperty("stackable")]
23
+        public long Stackable { get; set; }
24
+
25
+        [JsonProperty("itemBind")]
26
+        public long ItemBind { get; set; }
27
+
28
+        [JsonProperty("bonusStats")]
29
+        public BonusStat[] BonusStats { get; set; }
30
+
31
+        [JsonProperty("itemSpells")]
32
+        public object[] ItemSpells { get; set; }
33
+
34
+        [JsonProperty("buyPrice")]
35
+        public long BuyPrice { get; set; }
36
+
37
+        [JsonProperty("itemClass")]
38
+        public long ItemClass { get; set; }
39
+
40
+        [JsonProperty("itemSubClass")]
41
+        public long ItemSubClass { get; set; }
42
+
43
+        [JsonProperty("containerSlots")]
44
+        public long ContainerSlots { get; set; }
45
+
46
+        [JsonProperty("weaponInfo")]
47
+        public WeaponInfo WeaponInfo { get; set; }
48
+
49
+        [JsonProperty("inventoryType")]
50
+        public long InventoryType { get; set; }
51
+
52
+        [JsonProperty("equippable")]
53
+        public bool Equippable { get; set; }
54
+
55
+        [JsonProperty("itemLevel")]
56
+        public long ItemLevel { get; set; }
57
+
58
+        [JsonProperty("maxCount")]
59
+        public long MaxCount { get; set; }
60
+
61
+        [JsonProperty("maxDurability")]
62
+        public long MaxDurability { get; set; }
63
+
64
+        [JsonProperty("minFactionId")]
65
+        public long MinFactionId { get; set; }
66
+
67
+        [JsonProperty("minReputation")]
68
+        public long MinReputation { get; set; }
69
+
70
+        [JsonProperty("quality")]
71
+        public long Quality { get; set; }
72
+
73
+        [JsonProperty("sellPrice")]
74
+        public long SellPrice { get; set; }
75
+
76
+        [JsonProperty("requiredSkill")]
77
+        public long RequiredSkill { get; set; }
78
+
79
+        [JsonProperty("requiredLevel")]
80
+        public long RequiredLevel { get; set; }
81
+
82
+        [JsonProperty("requiredSkillRank")]
83
+        public long RequiredSkillRank { get; set; }
84
+
85
+        [JsonProperty("itemSource")]
86
+        public ItemSource ItemSource { get; set; }
87
+
88
+        [JsonProperty("baseArmor")]
89
+        public long BaseArmor { get; set; }
90
+
91
+        [JsonProperty("hasSockets")]
92
+        public bool HasSockets { get; set; }
93
+
94
+        [JsonProperty("isAuctionable")]
95
+        public bool IsAuctionable { get; set; }
96
+
97
+        [JsonProperty("armor")]
98
+        public long Armor { get; set; }
99
+
100
+        [JsonProperty("displayInfoId")]
101
+        public long DisplayInfoId { get; set; }
102
+
103
+        [JsonProperty("nameDescription")]
104
+        public string NameDescription { get; set; }
105
+
106
+        [JsonProperty("nameDescriptionColor")]
107
+        public string NameDescriptionColor { get; set; }
108
+
109
+        [JsonProperty("upgradable")]
110
+        public bool Upgradable { get; set; }
111
+
112
+        [JsonProperty("heroicTooltip")]
113
+        public bool HeroicTooltip { get; set; }
114
+
115
+        [JsonProperty("context")]
116
+        public string Context { get; set; }
117
+
118
+        [JsonProperty("bonusLists")]
119
+        public object[] BonusLists { get; set; }
120
+
121
+        [JsonProperty("availableContexts")]
122
+        public string[] AvailableContexts { get; set; }
123
+
124
+        [JsonProperty("bonusSummary")]
125
+        public BonusSummary BonusSummary { get; set; }
126
+
127
+        [JsonProperty("artifactId")]
128
+        public long ArtifactId { get; set; }
129
+    }
130
+
131
+    public class BonusStat
132
+    {
133
+        [JsonProperty("stat")]
134
+        public long Stat { get; set; }
135
+
136
+        [JsonProperty("amount")]
137
+        public long Amount { get; set; }
138
+    }
139
+
140
+    public class BonusSummary
141
+    {
142
+        [JsonProperty("defaultBonusLists")]
143
+        public object[] DefaultBonusLists { get; set; }
144
+
145
+        [JsonProperty("chanceBonusLists")]
146
+        public object[] ChanceBonusLists { get; set; }
147
+
148
+        [JsonProperty("bonusChances")]
149
+        public object[] BonusChances { get; set; }
150
+    }
151
+
152
+    public class ItemSource
153
+    {
154
+        [JsonProperty("sourceId")]
155
+        public long SourceId { get; set; }
156
+
157
+        [JsonProperty("sourceType")]
158
+        public string SourceType { get; set; }
159
+    }
160
+
161
+    public class WeaponInfo
162
+    {
163
+        [JsonProperty("damage")]
164
+        public Damage Damage { get; set; }
165
+
166
+        [JsonProperty("weaponSpeed")]
167
+        public double WeaponSpeed { get; set; }
168
+
169
+        [JsonProperty("dps")]
170
+        public double Dps { get; set; }
171
+    }
172
+
173
+    public class Damage
174
+    {
175
+        [JsonProperty("min")]
176
+        public long Min { get; set; }
177
+
178
+        [JsonProperty("max")]
179
+        public long Max { get; set; }
180
+
181
+        [JsonProperty("exactMin")]
182
+        public double ExactMin { get; set; }
183
+
184
+        [JsonProperty("exactMax")]
185
+        public double ExactMax { get; set; }
186
+    }
187
+
188
+}