Exemplo n.º 1
0
        async Task <TRecord> CUROperation <TRecord>(HttpMethod method, string recordId, Dictionary <string, object> fields, bool typecast) where TRecord : AirRecord
        {
            // For JsonConvert
            fields = FixDates(fields);

            var uri = AirClient.RecordUri(Base.BaseId, Name, recordId);
            var fieldsAndTypecast = new FieldsAndTypecast(fields, typecast);

            var response = await AirClient.SendAsync(method, Base.ApiKey, uri, fieldsAndTypecast.ToJson());

            var record = JsonConvert.DeserializeObject <TRecord>(response.Body);

            return(record);
        }
Exemplo n.º 2
0
        public async Task <bool> DeleteRecord(string recordId)
        {
            var uri = AirClient.RecordUri(Base.BaseId, Name, recordId);

            try {
                await AirClient.DeleteAsync(Base.ApiKey, uri);

                return(true);
            }
            catch (Exception exc) {
                Debug.ExceptionCaught(exc);
                return(false);
            }
        }
Exemplo n.º 3
0
        //public async Task<DataQueryResult> Query<TRecord>(object queryToken) where TRecord : AirRecord
        //{
        //	QyeryBuilder queryBuilder;
        //	if (queryToken is QyeryBuilder) {
        //		queryBuilder = (QyeryBuilder)queryToken;
        //	}
        //	else if (queryToken == null) {
        //		queryBuilder = new QyeryBuilder();
        //	}
        //	else {
        //		throw new ArgumentException("Invalid type of query token", queryToken.GetType().ToString());
        //	}

        //	var list = await List<TRecord>(queryBuilder);
        //	if (list != null && list.Records.Length > 0) {
        //		queryBuilder.Offset += list.Records.Length;

        //		return new DataQueryResult {
        //			Records = list.Records,
        //			Count = list.Records.Length,
        //			NextToken = queryBuilder
        //		};
        //	}
        //	else {
        //		return new DataQueryResult { Records = null, Count = 0, NextToken = null };
        //	}
        //}

        //public async Task<DataQueryResult> Filter<TRecord>(string formula, QyeryBuilder queryBuilder = null) where TRecord : AirRecord
        //{
        //	Guard.ArgumentNotEmpty(formula, nameof(formula));

        //	string savedFormula = null;
        //	if (queryBuilder == null) {
        //		queryBuilder = new QyeryBuilder { FilterByFormula = formula };
        //	}
        //	else {
        //		savedFormula = queryBuilder.FilterByFormula;
        //		queryBuilder.FilterByFormula = formula;
        //	}

        //	var result = await Query<TRecord>(queryBuilder);
        //	queryBuilder.FilterByFormula = savedFormula;
        //	return result;
        //}

        //public async Task<ICollection<IDataRecord>> GetAllRecords<TRecord>() where TRecord : AirRecord
        //{
        //	var records = new List<IDataRecord>();
        //	var queryBuilder = new QyeryBuilder();
        //	bool hasMore = true;
        //	do {
        //		var list = await List<TRecord>(queryBuilder);
        //		if (list != null && list.Records.Length > 0) {
        //			records.AddRange(list.Records);
        //			queryBuilder.Offset = list.Offset;
        //			hasMore = list.Offset != null;
        //		}
        //		else {
        //			hasMore = false;
        //		}
        //	}
        //	while (hasMore);

        //	return records;
        //}

        public async Task <TRecord> GetRecord <TRecord>(string recordId)
        {
            var uri = AirClient.RecordUri(Base.BaseId, Name, recordId);

            var response = await AirClient.GetAsync(Base.ApiKey, uri);

            var settings = new JsonSerializerSettings();

            settings.DateTimeZoneHandling = UsesUTC ? DateTimeZoneHandling.Utc : DateTimeZoneHandling.Local;

            var record = JsonConvert.DeserializeObject <TRecord>(response.Body, settings);

            return(record);
        }