Exemplo n.º 1
0
        public async IAsyncEnumerable <TResponse> GetAllAsync <TResponse, TAttribute, TRelationship>(
            IPatreonRequest <TResponse, TAttribute, TRelationship> request,
            string parameter = null)
            where TResponse : PatreonCollectionResponse <TAttribute, TRelationship>
            where TRelationship : IRelationship
        {
            var response = await GetAsync(request, parameter);

            yield return(response);

            while (response.HasMore)
            {
                response = await SendAsync <TResponse, TAttribute, TRelationship>(response.Links.Next);

                yield return(response);
            }
        }
Exemplo n.º 2
0
        public Task <TResponse> GetAsync <TResponse, TAttribute, TRelationship>(
            IPatreonRequest <TResponse, TAttribute, TRelationship> request,
            string parameter = null)
            where TResponse : PatreonResponseBase <TAttribute, TRelationship>
            where TRelationship : IRelationship
        {
            if (request is ParameterizedPatreonRequest <TResponse, TAttribute, TRelationship> )
            {
                if (string.IsNullOrEmpty(parameter))
                {
                    throw new ArgumentException($"{nameof(parameter)} is required for {typeof(TAttribute).Name}");
                }
                return(SendAsync <TResponse, TAttribute, TRelationship>(string.Format(request.Url, parameter)));
            }

            if (request is PatreonRequest <TResponse, TAttribute, TRelationship> )
            {
                return(SendAsync <TResponse, TAttribute, TRelationship>(request.Url));
            }

            throw new ArgumentException($"invalid {nameof(request)}");
        }