Skip to content

Commit

Permalink
update for API v2.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Cytraen committed Dec 3, 2021
1 parent 96b92a6 commit 8f239d6
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 70 deletions.
6 changes: 6 additions & 0 deletions BungieSharper.Entities/Common/Entities.Common.Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public class Destiny2CoreSettings
[JsonPropertyName("currentRankProgressionHashes")]
public IEnumerable<uint> CurrentRankProgressionHashes { get; set; }

[JsonPropertyName("insertPlugFreeProtectedPlugItemHashes")]
public IEnumerable<uint> InsertPlugFreeProtectedPlugItemHashes { get; set; }

[JsonPropertyName("insertPlugFreeBlockedSocketTypeHashes")]
public IEnumerable<uint> InsertPlugFreeBlockedSocketTypeHashes { get; set; }

[JsonPropertyName("undiscoveredCollectibleImage")]
public string UndiscoveredCollectibleImage { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public enum DestinyActivityModeType : int
Momentum = 81,
Dungeon = 82,
Sundial = 83,
TrialsOfOsiris = 84
TrialsOfOsiris = 84,
Dares = 85
}

public class DestinyHistoricalStatsDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DestinyCharacterActionRequest

public class DestinyItemActionRequest
{
/// <summary>The instance ID of the item for this action request.</summary>
[JsonPropertyName("itemId")]
public long ItemId { get; set; }

Expand All @@ -38,6 +39,7 @@ public class DestinyPostmasterTransferRequest
[JsonPropertyName("stackSize")]
public int StackSize { get; set; }

/// <summary>The instance ID of the item for this action request.</summary>
[JsonPropertyName("itemId")]
public long ItemId { get; set; }

Expand Down Expand Up @@ -65,6 +67,7 @@ public class DestinyItemStateRequest
[JsonPropertyName("state")]
public bool State { get; set; }

/// <summary>The instance ID of the item for this action request.</summary>
[JsonPropertyName("itemId")]
public long ItemId { get; set; }

Expand Down Expand Up @@ -127,4 +130,21 @@ public enum DestinySocketArrayType : int
Default = 0,
Intrinsic = 1
}

public class DestinyInsertPlugsFreeActionRequest
{
/// <summary>The plugs being inserted.</summary>
[JsonPropertyName("plug")]
public Destiny.Requests.Actions.DestinyInsertPlugsRequestEntry Plug { get; set; }

/// <summary>The instance ID of the item for this action request.</summary>
[JsonPropertyName("itemId")]
public long ItemId { get; set; }

[JsonPropertyName("characterId")]
public long CharacterId { get; set; }

[JsonPropertyName("membershipType")]
public BungieMembershipType MembershipType { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class DestinyItemTransferRequest
[JsonPropertyName("transferToVault")]
public bool TransferToVault { get; set; }

/// <summary>The instance ID of the item for this action request.</summary>
[JsonPropertyName("itemId")]
public long ItemId { get; set; }

Expand Down
14 changes: 11 additions & 3 deletions BungieSharper.Entities/Destiny/Entities.Destiny.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ public enum DestinyVendorProgressionType : int
Default = 0,

/// <summary>Progression from ranks in ritual content. For example: Crucible (Shaxx), Gambit (Drifter), and Season 13 Battlegrounds (War Table).</summary>
Ritual = 1
Ritual = 1,

/// <summary>A vendor progression with no seasonal refresh. For example: Xur in the Eternity destination for the 30th Anniversary.</summary>
NoSeasonalRefresh = 2
}

/// <summary>
Expand Down Expand Up @@ -857,7 +860,9 @@ public enum DestinyGameVersions : int
Forsaken = 8,
YearTwoAnnualPass = 16,
Shadowkeep = 32,
BeyondLight = 64
BeyondLight = 64,
Anniversary30th = 128,
TheWitchQueen = 256
}

/// <summary>
Expand Down Expand Up @@ -1433,7 +1438,10 @@ public enum DestinyVendorItemState : int
BestDeal = 32768,

/// <summary>This indicates that the sale item is popular.</summary>
Popular = 65536
Popular = 65536,

/// <summary>This indicates that the sale item is free.</summary>
Free = 131072
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion BungieSharper.Entities/Exceptions/Entities.Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public enum PlatformErrorCodes : int
IgnoreNotFound = 1007,
IgnoreUserGloballyIgnored = 1008,
IgnoreUserIgnored = 1009,
TargetUserIgnored = 1010,
NotificationSettingInvalid = 1100,
PsnApiExpiredAccessToken = 1204,
PSNExForbidden = 1205,
Expand Down Expand Up @@ -808,6 +809,10 @@ public enum PlatformErrorCodes : int
ErrorBungieFriendsAlreadyFriends = 3903,
ErrorBungieFriendsUnableToRemoveRequest = 3904,
ErrorBungieFriendsUnableToRemove = 3905,
ErrorBungieFriendsIdenticalSourceTarget = 3906
ErrorBungieFriendsIdenticalSourceTarget = 3906,
ErrorBungieFriendsSelf = 3907,
ErrorBungieBlockSelf = 3908,
ErrorBungieFriendsListFull = 3910,
ErrorBungieBlockListFull = 3911
}
}
15 changes: 15 additions & 0 deletions BungieSharper.Entities/User/Entities.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ public class UserSearchResponseDetail
public IEnumerable<User.UserInfoCard> DestinyMemberships { get; set; }
}

