-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using NUnit.Framework; | ||
using XboxWebApi.Common; | ||
using XboxWebApi.Extensions; | ||
using XboxWebApi.Services.Model; | ||
|
||
namespace XboxWebApi.UnitTests.Api | ||
{ | ||
[TestFixture] | ||
public class TestProfileModels : TestDataProvider | ||
{ | ||
public TestProfileModels() | ||
: base("ApiProfile") | ||
{ | ||
} | ||
|
||
[Test] | ||
public void CreateProfileRequestQuery() | ||
{ | ||
ProfileRequestQuery query = new ProfileRequestQuery(new ProfileSetting[] | ||
{ | ||
ProfileSetting.AccountTier, | ||
ProfileSetting.GameDisplayName, | ||
ProfileSetting.PublicGamerpic | ||
}); | ||
NameValueCollection nv = query.GetQuery(); | ||
|
||
Assert.IsNotEmpty(nv); | ||
Assert.AreEqual(1, nv.Count); | ||
Assert.AreEqual("AccountTier,GameDisplayName,PublicGamerpic", nv["settings"]); | ||
} | ||
|
||
[Test] | ||
public void DeserializeProfileResponse() | ||
{ | ||
string json = TestData["ProfileResponse.json"]; | ||
ProfileResponse response = NewtonsoftJsonSerializer | ||
.Create(JsonNamingStrategy.CamelCase) | ||
.Deserialize<ProfileResponse>(json); | ||
|
||
Assert.IsInstanceOf(typeof(IStringable), response); | ||
|
||
Assert.IsNotNull(response.ProfileUsers); | ||
Assert.IsNotEmpty(response.ProfileUsers); | ||
Assert.AreEqual(1, response.ProfileUsers.Length); | ||
|
||
Assert.AreEqual(2580478784034343, response.ProfileUsers[0].Id); | ||
Assert.AreEqual(2580478784034343, response.ProfileUsers[0].HostId); | ||
Assert.IsFalse(response.ProfileUsers[0].IsSponsoredUser); | ||
Assert.IsNotNull(response.ProfileUsers[0].Settings); | ||
Assert.IsNotEmpty(response.ProfileUsers[0].Settings); | ||
Assert.AreEqual(6, response.ProfileUsers[0].Settings.Length); | ||
|
||
Assert.AreEqual(ProfileSetting.AppDisplayName, response.ProfileUsers[0].Settings[0].Id); | ||
Assert.AreEqual("Some Gamertag", response.ProfileUsers[0].Settings[0].Value); | ||
Assert.AreEqual(ProfileSetting.Gamerscore, response.ProfileUsers[0].Settings[1].Id); | ||
Assert.AreEqual("1337000", response.ProfileUsers[0].Settings[1].Value); | ||
Assert.AreEqual(ProfileSetting.Gamertag, response.ProfileUsers[0].Settings[2].Id); | ||
Assert.AreEqual("Some Gamertag", response.ProfileUsers[0].Settings[2].Value); | ||
Assert.AreEqual(ProfileSetting.PublicGamerpic, response.ProfileUsers[0].Settings[3].Id); | ||
Assert.AreEqual("http://images-eds.xboxlive.com/image?url=abcdef", | ||
response.ProfileUsers[0].Settings[3].Value); | ||
Assert.AreEqual(ProfileSetting.XboxOneRep, response.ProfileUsers[0].Settings[4].Id); | ||
Assert.AreEqual("Superstar", response.ProfileUsers[0].Settings[4].Value); | ||
Assert.AreEqual(ProfileSetting.RealName, response.ProfileUsers[0].Settings[5].Id); | ||
Assert.AreEqual("John Doe", response.ProfileUsers[0].Settings[5].Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"profileUsers": [ | ||
{ | ||
"id": "2580478784034343", | ||
"hostId": "2580478784034343", | ||
"settings": [ | ||
{ | ||
"id": "AppDisplayName", | ||
"value": "Some Gamertag" | ||
}, | ||
{ | ||
"id": "Gamerscore", | ||
"value": "1337000" | ||
}, | ||
{ | ||
"id": "Gamertag", | ||
"value": "Some Gamertag" | ||
}, | ||
{ | ||
"id": "PublicGamerpic", | ||
"value": "http://images-eds.xboxlive.com/image?url=abcdef" | ||
}, | ||
{ | ||
"id": "XboxOneRep", | ||
"value": "Superstar" | ||
}, | ||
{ | ||
"id": "RealName", | ||
"value": "John Doe" | ||
} | ||
], | ||
"isSponsoredUser": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using RestSharp; | ||
using XboxWebApi.Common; | ||
using XboxWebApi.Extensions; | ||
using XboxWebApi.Services.Model; | ||
|
||
namespace XboxWebApi.Services.Api | ||
{ | ||
public class ProfileService : XblService | ||
{ | ||
public ProfileService(XblConfiguration config) | ||
: base(config, "https://profile.xboxlive.com") | ||
{ | ||
Headers = new NameValueCollection() | ||
{ | ||
{"x-xbl-contract-version", "2"} | ||
}; | ||
} | ||
|
||
public ProfileResponse GetProfilesBatch(ulong[] xuids, ProfileSetting[] settings = null) | ||
{ | ||
RestRequestEx request = new RestRequestEx("users/batch/profile/settings", | ||
Method.POST); | ||
ProfileSetting[] profileSettings = settings != null ? settings : new ProfileSetting[] | ||
{ | ||
ProfileSetting.AppDisplayName, ProfileSetting.Gamerscore, | ||
ProfileSetting.Gamertag, ProfileSetting.PublicGamerpic, | ||
ProfileSetting.XboxOneRep, ProfileSetting.RealName | ||
}; | ||
ProfilesRequest body = new ProfilesRequest(xuids, profileSettings); | ||
request.AddHeaders(Headers); | ||
request.AddJsonBody(body, JsonNamingStrategy.CamelCase); | ||
IRestResponse<ProfileResponse> response = Client(JsonNamingStrategy.CamelCase) | ||
.Execute<ProfileResponse>(request); | ||
return response.Data; | ||
} | ||
|
||
private ProfileResponse _GetProfile(string resource, ProfileSetting[] settings = null) | ||
{ | ||
RestRequestEx request = new RestRequestEx(resource, Method.GET); | ||
ProfileSetting[] profileSettings = settings != null ? settings : new ProfileSetting[] | ||
{ | ||
ProfileSetting.AppDisplayName, ProfileSetting.Gamerscore, | ||
ProfileSetting.Gamertag, ProfileSetting.PublicGamerpic, | ||
ProfileSetting.XboxOneRep, ProfileSetting.RealName | ||
}; | ||
ProfileRequestQuery query = new ProfileRequestQuery(profileSettings); | ||
request.AddHeaders(Headers); | ||
request.AddQueryParameters(query.GetQuery()); | ||
IRestResponse<ProfileResponse> response = Client(JsonNamingStrategy.CamelCase) | ||
.Execute<ProfileResponse>(request); | ||
return response.Data; | ||
} | ||
|
||
public ProfileResponse GetProfile(ulong xuid, ProfileSetting[] settings = null) | ||
{ | ||
return _GetProfile($"users/xuid({xuid})/profile/settings", settings); | ||
} | ||
|
||
public ProfileResponse GetProfile(string gamertag, ProfileSetting[] settings = null) | ||
{ | ||
return _GetProfile($"users/gt({gamertag})/profile/settings", settings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using XboxWebApi.Extensions; | ||
|
||
namespace XboxWebApi.Services.Model | ||
{ | ||
public class ProfileRequestQuery | ||
{ | ||
public ProfileSetting[] Settings; | ||
|
||
public ProfileRequestQuery(ProfileSetting[] settings) | ||
{ | ||
Settings = settings; | ||
} | ||
|
||
public NameValueCollection GetQuery() | ||
{ | ||
return new NameValueCollection() | ||
{ | ||
{"settings", String.Join(",", Array.ConvertAll(Settings, x => x.ToString()))} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using XboxWebApi.Extensions; | ||
|
||
namespace XboxWebApi.Services.Model | ||
{ | ||
public class ProfileSettingElement : IStringable | ||
{ | ||
public ProfileSetting Id; | ||
public string Value; | ||
} | ||
|
||
public class ProfileUser : IStringable | ||
{ | ||
public ulong Id; | ||
public ulong HostId; | ||
public ProfileSettingElement[] Settings; | ||
public bool IsSponsoredUser; | ||
} | ||
|
||
public class ProfileResponse : IStringable | ||
{ | ||
public ProfileUser[] ProfileUsers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using XboxWebApi.Common; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace XboxWebApi.Services.Model | ||
{ | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum ProfileSetting | ||
{ | ||
GameDisplayName, | ||
AppDisplayName, | ||
AppDisplayPicRaw, | ||
GameDisplayPicRaw, | ||
PublicGamerpic, | ||
ShowUserAsAvatar, | ||
Gamerscore, | ||
Gamertag, | ||
AccountTier, | ||
TenureLevel, | ||
XboxOneRep, | ||
PreferredColor, | ||
Location, | ||
Bio, | ||
Watermarks, | ||
RealName, | ||
RealNameOverride | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using XboxWebApi.Extensions; | ||
|
||
using XboxWebApi.Common; | ||
|
||
namespace XboxWebApi.Services.Model | ||
{ | ||
public class ProfilesRequest | ||
{ | ||
public ulong[] UserIds; | ||
public ProfileSetting[] Settings; | ||
|
||
public ProfilesRequest(ulong[] xuids, ProfileSetting[] settings) | ||
{ | ||
UserIds = xuids; | ||
Settings = settings; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters