Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 26 additions & 33 deletions Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
using R6Sharp;
using R6Sharp.Endpoint;
using R6DataAccess.Interfaces;
using R6DataAccess.Models;
using R6Sharp;
using R6Sharp.Response;
using R6Sharp.Response.Static;
using R6Sharp.Response.Statistic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Example
{
public static class Program
{
internal class Credential

public static void Main()
{
[JsonPropertyName("email")]
public string Email { get; set; }


[JsonPropertyName("password")]
public string Password { get; set; }
}
var api = new R6Api(new Auth ("email", "password", false));

public static void Main()
{
Console.OutputEncoding = Encoding.UTF8;
// credentials.json = {"email": "email@email.com", "password": "somepassword"}
var json = File.ReadAllText(@"credentials.json");
var credentials = JsonSerializer.Deserialize<Credential>(json);
var api = new R6Api(credentials.Email, credentials.Password);

var guids = new[]
{
Expand All @@ -41,28 +31,30 @@ public static void Main()
};

#region Player Data
var username = "Pseudosin";
var platform = Platform.Uplay;
var username = Guid.Parse("0a32319d-f7de-4ec1-a845-25ee53f978a7");
IPlatform platform = Platform.UPLAY;
var region = Region.EMEA;

Profile profile = api.Profile.GetProfileAsync(username, platform).Result;
IProfile profile = api.Profile.GetProfileAsync(username, platform).Result;

// var profile = api.GetProfileAsync(guids, platform).Result;
Console.WriteLine($"Profile ID: {profile.UserId}");

PlayerProgression progression = api.PlayerProgression.GetPlayerProgressionAsync(profile.ProfileId, platform).Result;
IPlayerProgression progression = api.PlayerProgression.GetPlayerProgressionAsync(profile.ProfileId, platform).Result;
Console.WriteLine($"Level: {progression.Level}");

Dictionary<string, BoardInfo> ranked = api.Player.GetRankedAsync(profile.ProfileId, platform, region).Result;
Console.WriteLine($"Ranked Rank: {ranked[progression.ProfileId.ToString()].Rank}");

Dictionary<string, BoardInfo> casual = api.Player.GetCasualAsync(profile.ProfileId, platform, region).Result;
Console.WriteLine($"Casual Rank: {casual[progression.ProfileId.ToString()].Rank}");
IBoardInfo ranked = api.Player.GetRankedAsync(profile.ProfileId, platform, region).Result;
Console.WriteLine($"Ranked Rank: {ranked.Rank}");

IBoardInfo casual = api.Player.GetCasualAsync(profile.ProfileId, platform, region).Result;
Console.WriteLine($"Casual Rank: {casual.Rank}");

EquipmentStatistic equipments = api.Statistic.GetEquipmentStatistics(profile.ProfileId, Platform.Uplay).Result;
GamemodeStatistic gamemodes = api.Statistic.GetGamemodeStatistics(profile.ProfileId, Platform.Uplay).Result;
OperatorStatistic operators = api.Statistic.GetOperatorStatistics(profile.ProfileId, Platform.Uplay).Result;
QueueStatistic queues = api.Statistic.GetQueueStatistics(profile.ProfileId, Platform.Uplay).Result;
TerroristHuntMissionStatistic terroristhuntmissions = api.Statistic.GetTerroristHuntMissionsStatistics(profile.ProfileId, Platform.Uplay).Result;
IEquipmentStatistic equipments = api.Statistic.GetEquipmentStatistics(profile.ProfileId, platform).Result;
IGamemodeStatistic gamemodes = api.Statistic.GetGamemodeStatistics(profile.ProfileId, platform).Result;
IOperatorStatistic operators = api.Statistic.GetOperatorStatistics(profile.ProfileId, platform).Result;
IQueueStatistic queues = api.Statistic.GetQueueStatistics(profile.ProfileId, platform).Result;
ITerroristHuntMissionStatistic terroristhuntmissions = api.Statistic.GetTerroristHuntMissionsStatistics(profile.ProfileId, platform).Result;
#endregion

#region Static Data
Expand All @@ -73,8 +65,8 @@ public static void Main()
// Season season = Season.GetSeasonAsync().Result;
Console.WriteLine($"Current Season: {season.Id}");

Dictionary<string, string> locales = api.Static.GetLocaleAsync(Language.BritishEnglish).Result;
List<SeasonDetail> seasonDetails = api.Static.GetSeasonDetailsAsync().Result;
var locales = api.Static.GetLocaleAsync(LanguageEndPoint.BritishEnglish).Result;
var seasonDetails = api.Static.GetSeasonDetailsAsync().Result;

var seasonId = 18;
// Find season details for season 18
Expand All @@ -87,5 +79,6 @@ public static void Main()
Console.WriteLine($"Highest Rank URL: {highestSeasonRank.Images.Hd}");
#endregion
}

}
}
138 changes: 138 additions & 0 deletions R6DataAccess/Builder/BuildHelper/BuildHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using R6DataAccess.Interfaces;
using R6DataAccess.Models;
using R6Sharp;
using R6Sharp.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace R6DataAccess.Builder.BuildHelper
{
public class BuildHelper
{

// may need to be broken down into seperate methods overloaded



public static IQuery BuildProfileQuery(string player, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.NameOnPlatform(player)
.PlatformType(platform)
.Build()
;

return query;
}


public static IQuery BuildProfileQuery(string[] player, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.NameOnPlatform(player)
.PlatformType(platform)
.Build()
;

return query;
}

public static IQuery BuildProfileQuery(Guid uuid, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.IdOnPlatform(uuid)
.PlatformType(platform)
.Build()
;

return query;
}
public static IQuery BuildProfileQuery(Guid[] uuid, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.IdOnPlatform(uuid)
.PlatformType(platform)
.Build()
;

return query;
}

public static IQuery BuildPlayerProgressQuery(Guid[] uuid, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.ProfileId(uuid)
.PlatformType(platform)
.Build()
;

return query;
}


public static IQuery BuildPlayerProgressQuery(Guid uuid, IPlatform platform)
{
IQuery query = Factory.GetQueryBuilder()
.ProfileId(uuid)
.PlatformType(platform)
.Build()
;

return query;
}

public static IQuery BuildPlayersQuery(Guid[] uuids, IPlatform platform, IRegion region, string boardId, string season= null)
{
IQuery query = Factory.GetQueryBuilder()
.ProfileId(uuids)
.BoardId(boardId)
.Region(region)
.SeasonId(season)
.PlatformType(platform)
.Build()
;

return query;
}
public static IQuery BuildPlayersQuery(Guid uuids, IPlatform platform, IRegion region, string boardId, string season = null)
{
IQuery query = Factory.GetQueryBuilder()
.ProfileId(uuids)
.BoardId(boardId)
.Region(region)
.SeasonId(season)
.PlatformType(platform)
.Build()
;

return query;
}


public static IQuery BuildStatisticQuery(Guid uuids, IPlatform platform, string statistics)
{
IQuery query = Factory.GetQueryBuilder()
.PlatformType(platform)
.Population(uuids)
.Statistics(statistics)
.Build();


return query;
}
public static IQuery BuildStatisticQuery(Guid[] uuids, IPlatform platform, string statistics)
{
IQuery query = Factory.GetQueryBuilder()
.PlatformType(platform)
.Population(uuids)
.Statistics(statistics)
.Build();


return query;
}


}
}
140 changes: 140 additions & 0 deletions R6DataAccess/Builder/BuildHelper/QueryHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using R6Sharp.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Text.Json.Serialization;
using R6DataAccess.Interfaces;
using R6DataAccess.Models;