public class UserSearchPrefixRequest
{
[JsonPropertyName("displayNamePrefix")]
public string DisplayNamePrefix { get; set; }
}

public class ExactSearchRequest
{
[JsonPropertyName("displayName")]
public string DisplayName { get; set; }

[JsonPropertyName("displayNameCode")]
public short DisplayNameCode { get; set; }
}

/// <summary>
/// The set of all email subscription/opt-in settings and definitions.
/// </summary>
Expand Down
63 changes: 4 additions & 59 deletions BungieSharper.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using BungieSharper.Entities;
using BungieSharper.Entities.Destiny.Definitions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -19,22 +15,22 @@ public BaseTests(TestClientFixture clientFixture)
}

[Fact]
public async Task GetManifestTask()
public async Task GetManifestTest()
{
var manifestData = await ClientFixture.TestClient.Api.Destiny2_GetDestinyManifest();
Assert.False(string.IsNullOrEmpty(manifestData.Version));
}

[Fact]
public async Task SearchUserTest_Steam()
public async Task PostUserSearchTest()
{
const BungieMembershipType expectedMembershipType = BungieMembershipType.TigerSteam;
const long expectedMembershipId = 4611686018467948914;
const string expectedDisplayName = "Cytraen";
const short expectedDisplayNameCode = 2213;

var actualCards = (await ClientFixture.TestClient.Api.Destiny2_SearchDestinyPlayer(
$"{expectedDisplayName}#{expectedDisplayNameCode}", BungieMembershipType.All
var actualCards = (await ClientFixture.TestClient.Api.Destiny2_SearchDestinyPlayerByBungieName(
BungieMembershipType.All, new Entities.User.ExactSearchRequest { DisplayName = expectedDisplayName, DisplayNameCode = expectedDisplayNameCode }
)).ToList();

Assert.Equal(4, actualCards.Count);
Expand All @@ -47,56 +43,5 @@ public async Task SearchUserTest_Steam()
Assert.Equal(expectedDisplayName, userCard.BungieGlobalDisplayName);
Assert.Equal(expectedDisplayNameCode, userCard.BungieGlobalDisplayNameCode);
}

[Fact]
public async Task DownloadStringAndDeserialize()
{
const string expectedName = "Midnight Coup";
const string expectedFlavorText =
"The conspirators were too afraid to kill me—rightly so. " +
"I am the beloved father of the people, and the glorious mob would not suffer my death. " +
"My sentence was exile.";
const uint expectedDamageTypeHash = 3373582085;

var manifestData = await ClientFixture.TestClient.Api.Destiny2_GetDestinyManifest();
var str = await ClientFixture.TestClient.DownloadString(
manifestData.JsonWorldComponentContentPaths["en"]["DestinyInventoryItemDefinition"]
);
var inventoryItems = JsonSerializer.Deserialize<Dictionary<uint, DestinyInventoryItemDefinition>>(str);
var item = inventoryItems[1128225405];

Assert.Equal(expectedName, item.DisplayProperties.Name);
Assert.Equal(expectedFlavorText, item.FlavorText);
Assert.Equal(expectedDamageTypeHash, item.DefaultDamageTypeHash);
}

[Fact]
public async Task DownloadFileAndDeserialize()
{
const string fileName = "inventoryItems.json";
const string expectedName = "Midnight Coup";
const string expectedFlavorText =
"The conspirators were too afraid to kill me—rightly so. " +
"I am the beloved father of the people, and the glorious mob would not suffer my death. " +
"My sentence was exile.";
const uint expectedDamageTypeHash = 3373582085;

var manifestData = await ClientFixture.TestClient.Api.Destiny2_GetDestinyManifest();

await using var fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
await ClientFixture.TestClient.DownloadFile(
manifestData.JsonWorldComponentContentPaths["en"]["DestinyInventoryItemDefinition"], fileStream
);
fileStream.Close();

var fileText = await File.ReadAllTextAsync(fileName);

var inventoryItems = JsonSerializer.Deserialize<Dictionary<uint, DestinyInventoryItemDefinition>>(fileText);
var item = inventoryItems[1128225405];

Assert.Equal(expectedName, item.DisplayProperties.Name);
Assert.Equal(expectedFlavorText, item.FlavorText);
Assert.Equal(expectedDamageTypeHash, item.DefaultDamageTypeHash);
}
}
}
2 changes: 1 addition & 1 deletion BungieSharper.Tests/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public TestClientFixture()
{
ApiKey = Environment.GetEnvironmentVariable("TEST_BUNGIE_API_KEY") ?? throw new NullReferenceException(),
UserAgent = $"BungieSharper.Tests/{typeof(TestClientFixture).Assembly.GetName().Version!.ToString(3)} (+github.com/ashakoor/BungieSharper)",
RateLimit = 50
RateLimit = 10
};

