/// <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);
        }
        /// <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);
        }
        /// <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>
        /// 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);
        }
        /// <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);
        }
        /// <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);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a User defined table by TableID
        /// </summary>
        /// <param name="TableID"></param>
        /// <returns></returns>
        public UserDefinedTable_MetaData GetUserDefinedTable(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.Get(
                ApiBaseUri,
                RequestUri,
                dicQueryStringParameters,
                accept);

            PepperiHttpClient.HandleError(PepperiHttpClientResponse);

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

            return(result);
        }
        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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 15
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());
        }
        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);
        }