コード例 #1
0
        public async Task <T[]> LoadTableAsync <T>(string tableName)
        {
            var result = new List <T>();
            var offset = "0";

            while (!string.IsNullOrWhiteSpace(offset))
            {
                var url     = $"https://api.airtable.com/v0/{baseId}/{tableName}?api_key={client.ApiKey}&offset={offset}";
                var message = await client.Get(url);

                if (message.StatusCode != HttpStatusCode.OK)
                {
                    switch (message.StatusCode)
                    {
                    case HttpStatusCode.BadRequest:
                        throw new AirtableBadRequestException();

                    case HttpStatusCode.Forbidden:
                        throw new AirtableForbiddenException();

                    case HttpStatusCode.NotFound:
                        throw new AirtableNotFoundException();

                    case HttpStatusCode.PaymentRequired:
                        throw new AirtablePaymentRequiredException();

                    case HttpStatusCode.Unauthorized:
                        throw new AirtableUnauthorizedException();

                    case HttpStatusCode.RequestEntityTooLarge:
                        throw new AirtableRequestEntityTooLargeException();

                    case (HttpStatusCode)422:
                        var error = JsonSerializer.Deserialize <dynamic>(await message.Content.ReadAsByteArrayAsync());
                        throw new AirtableInvalidRequestException(error?["error"]?["message"]);

                    case (HttpStatusCode)429:
                        throw new AirtableTooManyRequestsException();

                    default:
                        throw new AirtableUnrecognizedException(message.StatusCode);
                    }
                }

                var jsonBody = JsonSerializer.Deserialize <JsonBody <T> >(await message.Content.ReadAsByteArrayAsync());
                offset = jsonBody.Offset;

                result.AddRange(jsonBody.Records.Select(x => x.Body));
            }
            while (!string.IsNullOrWhiteSpace(offset))
            {
                ;
            }

            return(result.ToArray());
        }
コード例 #2
0
        public async Task <T[]> LoadTableAsync <T>()
        {
            var url     = $"https://api.airtable.com/v0/{baseId}/{typeof(T).Name}?api_key={client.ApiKey}";
            var message = await client.Get(url);

            if (message.StatusCode != HttpStatusCode.OK)
            {
                switch (message.StatusCode)
                {
                case HttpStatusCode.BadRequest:
                    throw new AirtableBadRequestException();

                case HttpStatusCode.Forbidden:
                    throw new AirtableForbiddenException();

                case HttpStatusCode.NotFound:
                    throw new AirtableNotFoundException();

                case HttpStatusCode.PaymentRequired:
                    throw new AirtablePaymentRequiredException();

                case HttpStatusCode.Unauthorized:
                    throw new AirtableUnauthorizedException();

                case HttpStatusCode.RequestEntityTooLarge:
                    throw new AirtableRequestEntityTooLargeException();

                case (HttpStatusCode)422:
                    var error = JsonSerializer.Deserialize <dynamic>(await message.Content.ReadAsByteArrayAsync());
                    throw new AirtableInvalidRequestException(error?["error"]?["message"]);

                case (HttpStatusCode)429:
                    throw new AirtableTooManyRequestsException();

                default:
                    throw new AirtableUnrecognizedException(message.StatusCode);
                }
            }

            var jsonBody = JsonSerializer.Deserialize <JsonBody <T> >(await message.Content.ReadAsByteArrayAsync());

            return(jsonBody.Records.Select(x => x.Body).ToArray());
        }