/// <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);
        }
        /// <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);
        }
        /// <summary>
        /// </summary>
        /// <param name="UUID"></param>
        /// <param name="include_nested"></param>
        /// <param name="full_mode"></param>
        /// <returns>
        /// json returned by Pepperi API
        /// </returns>
        /// <remarks>
        /// 1. The method is usefull if you want to get data as json (eg, to get TSAs that are not defined in TModel)
        /// </remarks>
        public string FindJson_ByUUID(string UUID, bool?include_nested = null, bool?full_mode = null)
        {
            string RequestUri = ResourceName + "//UUID//" + HttpUtility.UrlEncode(UUID);
            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(PepperiHttpClientResponse.Body);
        }
Ejemplo n.º 4
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);
        }
        /// <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);
        }
Ejemplo n.º 6
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);
        }
        /// <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);
        }
        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);
        }
        /// <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);
        }
        /// <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="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);
        }
Ejemplo n.º 12
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);
        }
        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);
        }
Ejemplo n.º 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);
        }
        /// <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);
        }
Ejemplo n.º 16
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);
        }
        /// <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);
        }
Ejemplo n.º 18
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));
        }
        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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
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);
        }
        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);
        }
        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);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
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());
        }
Ejemplo n.º 29
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));
        }
        public long GetCount(string where = null, bool?include_deleted = null)
        {
            #region read first Page

            string RequestUri = ResourceName;

            Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>();
            if (where != null)
            {
                dicQueryStringParameters.Add("where", where);
            }
            if (include_deleted.HasValue)
            {
                dicQueryStringParameters.Add("include_deleted", include_deleted.Value.ToString());
            }
            dicQueryStringParameters.Add("include_count", "true");

            dicQueryStringParameters.Add("page", "1");
            dicQueryStringParameters.Add("page_size", "1");

            string accept = "application/json";

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

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

            #endregion

            #region Parse result (value of X-Pepperi-Total-Pages header)

            string headerKey     = "X-Pepperi-Total-Pages";
            bool   header_exists = PepperiHttpClientResponse.Headers.ContainsKey(headerKey);
            if (header_exists == false)
            {
                throw new PepperiException("Failed retrieving Total pages from response.");
            }

            IEnumerable <string> headerValue = PepperiHttpClientResponse.Headers[headerKey];
            if (headerValue == null || headerValue.Count() != 1)
            {
                throw new PepperiException("Failed retrieving Total pages from response.");
            }

            string resultAsString    = headerValue.First();
            long   result            = 0;
            bool   parsedSucessfully = long.TryParse(resultAsString, out result);


            if (!parsedSucessfully)
            {
                throw new PepperiException("Failed retrieving Total pages from response.");
            }

            #endregion

            return(result);
        }