/// <summary></summary> /// <returns>the sub types of this resource</returns> /// <remarks> /// 1. some resources (eg, transaction and activity) are "abstract types". /// the concrete types "derive" from them: eg, sales transaction, invoice derive from transaction (with header and lines) /// eg, visit derive from activity (with header) /// the concrete class cusom fields are modeled as TSA filed /// 2. All the types are returned by metadata endpoint /// 3. Activities, Transactions, transaction_lines are "abstract" type. Acconut is concrete typr that may be derived by SubType. /// The concrete type is identified by ActivityTypeID /// For Bulk or CSV upload, the ActivityTypeID is sent on the url /// For single Upsert, the ActivityTypeID is set on the object /// The values of the ActivityTypeID are taken from the SubTypeMetadata action /// </remarks> public IEnumerable <TypeMetadata> GetSubTypesMetadata() { string RequestUri = string.Format("metadata"); Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept); PepperiHttpClient.HandleError(PepperiHttpClientResponse); IEnumerable <TypeMetadata> result = PepperiJsonSerializer.DeserializeCollection <TypeMetadata>(PepperiHttpClientResponse.Body); result = result.Where(subTypeMetadata => subTypeMetadata.Type == ResourceName && subTypeMetadata.SubTypeID != null && subTypeMetadata.SubTypeID.Length > 0 ). ToList(); return(result); }
/// <summary> /// /// </summary> /// <param name="where"></param> /// <param name="order_by"></param> /// <param name="page"></param> /// <param name="page_size"></param> /// <param name="include_nested"></param> /// <param name="include_nested">populate the References propeties of the result(1:many)</param> /// <param name="full_mode">populate the Reference propeties of the result (1:1)</param> /// <param name="fields"></param> /// <returns></returns> public IEnumerable <TModel> Find(string where = null, string order_by = null, int?page = null, int?page_size = null, bool?include_nested = null, bool?full_mode = null, bool?include_deleted = null, string fields = null, bool?is_distinct = null) { string RequestUri = ResourceName; Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); if (where != null) { dicQueryStringParameters.Add("where", where); } if (order_by != null) { dicQueryStringParameters.Add("order_by", order_by); } if (page.HasValue) { dicQueryStringParameters.Add("page", page.Value.ToString()); } if (page_size.HasValue) { dicQueryStringParameters.Add("page_size", page_size.Value.ToString()); } if (include_nested.HasValue) { dicQueryStringParameters.Add("include_nested", include_nested.Value.ToString()); } if (full_mode.HasValue) { dicQueryStringParameters.Add("full_mode", full_mode.Value.ToString()); } if (include_deleted.HasValue) { dicQueryStringParameters.Add("include_deleted", include_deleted.Value.ToString()); } if (fields != null) { dicQueryStringParameters.Add("fields", fields); } if (is_distinct != null) { dicQueryStringParameters.Add("is_distinct", fields); } string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept ); PepperiHttpClient.HandleError(PepperiHttpClientResponse); IEnumerable <TModel> result = PepperiJsonSerializer.DeserializeCollection <TModel>(PepperiHttpClientResponse.Body); return(result); }
public IEnumerable <UserDefinedCollection_MetaData> GetUserDefinedCollections() { string RequestUri = @"user_defined_collections/schemes"; Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept); PepperiHttpClient.HandleError(PepperiHttpClientResponse); IEnumerable <UserDefinedCollection_MetaData> result = PepperiJsonSerializer.DeserializeCollection <UserDefinedCollection_MetaData>(PepperiHttpClientResponse.Body); return(result); }
/// <summary> /// Returns the Types of the Resource /// </summary> /// <returns>The Types of the given resuorce (Accounts, Activities, Transactions)</returns> /// <remarks> /// eg, ApiClient.AccountsMetaData.GetTypes() may return Customer. /// ApiClient.ActivitiesMetaData.GetTypes() may return Photo and Visit. /// ApiClient.TransactionsMetaData.GetTyoes() may returns SalesOrder. /// </remarks> public IEnumerable <Type_MetaData> GetTypes() { string RequestUri = string.Format(@"meta_data/{0}/types", this.ResourceName); Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept); PepperiHttpClient.HandleError(PepperiHttpClientResponse); IEnumerable <Type_MetaData> result = PepperiJsonSerializer.DeserializeCollection <Type_MetaData>(PepperiHttpClientResponse.Body); return(result); }
/// <summary> ///returns list of ist of (Standart and User Defined) fields of that belong to the given Type /// </summary> /// <param name="ExternalID">The value of Type.ExternalID</param> /// <returns>The fields of the given type</returns> /// <Note> /// 1.The value of IsUserDefinedField property defines whether a given field is a "User Defined Field" /// </Note> public IEnumerable <Field_MetaData> GetFields_By_TypeExternalID(string TypeExternalID) { string RequestUri = string.Format(@"meta_data/{0}/types/externalid/{1}/fields", this.ResourceName, System.Web.HttpUtility.UrlPathEncode(TypeExternalID)); Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept); PepperiHttpClient.HandleError(PepperiHttpClientResponse); IEnumerable <Field_MetaData> result = PepperiJsonSerializer.DeserializeCollection <Field_MetaData>(PepperiHttpClientResponse.Body); return(result); }
private UDC_UploadFile_Result GetImportFileDataResult(PepperiAuditLog auditLog) { var logResultObject = auditLog?.AuditInfo?.ResultObject; var parsedResultObject = PepperiJsonSerializer.DeserializeOne <UDC_UploadFile_AuditLog_ResultObject>(logResultObject); var url = parsedResultObject?.URI; ValuesValidator.Validate(url, "Can't get URI Response!"); var HttpClient = new HttpClient(new LoggingHandler(this.Logger)) { }; //send request HttpClient.Timeout = new TimeSpan(0, 5, 0);// by default wait 5 minutes HttpResponseMessage HttpResponseMessage = HttpClient.GetAsync(url).Result; string body = HttpResponseMessage.Content.ReadAsStringAsync().Result; ValuesValidator.Validate(HttpResponseMessage.StatusCode == HttpStatusCode.OK, $"Can't get Required File! (Status Code - {HttpResponseMessage.StatusCode})"); var table = PepperiJsonSerializer.DeserializeCollection <UDC_UploadFile_Row>(body); var result = new UDC_UploadFile_Result() { Success = true, Total = table.Count(), TotalUpdated = 0, TotalIgnored = 0, TotalFailed = 0, FailedRows = new List <UDC_UploadFile_Row>() { } }; var grouped = table.GroupBy(row => row.Status); foreach (var gropedRow in grouped) { switch (gropedRow.Key) { case "Error": result.TotalFailed = gropedRow.Count(); result.FailedRows = gropedRow.ToList(); break; case "Update": result.TotalUpdated = gropedRow.Count(); break; case "Insert": result.TotalInserted = gropedRow.Count(); break; case "Ignore": result.TotalIgnored = gropedRow.Count(); break; default: break; } } return(result); }