Exemple #1
0
        //----------------------------------------------------------------------------
        //
        // AirtableBase.RetrieveRecord<T>
        //
        // Called to retrieve a record with the specified id from the specified table.
        // The fields of the retrieved record are deserialized to type <T>.
        //
        //----------------------------------------------------------------------------

        public async Task <AirtableRetrieveRecordResponse <T> > RetrieveRecord <T>(
            string tableName,
            string id)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("Table Name cannot be null", "tableName");
            }

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Record ID cannot be null", "id");
            }

            string uriStr   = AIRTABLE_API_URL + BaseId + "/" + Uri.EscapeDataString(tableName) + "/" + id;
            var    request  = new HttpRequestMessage(HttpMethod.Get, uriStr);
            var    response = await httpClientWithRetries.SendAsync(request);

            AirtableApiException error = await CheckForAirtableException(response);

            if (error != null)
            {
                return(new AirtableRetrieveRecordResponse <T>(error));
            }
            var responseBody = await response.Content.ReadAsStringAsync();

            AirtableRecord <T> airtableRecord = JsonSerializer.Deserialize <AirtableRecord <T> >(responseBody);

            return(new AirtableRetrieveRecordResponse <T>(airtableRecord));
        }
        //----------------------------------------------------------------------------
        //
        // AirtableBase.RetrieveRecord
        //
        // Called to retrieve a record with the specified id from the specified table.
        //
        //----------------------------------------------------------------------------

        public async Task <AirtableRetrieveRecordResponse> RetrieveRecord(
            string tableName,
            string id)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("Table Name cannot be null", "tableName");
            }

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Record ID cannot be null", "id");
            }

            AirtableRecord airtableRecord = null;
            string         uriStr         = AIRTABLE_API_URL + BaseId + "/" + tableName + "/" + id;
            var            request        = new HttpRequestMessage(HttpMethod.Get, uriStr);
            var            response       = await Client.SendAsync(request);

            AirtableApiException error = await CheckForAirtableException(response);

            if (error != null)
            {
                return(new AirtableRetrieveRecordResponse(error));
            }
            var responseBody = await response.Content.ReadAsStringAsync();

            airtableRecord = JsonConvert.DeserializeObject <AirtableRecord>(responseBody);

            return(new AirtableRetrieveRecordResponse(airtableRecord));
        }
 public AirtableRetrieveRecordResponse(AirtableRecord record) : base()
 {
     Record = record;
 }
 public AirtableCreateUpdateReplaceRecordResponse(AirtableRecord record) : base()
 {
     Record = record;
 }