|
4 | 4 | using System; |
5 | 5 | using System.Threading.Tasks; |
6 | 6 | using Foundation; |
| 7 | +using System.Net.Http; |
7 | 8 |
|
8 | 9 | namespace CodeHub.iOS.Services |
9 | 10 | { |
10 | 11 | public class FeaturesService : IFeaturesService |
11 | 12 | { |
12 | 13 | private readonly IDefaultValueService _defaultValueService; |
13 | | - private readonly IHttpClientService _httpClientService; |
14 | | - private readonly IJsonSerializationService _jsonSerializationService; |
15 | 14 |
|
16 | | - |
17 | | - public FeaturesService(IDefaultValueService defaultValueService, IHttpClientService httpClientService, IJsonSerializationService jsonSerializationService) |
| 15 | + public FeaturesService(IDefaultValueService defaultValueService) |
18 | 16 | { |
19 | 17 | _defaultValueService = defaultValueService; |
20 | | - _httpClientService = httpClientService; |
21 | | - _jsonSerializationService = jsonSerializationService; |
22 | 18 | } |
23 | 19 |
|
24 | 20 | public bool IsPushNotificationsActivated |
@@ -58,14 +54,17 @@ public bool IsActivated(string id) |
58 | 54 |
|
59 | 55 | public async Task<IEnumerable<string>> GetAvailableFeatureIds() |
60 | 56 | { |
61 | | - var ids = new List<string>(); |
62 | | - ids.Add(FeatureIds.EnterpriseSupport); |
63 | | - var client = _httpClientService.Create(); |
| 57 | + var client = new HttpClient(); |
64 | 58 | client.Timeout = new TimeSpan(0, 0, 15); |
65 | | - var response = await client.GetAsync("http://push.codehub-app.com/in-app?version=" + NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"].ToString()); |
| 59 | + |
| 60 | + var response = await client.GetAsync("https://raw.githubusercontent.com/thedillonb/CodeHub/gh-pages/features.json"); |
66 | 61 | var data = await response.Content.ReadAsStringAsync(); |
67 | | - ids.AddRange(_jsonSerializationService.Deserialize<List<string>>(data)); |
68 | | - return ids; |
| 62 | + var features = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(data); |
| 63 | + |
| 64 | + var version = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"].ToString(); |
| 65 | + if (!features.ContainsKey(version)) |
| 66 | + return new [] { FeatureIds.EnterpriseSupport }; |
| 67 | + return features[version]; |
69 | 68 | } |
70 | 69 | } |
71 | 70 | } |
|
0 commit comments