public GetBulkJobInfoResponse GetBulkJobInfo(string JobID)
        {
            string RequestUri = string.Format("bulk/jobinfo/{0}", HttpUtility.UrlEncode(JobID));
            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);

            GetBulkJobInfoResponse result = PepperiJsonSerializer.DeserializeOne <GetBulkJobInfoResponse>(PepperiHttpClientResponse.Body);   //Api returns single object

            return(result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="authorization_code">The authorization code we get from service on callback, indicating that user has given valid credentinals.</param>
        /// <param name="redirect_uri"></param>
        /// <param name="scope"></param>
        /// <param name="Oauth2TokenRepository"></param>
        /// <returns></returns>
        public Oauth2Token GetAccessTokenByAuthorizationCode(string authorization_code, string redirect_uri, string scope, IOauth2TokenRepository Oauth2TokenRepository)
        {
            string RequestUri = "oauth//access_token";

            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            List <KeyValuePair <string, string> > postBody = new List <KeyValuePair <string, string> >();

            postBody.Add(new KeyValuePair <string, string>("client_id", this.AppConsumerKey));
            postBody.Add(new KeyValuePair <string, string>("client_secret", this.AppConsumerSecret));
            postBody.Add(new KeyValuePair <string, string>("scope", scope));
            postBody.Add(new KeyValuePair <string, string>("grant_type", "authorization_code"));
            postBody.Add(new KeyValuePair <string, string>("code", authorization_code));
            postBody.Add(new KeyValuePair <string, string>("redirect_uri", redirect_uri));

            string contentType = "application/x-www-form-urlencoded";

            string accept = "application/json";

            IAuthentication   Authentication    = null; //no special headers
            PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(Authentication, Logger);
            ///
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostFormUrlEncodedContent(
                this.OauthBaseUri,
                RequestUri,
                dicQueryStringParameters,
                postBody,
                contentType,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            Oauth2Token result = PepperiJsonSerializer.DeserializeOne <Oauth2Token>(PepperiHttpClientResponse.Body);   //Api returns single object

            //save result
            if (Oauth2TokenRepository != null)
            {
                Oauth2TokenRepository.SaveToken(result);
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a specific Type by its TypeID
        /// </summary>
        /// <param name="TypeID"></param>
        /// <returns>The Type with the given TypeID</returns>
        public Type_MetaData GetTypeByID(long TypeID)
        {
            string RequestUri = string.Format(@"meta_data/{0}/types/{1}", this.ResourceName, TypeID);
            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);

            Type_MetaData result = PepperiJsonSerializer.DeserializeOne <Type_MetaData>(PepperiHttpClientResponse.Body);

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Deletes a UserDefinedField from a given Type
        /// </summary>
        /// <param name="FieldID">Identifies the field to delete</param>
        /// <param name="TypeID">Identifies the  type that holds the field to delete</param>
        /// <returns>true on Success</returns>
        /// <remarks>
        /// 1. Attempting to delete a field that is not a "User Defined Field" will fail
        /// </remarks>
        public bool DeleteUserDefinedField(long TypeID, string FieldID)
        {
            string RequestUri = string.Format(@"meta_data/{0}/types/{1}/fields/{2}", this.ResourceName, TypeID, FieldID);
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            string accept = "application/json";

            PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger);

            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Delete(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            bool result = PepperiJsonSerializer.DeserializeOne <bool>(PepperiHttpClientResponse.Body);   //Api returns bool right now. true-when resource is found and deleted. Otherwise, false.

            return(result);
        }
Beispiel #5
0
        /// <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);
        }
        public IEnumerable <FieldMetadata> GetFieldsMetaData()
        {
            string RequestUri = string.Format(@"metadata/{0}", 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 <FieldMetadata> result = PepperiJsonSerializer.DeserializeCollection <FieldMetadata>(PepperiHttpClientResponse.Body);

            result = result.OrderBy(o => o.Name);
            return(result);
        }
        public bool DeleteByExternalID(string externalId)
        {
            string RequestUri = ResourceName + "//externalid//" + HttpUtility.UrlEncode(externalId);
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            string accept = "application/json";

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.Authentication, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Delete(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            bool result = PepperiJsonSerializer.DeserializeOne <bool>(PepperiHttpClientResponse.Body);   //Api returns bool right now. true-when resource is found and deleted. Otherwise, false.

            return(result);
        }
Beispiel #8
0
        private string GetPresignedUrl(string key, string contentType = "application/json")
        {
            var requestUri  = "Aws/GetAwsPreSignedUrlForPut";
            var queryParams = new Dictionary <string, string>()
            {
                { "key", key },
                { "contentType", contentType }
            };
            string                    accept                    = "application/json";
            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.AuthentificationManager.IpaasAuth, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get(
                IpaasBaseUri,
                requestUri,
                queryParams,
                accept
                );

            var deserialized = PepperiJsonSerializer.DeserializeOne <GenericIpaasResponse <IEnumerable <string> > >(PepperiHttpClientResponse.Body);

            return(deserialized.Data.FirstOrDefault());
        }
        /// <summary>
        /// reusable method
        /// </summary>
        /// <param name="fileAsZipInUTF8"></param>
        /// <param name="OverwriteMethod"></param>
        /// <param name="SubTypeID">
        ///     usually empty value.
        ///     we use the parameter for sub types
        ///         eg, sales order that derive from transaction
        ///         eg, invoice     that derive from transaction
        ///         eg, visit       that derive from activity
        ///     in that case we take the SubTypeID from the metadata endpoint (see GetSubTypesMetadata method)
        ///     The custom fields are TSA fields
        ///     </param>
        /// <returns></returns>
        /// <remarks>
        /// 1. the post body is in UTF8
        /// </remarks>
        private BulkUploadResponse BulkUploadOfZip(byte[] fileAsZipInUTF8, eOverwriteMethod OverwriteMethod, string SubTypeID = null)
        {
            string bulkPrefix = "bulk";

            if (IsInternalAPI)
            {
                bulkPrefix = "AsyncAPI";
            }
            string RequestUri =
                (SubTypeID == null || SubTypeID.Length == 0) ?
                string.Format(bulkPrefix + "/{0}/csv_zip", ResourceName) :
                string.Format(bulkPrefix + "/{0}/{1}/csv_zip", ResourceName, SubTypeID);                                    //eg, for transaction or activity

            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            dicQueryStringParameters.Add("overwrite", OverwriteMethod.ToString());


            byte[] postBody    = fileAsZipInUTF8;
            string contentType = "application/zip";
            string accept      = "application/json";

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.Authentication, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostByteArraycontent(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                postBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            BulkUploadResponse result = PepperiJsonSerializer.DeserializeOne <BulkUploadResponse>(PepperiHttpClientResponse.Body);

            return(result);
        }
Beispiel #10
0
        private PepperiResponseForAuditLog SendImportFileToPepperiRequest(string schemeName, string fileUrl)
        {
            var RequestUri = $"resources/{HttpUtility.UrlEncode(schemeName)}/import/file";
            PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.AuthentificationManager.IdpAuth, this.Logger);

            string postBody = PepperiJsonSerializer.Serialize(new Dictionary <string, string>()
            {
                { "URI", fileUrl }
            });
            string contentType = "application/json";
            string accept      = "application/json";

            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostStringContent(
                ApiBaseUri,
                RequestUri,
                new Dictionary <string, string>(),
                postBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);
            return(PepperiJsonSerializer.DeserializeOne <PepperiResponseForAuditLog>(PepperiHttpClientResponse.Body));
        }
Beispiel #11
0
        public IEnumerable <TModel> Find <TModel>(string collectionName,
                                                  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 = $"resources/{collectionName}";

            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.AuthentificationManager.IdpAuth, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            IEnumerable <TModel> result = PepperiJsonSerializer.DeserializeCollection <TModel>(PepperiHttpClientResponse.Body);

            return(result);
        }
Beispiel #12
0
        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);
        }