75 lines
2.6 KiB
C#
75 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using Localization;
|
|
using uPromise;
|
|
|
|
namespace Online
|
|
{
|
|
public class NewsService
|
|
{
|
|
public class NewsData
|
|
{
|
|
public DateTime PublicationDate;
|
|
public string Title;
|
|
public string Body;
|
|
public string MediaUrl;
|
|
public Dictionary<string, string> Links;
|
|
}
|
|
|
|
private IHttpEngine httpEngine;
|
|
private string applicationId;
|
|
private string spaceId;
|
|
|
|
public NewsService(IHttpEngine httpEngine, string applicationId, string spaceId)
|
|
{
|
|
this.httpEngine = httpEngine;
|
|
this.applicationId = applicationId;
|
|
this.spaceId = spaceId;
|
|
}
|
|
|
|
public Promise<List<NewsData>> RequestNews()
|
|
{
|
|
return PromiseFactory.StartNewDeferred<List<NewsData>>(dfd => dfd.Reject());
|
|
|
|
/*var deferred = new Deferred<List<NewsData>>();
|
|
|
|
serviceLocator.BuildUbiservicesRequest(1, "/spaces/news?spaceId=" + spaceId)
|
|
.Then(request =>
|
|
{
|
|
var language = LocalizationManager.Instance.GetSystemLanguage();
|
|
var locale = LocalizationManager.Instance.GetSystemCountry();
|
|
|
|
request.Method = HttpMethod.Get;
|
|
request.Headers["Ubi-AppId"] = applicationId;
|
|
request.Headers["Ubi-LocaleCode"] = language + "-" + locale;
|
|
request.Headers["Ubi-Market"] = locale;
|
|
|
|
return httpEngine.Execute(request);
|
|
})
|
|
.Then(response =>
|
|
{
|
|
//Debug.Log(JSON.Stringify(response.Body));
|
|
|
|
// convert from JSON to public API format
|
|
var news = response.Body.GetFieldAsArray("news")
|
|
.Select(json => new NewsData
|
|
{
|
|
PublicationDate = DateTime.Parse(json.GetFieldAsString("publicationDate")),
|
|
Title = json.GetFieldAsString("title"),
|
|
Body = json.GetFieldAsString("body"),
|
|
MediaUrl = json.GetFieldAsString("mediaURL"),
|
|
Links = json.GetFieldAsArray("links").ToDictionary(link => link.GetFieldAsString("type"), link => link.GetFieldAsString("param"))
|
|
})
|
|
.OrderBy(data => data.PublicationDate)
|
|
.ToList();
|
|
|
|
deferred.Resolve(news);
|
|
})
|
|
.Fail(() => deferred.Reject());
|
|
|
|
return deferred.Promise;*/
|
|
}
|
|
}
|
|
}
|