namespace R6DataAccess.Builder.BuildHelper
{
public static class QueryHelper
{

private static IQuery _query;
private static IEndPoints _endPoints;

// this could go into queryBuilder
public static string GetQueryString(IQuery query, IEndPoints endPoints)
{

_query = query;
_endPoints = endPoints;



var queryString = "";

foreach(var property in query.GetType().GetProperties())
{

var propValue = property.GetValue(query);




if (propValue != null)
{
var type = property.PropertyType;





var propertyName = GetJsonPropertyValue(property);
var propertyValue = GetPropertyValue(type, propValue);

if (propertyValue != null)
{

queryString += $"{propertyName}={propertyValue}&";
}


}

}


return cleanUpQueryString(queryString);
}



// as properties get bigger made this method to remove last char as supposed to
private static string cleanUpQueryString(string query)
{

var lengthOfQuery = query.Length;

var lastIndex = lengthOfQuery - 1;

char lastCharInQuery = query[lastIndex];

if (lastCharInQuery.Equals('&'))
{
return query.Remove(lastIndex);
}




return query;
}




private static string GetJsonPropertyValue(PropertyInfo property)
{

var jsonPropertyArray = property.GetCustomAttributes(typeof(JsonPropertyNameAttribute), true);

//get first array
var firstAttributes = (JsonPropertyNameAttribute)jsonPropertyArray[0];

return firstAttributes.Name;
}

private static string GetPropertyValue(Type type, object propertyValue)
{
string propStringValue;
// would need refactoring if there are any other way

/// would need to change it so object are casted at run time
/// should be able to rewrite later on
///
if (type == typeof(IPlatform))
{
//endpoint doesnt need the platform values

if (!_endPoints.Name.Equals(EndPoints.Statistics.Name))
{
var platform = (IPlatform)propertyValue;

propStringValue = platform.Name;
}
else
{

return null;
}
}
else if (type == typeof(IRegion))
{
var platform = (IRegion)propertyValue;

propStringValue = platform.Name;
}
else
{

propStringValue = propertyValue.ToString();
}


return propStringValue;
}
}
}
Loading