예제 #1
0
        public async ValueTask <BungieResponse <GroupMemberLeaveResult> > KickMember(
            AuthorizationTokenData authData,
            long groupId,
            long membershipId,
            BungieMembershipType membershipType,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes
                .HasFlag(ApplicationScopes.AdminGroups))
            {
                throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
            }

            var url = StringBuilderPool.GetBuilder(token)
                      .Append("/GroupV2/")
                      .AddUrlParam(groupId.ToString())
                      .Append("Members/")
                      .AddUrlParam(((int)membershipType).ToString())
                      .AddUrlParam(membershipId.ToString())
                      .Append("Kick/")
                      .Build();

            return(await _httpClient.PostToBungieNetPlatform <GroupMemberLeaveResult>(url, token,
                                                                                      authToken : authData.AccessToken));
        }
예제 #2
0
 internal UserScopedContentMethodsAccess(
     IContentMethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
 internal UsedScopedForumMethodsAccess(
     IForumMethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
예제 #4
0
    public async ValueTask <BungieResponse <PartnerOfferSkuHistoryResponse[]> > GetPartnerOfferSkuHistory(
        AuthorizationTokenData authorizationToken,
        int partnerApplicationId,
        long targetBnetMembershipId,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.PartnerOfferGrant))
        {
            throw new InsufficientScopeException(ApplicationScopes.PartnerOfferGrant);
        }

        var url = StringBuilderPool
                  .GetBuilder(cancellationToken)
                  .Append("/Tokens/Partner/History/")
                  .AddUrlParam(partnerApplicationId.ToString())
                  .AddUrlParam(targetBnetMembershipId.ToString())
                  .Build();

        return(await _dotNetBungieApiHttpClient
               .GetFromBungieNetPlatform <PartnerOfferSkuHistoryResponse[]>(
                   url,
                   cancellationToken,
                   authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
예제 #5
0
    public static async IAsyncEnumerable <PlatformFriendResponse> GetPlatformFriendList(
        this ISocialMethodsAccess socialMethodsAccess,
        int maxPages,
        PlatformFriendType friendPlatform,
        AuthorizationTokenData authorizationToken,
        [EnumeratorCancellation] CancellationToken cancellationToken = default)
    {
        var currentPage  = 0;
        var hasMoreToGet = true;

        while (currentPage < maxPages && hasMoreToGet)
        {
            var response = await socialMethodsAccess.GetPlatformFriendList(
                friendPlatform,
                authorizationToken,
                currentPage,
                cancellationToken);

            if (!response.IsSuccessfulResponseCode || response.Response is null)
            {
                throw response.ToException();
            }

            hasMoreToGet = response.Response.HasMore;
            currentPage  = response.Response.CurrentPage + 1;
            yield return(response.Response);
        }
    }
 internal UserScopedFireteamMethodsAccess(
     IFireteamMethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
예제 #7
0
    public async ValueTask <BungieResponse <GroupApplicationResponse> > IndividualGroupInviteCancel(
        AuthorizationTokenData authorizationToken,
        long groupId,
        BungieMembershipType membershipType,
        long membershipId,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.AdminGroups))
        {
            throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
        }

        var url = StringBuilderPool.GetBuilder(cancellationToken)
                  .Append("/GroupV2/")
                  .AddUrlParam(groupId.ToString())
                  .Append("Members/IndividualInviteCancel/")
                  .AddUrlParam(((int)membershipType).ToString())
                  .AddUrlParam(membershipId.ToString())
                  .Build();

        return(await _dotNetBungieApiHttpClient
               .PostToBungieNetPlatform <GroupApplicationResponse>(url, cancellationToken,
                                                                   authToken : authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
    public async ValueTask <BungieResponse <SearchResultOfFireteamSummary> > SearchPublicAvailableClanFireteams(
        AuthorizationTokenData authorizationToken,
        FireteamPlatform platform,
        DestinyActivityModeType activityType,
        FireteamDateRange dateRange,
        FireteamSlotSearch slotFilter,
        int page          = 0,
        string langFilter = null,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.ReadGroups))
        {
            throw new InsufficientScopeException(ApplicationScopes.ReadGroups);
        }

        var url = StringBuilderPool
                  .GetBuilder(cancellationToken)
                  .Append("/Fireteam/Search/Available/")
                  .AddUrlParam(((byte)platform).ToString())
                  .AddUrlParam(((int)activityType).ToString())
                  .AddUrlParam(((byte)dateRange).ToString())
                  .AddUrlParam(((byte)slotFilter).ToString())
                  .AddUrlParam(page.ToString())
                  .AddQueryParam("langFilter", langFilter, () => !string.IsNullOrWhiteSpace(langFilter))
                  .Build();

        return(await _dotNetBungieApiHttpClient
               .GetFromBungieNetPlatform <SearchResultOfFireteamSummary>(url, cancellationToken,
                                                                         authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
예제 #9
0
    public async ValueTask <BungieResponse <int> > BanMember(
        AuthorizationTokenData authorizationToken,
        long groupId,
        long membershipId,
        BungieMembershipType membershipType,
        GroupBanRequest request,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.AdminGroups))
        {
            throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
        }

        var url = StringBuilderPool.GetBuilder(cancellationToken)
                  .Append("/GroupV2/")
                  .AddUrlParam(groupId.ToString())
                  .Append("Members/")
                  .AddUrlParam(((int)membershipType).ToString())
                  .AddUrlParam(membershipId.ToString())
                  .Append("Ban/")
                  .Build();

        var stream = new MemoryStream();
        await _serializer.SerializeAsync(stream, request);

        return(await _dotNetBungieApiHttpClient
               .PostToBungieNetPlatform <int>(url, cancellationToken, stream, authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
예제 #10
0
        public async ValueTask <BungieResponse <ApiUsage> > GetApplicationApiUsage(
            AuthorizationTokenData authToken,
            int applicationId,
            DateTime?start          = null,
            DateTime?end            = null,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes.HasFlag(
                    ApplicationScopes.ReadUserData))
            {
                throw new InsufficientScopeException(ApplicationScopes.ReadUserData);
            }
            if (start.HasValue && end.HasValue && (end.Value - start.Value).TotalHours > 48)
            {
                throw new Exception("Can't request more than 48 hours.");
            }
            end ??= DateTime.Now;
            start ??= end.Value.AddHours(-24);
            var url = StringBuilderPool
                      .GetBuilder(token)
                      .Append("/App/ApiUsage/")
                      .AddQueryParam("start",
                                     start.Value.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture))
                      .AddQueryParam("end",
                                     end.Value.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture))
                      .Build();

            return(await _httpClient.GetFromBungieNetPlatform <ApiUsage>(url, token, authToken.AccessToken));
        }
    public async ValueTask <BungieResponse <SearchResultOfFireteamSummary> > GetMyClanFireteams(
        AuthorizationTokenData authorizationToken,
        long groupId,
        FireteamPlatform platform,
        bool includeClosed,
        int page          = 0,
        string langFilter = null,
        bool groupFilter  = false,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.ReadGroups))
        {
            throw new InsufficientScopeException(ApplicationScopes.ReadGroups);
        }

        var url = StringBuilderPool
                  .GetBuilder(cancellationToken)
                  .Append("/Fireteam/Clan/")
                  .AddUrlParam(groupId.ToString())
                  .AddUrlParam(((byte)platform).ToString())
                  .Append("My/")
                  .AddUrlParam(includeClosed.ToString())
                  .AddUrlParam(page.ToString())
                  .AddQueryParam("langFilter", langFilter, () => !string.IsNullOrWhiteSpace(langFilter))
                  .AddQueryParam("groupFilter", groupFilter.ToString())
                  .Build();

        return(await _dotNetBungieApiHttpClient
               .GetFromBungieNetPlatform <SearchResultOfFireteamSummary>(url, cancellationToken,
                                                                         authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
        private async Task HandleTokenExpiration(AuthorizationTokenData token)
        {
            var newToken = await BungieClient.Platform.RenewAuthorizationToken(token);

            AuthorizationTokens[newToken.MembershipId] = newToken;
            _logger.Log($"Renewed token for membership: {token.MembershipId}", LogType.Info);
        }
예제 #13
0
        public async ValueTask <BungieResponse <SearchResultOfFireteamSummary> > GetAvailableClanFireteams(
            AuthorizationTokenData authData,
            long groupId,
            FireteamPlatform platform,
            DestinyActivityModeType activityType,
            FireteamDateRange dateRange,
            FireteamSlotSearch slotFilter,
            FireteamPublicSearchOption publicOnly,
            int page                = 0,
            string langFilter       = null,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes.HasFlag(ApplicationScopes.ReadGroups))
            {
                throw new InsufficientScopeException(ApplicationScopes.ReadGroups);
            }

            var url = StringBuilderPool
                      .GetBuilder(token)
                      .Append("/Fireteam/Clan/")
                      .AddUrlParam(groupId.ToString())
                      .Append("Available/")
                      .AddUrlParam(((byte)platform).ToString())
                      .AddUrlParam(((int)activityType).ToString())
                      .AddUrlParam(((byte)dateRange).ToString())
                      .AddUrlParam(((byte)slotFilter).ToString())
                      .AddUrlParam(((byte)publicOnly).ToString())
                      .AddUrlParam(page.ToString())
                      .AddQueryParam("langFilter", langFilter, () => !string.IsNullOrWhiteSpace(langFilter))
                      .Build();

            return(await _httpClient.GetFromBungieNetPlatform <SearchResultOfFireteamSummary>(url, token,
                                                                                              authData.AccessToken));
        }
예제 #14
0
        public async ValueTask <BungieResponse <GroupApplicationResponse> > IndividualGroupInvite(
            AuthorizationTokenData authData,
            long groupId,
            BungieMembershipType membershipType,
            long membershipId,
            GroupApplicationRequest request,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes
                .HasFlag(ApplicationScopes.AdminGroups))
            {
                throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
            }

            var url = StringBuilderPool.GetBuilder(token)
                      .Append("/GroupV2/")
                      .AddUrlParam(groupId.ToString())
                      .Append("Members/IndividualInvite/")
                      .AddUrlParam(((int)membershipType).ToString())
                      .AddUrlParam(membershipId.ToString())
                      .Build();

            var stream = new MemoryStream();
            await _serializationHelper.SerializeAsync(stream, request);

            return(await _httpClient.PostToBungieNetPlatform <GroupApplicationResponse>(url, token, stream,
                                                                                        authData.AccessToken));
        }
예제 #15
0
 internal UserScopedTrendingMethodsAccess(
     ITrendingMethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
예제 #16
0
    public async ValueTask <BungieResponse <EntityActionResult[]> > DenyPendingForList(
        AuthorizationTokenData authorizationToken,
        long groupId,
        GroupApplicationListRequest request,
        CancellationToken cancellationToken = default)
    {
        if (!_configuration.HasSufficientRights(ApplicationScopes.AdminGroups))
        {
            throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
        }

        var url = StringBuilderPool.GetBuilder(cancellationToken)
                  .Append("/GroupV2/")
                  .AddUrlParam(groupId.ToString())
                  .Append("Members/DenyList/")
                  .Build();

        var stream = new MemoryStream();
        await _serializer.SerializeAsync(stream, request);

        return(await _dotNetBungieApiHttpClient
               .PostToBungieNetPlatform <EntityActionResult[]>(url, cancellationToken, stream,
                                                               authorizationToken.AccessToken)
               .ConfigureAwait(false));
    }
예제 #17
0
 internal UserScopedSocialMethodsAccess(
     ISocialMethodsAccess socialMethodsAccess,
     AuthorizationTokenData token)
 {
     _socialMethodsAccess = socialMethodsAccess;
     _token = token;
 }
예제 #18
0
    public async ValueTask <BungieResponse <DestinyVendorResponse> > GetVendor(
        BungieMembershipType membershipType,
        long destinyMembershipId,
        long characterId,
        uint vendorHash,
        DestinyComponentType[] componentTypes,
        AuthorizationTokenData authorizationToken = null,
        CancellationToken cancellationToken       = default)
    {
        var url = StringBuilderPool
                  .GetBuilder(cancellationToken)
                  .Append("/Destiny2/")
                  .AddUrlParam(((int)membershipType).ToString())
                  .Append("Profile/")
                  .AddUrlParam(destinyMembershipId.ToString())
                  .Append("Character/")
                  .AddUrlParam(characterId.ToString())
                  .Append("Vendors/")
                  .AddUrlParam(vendorHash.ToString())
                  .AddQueryParam("components", componentTypes.ComponentsToIntString())
                  .Build();

        return(await _dotNetBungieApiHttpClient
               .GetFromBungieNetPlatform <DestinyVendorResponse>(url, cancellationToken,
                                                                 authorizationToken?.AccessToken)
               .ConfigureAwait(false));
    }
예제 #19
0
        public async ValueTask <BungieResponse <long> > EditOptionalConversation(
            AuthorizationTokenData authData,
            long groupId,
            long conversationId,
            GroupOptionalConversationEditRequest request,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes
                .HasFlag(ApplicationScopes.AdminGroups))
            {
                throw new InsufficientScopeException(ApplicationScopes.AdminGroups);
            }

            var url = StringBuilderPool.GetBuilder(token)
                      .Append("/GroupV2/")
                      .AddUrlParam(groupId.ToString())
                      .Append("OptionalConversations/Edit/")
                      .AddUrlParam(conversationId.ToString())
                      .Build();

            var stream = new MemoryStream();
            await _serializationHelper.SerializeAsync(stream, request);

            return(await _httpClient.PostToBungieNetPlatform <long>(url, token, stream, authData.AccessToken));
        }
예제 #20
0
        public async ValueTask <BungieResponse <DestinyCollectibleNodeDetailResponse> > GetCollectibleNodeDetails(
            BungieMembershipType membershipType,
            long destinyMembershipId,
            long characterId,
            uint collectiblePresentationNodeHash,
            DestinyComponentType[] componentTypes,
            AuthorizationTokenData authData = null,
            CancellationToken token         = default)
        {
            var url = StringBuilderPool
                      .GetBuilder(token)
                      .Append("/Destiny2/")
                      .AddUrlParam(((int)membershipType).ToString())
                      .AddQueryParam("components", componentTypes.ComponentsToIntString())
                      .Append("Profile/")
                      .AddUrlParam(destinyMembershipId.ToString())
                      .Append("Character/")
                      .AddUrlParam(characterId.ToString())
                      .Append("Collectibles/")
                      .AddUrlParam(collectiblePresentationNodeHash.ToString())
                      .AddQueryParam("components", componentTypes.ComponentsToIntString())
                      .Build();

            return(await _httpClient.GetFromBungieNetPlatform <DestinyCollectibleNodeDetailResponse>(url, token,
                                                                                                     authData?.AccessToken));
        }
 internal UserScopedGroupV2MethodsAccess(
     IGroupV2MethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
예제 #22
0
        public async ValueTask <BungieResponse <DestinyCharacterResponse> > GetCharacter(
            BungieMembershipType membershipType,
            long destinyMembershipId,
            long characterId,
            DestinyComponentType[] componentTypes,
            AuthorizationTokenData authData = null,
            CancellationToken token         = default)
        {
            if (componentTypes == null || componentTypes.Length == 0)
            {
                throw new ArgumentException("Specify some components before making a profile call.");
            }

            var url = StringBuilderPool
                      .GetBuilder(token)
                      .Append("/Destiny2/")
                      .AddUrlParam(((int)membershipType).ToString())
                      .Append("Profile/")
                      .AddUrlParam(destinyMembershipId.ToString())
                      .Append("Character/")
                      .AddUrlParam(characterId.ToString())
                      .AddQueryParam("components", componentTypes.ComponentsToIntString())
                      .Build();

            return(await _httpClient.GetFromBungieNetPlatform <DestinyCharacterResponse>(url, token,
                                                                                         authData?.AccessToken));
        }
예제 #23
0
 internal UserScopedAppMethodsAccess(
     IAppMethodsAccess access,
     AuthorizationTokenData token)
 {
     _apiAccess = access;
     _token     = token;
 }
예제 #24
0
 internal UserScopedDestiny2MethodsAccess(
     IDestiny2MethodsAccess apiAccess,
     AuthorizationTokenData token)
 {
     _apiAccess = apiAccess;
     _token     = token;
 }
예제 #25
0
 public async ValueTask <BungieResponse <ApiUsage> > GetApplicationApiUsage(
     AuthorizationTokenData authToken,
     int applicationId,
     DateTime?start          = null,
     DateTime?end            = null,
     CancellationToken token = default)
 {
     return(await _apiAccess.GetApplicationApiUsage(_token, applicationId, start, end, token));
 }
예제 #26
0
 public async ValueTask <BungieResponse <BungieFriendRequestListResponse> > GetFriendRequestList(
     AuthorizationTokenData authorizationToken,
     CancellationToken cancellationToken = default)
 {
     if (!_configuration.HasSufficientRights(ApplicationScopes.ReadUserData))
     {
         throw new InsufficientScopeException(ApplicationScopes.ReadUserData);
     }
     return(await _dotNetBungieApiHttpClient.GetFromBungieNetPlatform <BungieFriendRequestListResponse>(
                "/Social/Friends/Requests/", cancellationToken, authorizationToken.AccessToken));
 }
예제 #27
0
        public async ValueTask <BungieResponse <CredentialTypeForAccount[]> > GetCredentialTypesForTargetAccount(
            long id,
            AuthorizationTokenData authToken,
            CancellationToken token = default)
        {
            var url = StringBuilderPool
                      .GetBuilder(token)
                      .Append("/User/GetCredentialTypesForTargetAccount/")
                      .AddUrlParam(id.ToString())
                      .Build();

            return(await _httpClient.GetFromBungieNetPlatform <CredentialTypeForAccount[]>(url, token,
                                                                                           authToken.AccessToken));
        }
 /// <summary>
 ///     <inheritdoc cref="IFireteamMethodsAccess.GetActivePrivateClanFireteamCount" />
 /// </summary>
 /// <param name="authData"></param>
 /// <param name="groupId"></param>
 /// <param name="platform"></param>
 /// <param name="activityType"></param>
 /// <param name="dateRange"></param>
 /// <param name="slotFilter"></param>
 /// <param name="publicOnly"></param>
 /// <param name="page"></param>
 /// <param name="langFilter"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public async ValueTask <BungieResponse <SearchResultOfFireteamSummary> > GetAvailableClanFireteams(
     AuthorizationTokenData authData,
     long groupId,
     FireteamPlatform platform,
     DestinyActivityModeType activityType,
     FireteamDateRange dateRange,
     FireteamSlotSearch slotFilter,
     FireteamPublicSearchOption publicOnly,
     int page                = 0,
     string langFilter       = null,
     CancellationToken token = default)
 {
     return(await _apiAccess.GetAvailableClanFireteams(_token, groupId, platform, activityType, dateRange,
                                                       slotFilter, publicOnly, page, langFilter, token));
 }
예제 #29
0
        public async ValueTask <BungieResponse <int> > TransferItem(
            DestinyItemTransferRequest request,
            AuthorizationTokenData authData,
            CancellationToken token = default)
        {
            if (!_configuration.Settings.IdentificationSettings.ApplicationScopes
                .HasFlag(ApplicationScopes.MoveEquipDestinyItems))
            {
                throw new InsufficientScopeException(ApplicationScopes.MoveEquipDestinyItems);
            }
            var stream = new MemoryStream();
            await _serializationHelper.SerializeAsync(stream, request);

            return(await _httpClient.PostToBungieNetPlatform <int>("/Destiny2/Actions/Items/TransferItem/", token,
                                                                   stream, authData.AccessToken));
        }
        public async ValueTask <AuthorizationTokenData> RenewToken(AuthorizationTokenData authData)
        {
            try
            {
                var newToken = await _client.RenewAuthorizationToken(authData);

                authData.Update(newToken);
                return(_authorizationTokenDatas.AddOrUpdate(newToken.MembershipId, authData, (_, _) => authData));
            }
            catch (Exception e)
            {
                _logger.Log(e.Message, LogType.Error);
            }

            throw new Exception("Failed to get new token");
        }