コード例 #1
0
        /// <summary>
        /// Provides Find functionality async (without paging)
        /// </summary>
        /// <param name="where"></param>
        /// <param name="order_by"></param>
        /// <param name="include_deleted"></param>
        /// <param name="fields"></param>
        /// <param name="is_distinct"></param>
        /// <returns>resonse with JobID to send to GetExportJobInfo</returns>
        public ExportAsyncResponse ExportAsync(string where = null, string order_by = null, bool?include_deleted = null, string fields = null, bool?is_distinct = null)
        {
            var ExportAsyncRequest = new ExportAsyncRequest();

            ExportAsyncRequest.where           = where;
            ExportAsyncRequest.order_by        = order_by;
            ExportAsyncRequest.include_deleted = include_deleted;
            ExportAsyncRequest.fields          = fields;
            ExportAsyncRequest.is_distinct     = is_distinct;

            string RequestUri = string.Format("export/{0}", ResourceName);

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

            string postBody    = PepperiJsonSerializer.Serialize(ExportAsyncRequest); //null values are not serialzied.
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #2
0
        private BulkUploadResponse BulkUpload_OfJson(IEnumerable <TModel> data, eOverwriteMethod OverwriteMethod, IEnumerable <string> fieldsToUpload)
        {
            FlatModel FlatModel = PepperiFlatSerializer.MapDataToFlatModel(data, fieldsToUpload, "''");

            string RequestUri = string.Format("bulk/{0}/json", ResourceName);

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

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

            string postBody    = PepperiJsonSerializer.Serialize(FlatModel);                      //null values are not serialzied.
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Renames a UserDefinedField
        /// </summary>
        /// <param name="TypeID">The type to which the field belongs</param>
        /// <param name="FieldID">The original field name</param>
        /// <param name="newFieldID">The new field Name</param>
        /// <returns>The updated Feild</returns>
        /// <remarks>
        /// 1.Attempt to Rename a field that is not a "User Defined Field" retruns Bad Request
        /// </remarks>
        public Field_MetaData RenameUserDefinedField(long TypeID, string FieldID, string newFieldID)
        {
            string RequestUri = string.Format(@"meta_data/{0}/types/{1}/fields/{2}/rename", this.ResourceName, TypeID.ToString(), FieldID);
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            string putBody     = PepperiJsonSerializer.Serialize(new { FieldID = newFieldID });    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PutStringContent(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                putBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fields">comma seperated list of the fields to include</param
        /// <param name="include_nested">populate the References propeties of the result</param>
        /// <param name="full_mode">populate the Reference propeties of the result</param>
        /// <returns>the object</returns>
        public TModel FindByID(TModelKey id, string fields = null, bool?include_nested = null, bool?full_mode = null)
        {
            string RequestUri = ResourceName + "//" + HttpUtility.UrlEncode(id.ToString());
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            if (fields != null)
            {
                dicQueryStringParameters.Add("fields", fields);
            }
            if (include_nested.HasValue)
            {
                dicQueryStringParameters.Add("include_nested", include_nested.Value.ToString());
            }
            if (full_mode.HasValue)
            {
                dicQueryStringParameters.Add("full_mode", full_mode.Value.ToString());
            }
            string accept = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Upserts a UserDefinedField
        /// </summary>
        /// <param name="Field"></param>
        /// <returns></returns>
        /// <remarks>
        /// 1.Attempt to Upsert a field that is not a "User Defined Field" retruns Bad Request
        /// </remarks>
        public Field_MetaData UpsertUserDefinedField(Field_MetaData Field)
        {
            string RequestUri = string.Format(@"meta_data/{0}/fields", this.ResourceName);
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            string postBody    = PepperiJsonSerializer.Serialize(Field);                                    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostStringContent(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                postBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #6
0
        public TModel Upsert <TModel>(string collectionName, TModel Model)
        {
            string RequestUri = $"resources/{collectionName}";

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

            string postBody    = PepperiJsonSerializer.Serialize(Model);                                    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.AuthentificationManager.IdpAuth, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.PostStringContent(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                postBody,
                contentType,
                accept
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Group And Aggregate function
        /// </summary>
        /// <param name="select">comma seperated list of aggregate functions. eg: "max(UnitPrice),min(UnitPrice)".   Supported functions: min,max,av,count.</param>
        /// <param name="group_by">Optional. comma seperated list of fields to group_by</param>
        /// <param name="where">Optioal</param>
        /// <returns>
        /// Array with a dictionary per group. Each dicionary holds the selected values for that group, eg: max_UnitPrice.
        /// </returns>
        /// <example>
        /// if you want to  group   transaction_lines by Transaction.InternalID
        ///                 and     get for each group:                         max(UnitPrice),min(UnitPrice),avg(UnitPrice),count(UnitPrice)
        ///
        /// Then, call this method with:
        ///             group_by    ="Transaction.InternalID"
        ///             select      ="max(UnitPrice) as xxx,min(UnitPrice),avg(UnitPrice),count(UnitPrice)"
        ///             where       ="Transaction.InternalID>2066140676"
        ///
        /// The result:
        ///                         [   {"Transaction.InternalID": 65064336,"xxx": 23.0,"min_UnitPrice": 19.0,"avg_UnitPrice": 21.0,"count_UnitPrice": 2.0},
        ///		                        {"Transaction.InternalID": 65064316,"xxx": 23.0,"min_UnitPrice": 23.0,"avg_UnitPrice": 23.0,"count_UnitPrice": 1.0},
        ///		                    ]
        ///
        /// Note:       This method will send http request:     Get         https://.../V1.0//totals/transaction_lines?select=max(UnitPrice) as xxx,min(UnitPrice),avg(UnitPrice),count(UnitPrice)&group_by=Transaction.InternalID&where=Transaction.InternalID>2066140676
        /// </example>
        public Dictionary <string, object>[] GetTotals(string select, string group_by = null, string where = null)
        {
            string RequestUri = "totals/" + ResourceName;

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

            if (select != null)
            {
                dicQueryStringParameters.Add("select", select);
            }
            if (group_by != null)
            {
                dicQueryStringParameters.Add("group_by", group_by);
            }
            if (where != null)
            {
                dicQueryStringParameters.Add("where", where);
            }

            string accept = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            Dictionary <string, object>[] result = PepperiJsonSerializer.DeserializeOne <Dictionary <string, object>[]>(PepperiHttpClientResponse.Body);   //Api returns array of dictionary
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Upserts a User Defined Table
        /// </summary>
        /// <param name="UserDefinedTable"></param>
        /// <returns>The upserted User Defined Table</returns>
        public UserDefinedTable_MetaData UpsertUserDefinedTable(UserDefinedTable_MetaData UserDefinedTable)
        {
            string RequestUri = "meta_data/user_defined_tables";

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

            string postBody    = PepperiJsonSerializer.Serialize(UserDefinedTable);            //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="include_nested">indicates whether references (1:many) data should be upserted. reference (1:1) fields are upserted.</param>
        /// <returns></returns>
        /// <remarks>
        /// Post and Get use the same model
        /// Operation may do insert or Partial update depanding on the value of ExternalID \ InternalID
        /// Insert
        ///     if the External\InternalID are not given in the request
        ///     The model properties with null value are not serialzied by APIClient. Server populates them with default value.
        ///Partial update
        ///     If the External\InternalID is given in the request
        ///     The model properties with null value are not serialzied by APIClient. server updates the values of the properties which are not null.
        ///Regarding Reference:
        ///     used in 1:1 relations when both entities may exist indepandently.
        ///     To attach relation call upsert (setting the x.Reference.Data.ExternalID or x.Reference.Data.InternalID)
        ///     To detach relation call upsert (setting the x.Rerefere.Data to null)
        ///     To read the reference call find with full_mode = true
        ///Regarding References:
        ///     used in 1:many relations when child entities may exist without parent entity.
        ///     To set relations call upsert (simply deletes all exsiting relations and set the relations we send on upsert)
        ///         (setting the x.References.Data.Add ( { InternalID=  .... ExternalID = .... })
        ///     To delete all the relations call upset *setting the x.Reference.Data to empty collection.
        ///     To read the references call find with includ_nested =  true
        ///
        ///     used in 1:many relations when the child entity can not exist without the parent entity
        ///             (Contact can not exist without the account)
        ///             in that case, as you create the child entity (eg, Contact) you use its reference Property  (ExternalID or InternalID) to associte the child with existing parent.   [Do not use the ParentExternalId property of the child, since it is used obly in Bulk).
        ///
        /// </remarks>
        public TModel Upsert(TModel Model, bool?include_nested = null)
        {
            string RequestUri = ResourceName;

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

            if (include_nested.HasValue)
            {
                dicQueryStringParameters.Add("include_nested", include_nested.Value.ToString());
            }

            string postBody    = PepperiJsonSerializer.Serialize(Model);                                    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ApiTokenBaseUri"></param>
        /// <param name="AppConsumerKey"></param>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <returns>the api token will later on be sent as "password" of basic authentication</returns>
        /// <remarks>
        /// 1. Using PepperiHttpClient for consistency and maintainability (logging etc)
        /// </remarks>
        public static APITokenData GetAPITokenData(string ApiTokenBaseUri, string AppConsumerKey, string Username, string Password, ILogger Logger)
        {
            string RequestUri = "company//ApiToken";
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            string accept = "application/json";

            IAuthentication Authentication = new BasicAuthentication(Username, Password, AppConsumerKey, true);

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(Authentication, Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get(
                ApiTokenBaseUri,
                RequestUri,
                dicQueryStringParameters,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            //string result = APITokenData.APIToken;

            //return result;
            return(APITokenData);
        }
        private string GetIdpTokenData()
        {
            var    baseUrl    = this.IpaasBaseurl;
            string RequestUri = "PepperiApi/GetIdpToken";
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            string accept = "application/json";

            IAuthentication Authentication = new IpaasAddonAuthentification(this.Logger, this.APIToken, false);

            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(Authentication, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get(
                baseUrl,
                RequestUri,
                dicQueryStringParameters,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            var response = PepperiJsonSerializer.DeserializeOne <GetIpaasTokenResponse>(PepperiHttpClientResponse.Body);   //Api returns single object

            //string result = APITokenData.APIToken;

            //return result;
            return(response?.Data);
        }
コード例 #12
0
        /// <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 RequestUri =
                (SubTypeID == null || SubTypeID.Length == 0) ?
                string.Format("bulk/{0}/csv_zip", ResourceName) :
                string.Format("bulk/{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);
        }
コード例 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="UserDefinedField"></param>
        /// <returns>The name of the newly created field</returns>
        public string CreateUserDefinedField(UserDefinedField UserDefinedField, string SubTypeID = null)
        {
            string RequestUri =
                (SubTypeID == null || SubTypeID.Length == 0) ?
                string.Format(@"metadata/{0}", this.ResourceName) :
                string.Format(@"metadata/{0}/{1}", ResourceName, SubTypeID);

            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            string postBody    = PepperiJsonSerializer.Serialize(UserDefinedField);                                    //null values are not serialized
            string contentType = "application/json";
            string accept      = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #14
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// 1. The method is called on every Http operation used with this Authentication (from GetAuthorizationHeaderValue)
        /// </remarks>
        private Oauth2Token RefreshToken()
        {
            string RequestUri = "oauth//refresh_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>("grant_type", "refresh_token"));
            postBody.Add(new KeyValuePair <string, string>("refresh_token", this.Oauth2Token.refresh_token));

            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

            return(result);
        }
コード例 #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="externalId"></param>
        /// <param name="include_nested">populate the References propeties of the result</param>
        /// <param name="full_mode">populate the Reference propeties of the result</param>
        /// <returns></returns>
        public TModel FindByExternalID(string externalId, bool?include_nested = null, bool?full_mode = null)  //not relevant for: inventory and user defined tables
        {
            string RequestUri = ResourceName + "//externalid//" + HttpUtility.UrlEncode(externalId);
            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();

            if (include_nested.HasValue)
            {
                dicQueryStringParameters.Add("include_nested", include_nested.Value.ToString());
            }
            if (full_mode.HasValue)
            {
                dicQueryStringParameters.Add("full_mode", full_mode.Value.ToString());
            }
            string accept = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
コード例 #16
0
        public PepperiAuditLog GetAuditLog(string auditLogId)
        {
            var RequestUri = $"audit_logs/{auditLogId}";
            var dicQueryStringParameters = new Dictionary <string, string>();
            PepperiHttpClient         PepperiHttpClient         = new PepperiHttpClient(this.Authentication, this.Logger);
            PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                "application/json"
                );

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            return(PepperiJsonSerializer.DeserializeOne <PepperiAuditLog>(PepperiHttpClientResponse.Body));
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        /// <summary>
        /// Deletes the given User Defined Table
        /// </summary>
        /// <param name="TableID"></param>
        /// <returns></returns>
        /// <remarks>Not Found is returned if table does not exist</remarks>
        public bool DeleteUserDefinedTable(string TableID)
        {
            string RequestUri = string.Format(@"meta_data/user_defined_tables/{0}", TableID);
            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);

            return(result);
        }
コード例 #19
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);
        }
コード例 #20
0
        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);
        }
コード例 #21
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);
        }
コード例 #22
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);
        }
コード例 #23
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());
        }
コード例 #24
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));
        }
コード例 #25
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);
        }