public async Task <List <PandoraStation> > GetPandoraStationsAsync(PandoraConfig config, RESTfulService service, PandoraState pandoraState) { CryptoConfig cryptoConfig = PandoraConstants.GetCryptoConfig(); HttpResponseMessage response = await DoStandardCallAsync(service, "user.getStationList", new Dictionary <string, object>(), false, pandoraState, cryptoConfig); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); PandoraStationListDto stationList = JsonConvert.DeserializeObject <PandoraStationListDto>(await response.Content.ReadAsStringAsync()); List <PandoraStation> stations = new List <PandoraStation>(); foreach (PandoraStationDto station in stationList.Result.Stations) { stations.Add(new PandoraStation { Id = station.StationId, Token = station.StationToken, IsQuickMix = station.IsQuickMix, Name = station.StationName }); } stations.Sort((station1, station2) => string.Compare(station1.Name, station2.Name)); return(await Task.FromResult(stations)); }
public async Task <bool> LoginAsync(PandoraConfig config, RESTfulService service, PandoraState pandoraState) { Dictionary <string, object> data = new Dictionary <string, object> { { "loginType", "user" }, { "username", config.Username }, { "password", config.Password }, { "partnerAuthToken", pandoraState.PartnerAuthToken }, { "syncTime", pandoraState.SyncTime } }; CryptoConfig cryptoConfig = PandoraConstants.GetCryptoConfig(); Crypto crypto = new Crypto(); HttpResponseMessage response = await service.DoPost(PandoraConstants.BuildUrl($"method=auth.userLogin&auth_token={HttpUtility.UrlEncode(pandoraState.PartnerAuthToken)}&partner_id={pandoraState.PartnerId}"), data, cryptoConfig); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); PartnerLoginStatusDto loginData = JsonConvert.DeserializeObject <PartnerLoginStatusDto>(await response.Content.ReadAsStringAsync(), serializerSettings); if (loginData.Stat == "ok") { pandoraState.UserAuthToken = loginData.Result.UserAuthToken; pandoraState.UserId = loginData.Result.UserId; return(await Task.FromResult(true)); } return(await Task.FromResult(false)); }