TestClient = new BungieApiClient(config);
Expand Down
21 changes: 17 additions & 4 deletions BungieSharper/Endpoints/Destiny2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ public partial class Endpoints
/// <summary>
/// Returns a list of Destiny memberships given a global Bungie Display Name. This method will hide overridden memberships due to cross save.
/// </summary>
/// <param name="displayName">The full bungie global display name to look up, include the # and the code at the end. This is an exact match lookup.</param>
/// <param name="membershipType">A valid non-BungieNet membership type, or All. Indicates which memberships to return. You probably want this set to All.</param>
/// <param name="authToken">The OAuth access token to autheticate the request with.</param>
/// <param name="cancelToken">The <see cref="CancellationToken" /> to observe.</param>
public Task<IEnumerable<Entities.User.UserInfoCard>> Destiny2_SearchDestinyPlayer(string displayName, Entities.BungieMembershipType membershipType, string? authToken = null, CancellationToken cancelToken = default)
public Task<IEnumerable<Entities.User.UserInfoCard>> Destiny2_SearchDestinyPlayerByBungieName(Entities.BungieMembershipType membershipType, Entities.User.ExactSearchRequest requestBody, string? authToken = null, CancellationToken cancelToken = default)
{
return _apiAccessor.ApiRequestAsync<IEnumerable<Entities.User.UserInfoCard>>(
new Uri($"Destiny2/SearchDestinyPlayer/{membershipType}/{Uri.EscapeDataString(displayName)}/", UriKind.Relative),
null, HttpMethod.Get, authToken, cancelToken
new Uri($"Destiny2/SearchDestinyPlayerByBungieName/{membershipType}/", UriKind.Relative),
new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json"), HttpMethod.Post, authToken, cancelToken
);
}

Expand Down Expand Up @@ -313,6 +312,20 @@ public Task<int> Destiny2_SetQuestTrackedState(Entities.Destiny.Requests.Actions
);
}

/// <summary>
/// Insert a 'free' plug into an item's socket. This does not require 'Advanced Write Action' authorization and is available to 3rd-party apps, but will only work on 'free and reversible' socket actions (Perks, Armor Mods, Shaders, Ornaments, etc.). You must have a valid Destiny Account, and the character must either be in a social space, in orbit, or offline.
/// Requires OAuth2 scope(s): MoveEquipDestinyItems
/// </summary>
/// <param name="authToken">The OAuth access token to autheticate the request with.</param>
/// <param name="cancelToken">The <see cref="CancellationToken" /> to observe.</param>
public Task<Entities.Destiny.Responses.DestinyItemChangeResponse> Destiny2_InsertSocketPlugFree(Entities.Destiny.Requests.Actions.DestinyInsertPlugsFreeActionRequest requestBody, string? authToken = null, CancellationToken cancelToken = default)
{
return _apiAccessor.ApiRequestAsync<Entities.Destiny.Responses.DestinyItemChangeResponse>(
new Uri($"Destiny2/Actions/Items/InsertSocketPlugFree/", UriKind.Relative),
new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json"), HttpMethod.Post, authToken, cancelToken
);
}

/// <summary>
/// Gets the available post game carnage report for the activity ID.
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion BungieSharper/Endpoints/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -95,7 +96,7 @@ public partial class Endpoints
}

/// <summary>
/// Given the prefix of a global display name, returns all users who share that name.
/// [OBSOLETE] Do not use this to search users, use SearchByGlobalNamePost instead.
/// </summary>
/// <param name="displayNamePrefix">The display name prefix you're looking for.</param>
/// <param name="page">The zero-based page of results you desire.</param>
Expand All @@ -108,5 +109,19 @@ public partial class Endpoints
null, HttpMethod.Get, authToken, cancelToken
);
}

/// <summary>
/// Given the prefix of a global display name, returns all users who share that name.
/// </summary>
/// <param name="page">The zero-based page of results you desire.</param>
/// <param name="authToken">The OAuth access token to autheticate the request with.</param>
/// <param name="cancelToken">The <see cref="CancellationToken" /> to observe.</param>
public Task<Entities.User.UserSearchResponse> User_SearchByGlobalNamePost(int page, Entities.User.UserSearchPrefixRequest requestBody, string? authToken = null, CancellationToken cancelToken = default)
{
return _apiAccessor.ApiRequestAsync<Entities.User.UserSearchResponse>(
new Uri($"User/Search/GlobalName/{page}/", UriKind.Relative),
new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json"), HttpMethod.Post, authToken, cancelToken
);
}
}
}

0 comments on commit 8f239d6

Please sign in to comment.