Пример #1
0
        public PagedListViewModel <TemplateItemViewModel> Private(ApiCall call)
        {
            Dictionary <string, string> para = new Dictionary <string, string>();

            para.Add("OrganizationId", call.Context.User.CurrentOrgId.ToString());

            int pagenr   = ApiHelper.GetPageNr(call);
            int pagesize = ApiHelper.GetPageSize(call);

            if (pagenr != 0)
            {
                para.Add("PageNr", pagenr.ToString());
            }
            if (pagesize != 0)
            {
                para.Add("PageSize", pagesize.ToString());
            }

            string Url = UrlHelper.Combine(Kooboo.Data.AppSettings.ThemeUrl, "/_api/template/Private2");

            Url = UrlHelper.AppendQueryString(Url, para);

            var pagedlist = HttpHelper.Get <PagedListViewModel <TemplateItemViewModel> >(Url, para);

            SetThumbnailUrl(pagedlist.List);
            return(pagedlist);
        }
Пример #2
0
        private static async Task <string> _get(string url, Dictionary <string, string> query = null, string UserName = null, string Password = null)
        {
            try
            {
                if (query != null)
                {
                    url = UrlHelper.AppendQueryString(url, query);
                }

                HttpClient client         = HttpClientHelper.Client;
                var        requestMessage = new HttpRequestMessage
                {
                    RequestUri = new Uri(url),
                    Method     = HttpMethod.Get
                };
                if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
                {
                    var bytes = Encoding.UTF8.GetBytes(String.Format("{0}:{1}", UserName, Password));
                    requestMessage.Headers.Add(HttpRequestHeader.Authorization.ToString(), "Basic " + Convert.ToBase64String(bytes));
                }

                var response = await client.SendAsync(requestMessage);

                var byteArray = await response.Content.ReadAsByteArrayAsync();

                return(Encoding.UTF8.GetString(byteArray, 0, byteArray.Length));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Пример #3
0
        public PagedListViewModel <TemplateItemViewModel> List(ApiCall call)
        {
            int pagenr   = ApiHelper.GetPageNr(call);
            int pagesize = ApiHelper.GetPageSize(call);

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

            if (pagenr != 0)
            {
                paras.Add("PageNr", pagenr.ToString());
            }
            if (pagesize != 0)
            {
                paras.Add("PageSize", pagesize.ToString());
            }

            string Url = UrlHelper.Combine(AppSettings.ThemeUrl, "/_api/template/List2");

            Url = UrlHelper.AppendQueryString(Url, paras);

            var pagedlist = HttpHelper.Get <PagedListViewModel <TemplateItemViewModel> >(Url);

            SetThumbnailUrl(pagedlist.List);


            return(pagedlist);
        }
Пример #4
0
        public PagedListViewModel <TemplateItemViewModel> Search(ApiCall call)
        {
            Dictionary <string, string> para = new Dictionary <string, string>();

            para.Add("Keyword", call.GetValue("keyword"));

            int pagenr   = ApiHelper.GetPageNr(call);
            int pagesize = ApiHelper.GetPageSize(call);

            if (pagenr != 0)
            {
                para.Add("PageNr", pagenr.ToString());
            }
            if (pagesize != 0)
            {
                para.Add("PageSize", pagesize.ToString());
            }

            string Url = UrlHelper.Combine(Kooboo.Data.AppSettings.ThemeUrl, "/_api/template/Search2");

            Url = UrlHelper.AppendQueryString(Url, para);
            var pagedlist = HttpHelper.Get <PagedListViewModel <TemplateItemViewModel> >(Url, para);

            SetThumbnailUrl(pagedlist.List);
            return(pagedlist);
        }
Пример #5
0
        private static string _get(string url, Dictionary <string, string> query = null, string UserName = null, string Password = null)
        {
            try
            {
                if (query != null)
                {
                    url = UrlHelper.AppendQueryString(url, query);
                }
                var client = new WebClient();
                client.Headers.Add("user-agent", DefaultUserAgent);

                if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
                {
                    var bytes = Encoding.UTF8.GetBytes(String.Format("{0}:{1}", UserName, Password));
                    client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytes));
                }
                client.Proxy    = null;
                client.Encoding = Encoding.UTF8;
                SetSslValidate(url);
                var uri = new Uri(url);
                return(client.DownloadString(url));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
 // https://developers.klarna.com/documentation/hpp/api/create-session/#merchants-urls
 public MerchantUrls GetGetMerchantUrls(string callbackUrl, Guid requestId)
 {
     return(new MerchantUrls
     {
         Back = Back,
         Cancel = Cancel,
         Error = Error,
         Failure = Failure,
         StatusUpdate = UrlHelper.AppendQueryString(callbackUrl, "secretToken", requestId.ToString()),
         Success = Success
     });
 }
Пример #7
0
        // https://developers.klarna.com/documentation/hpp/api/create-session/#merchants-urls
        private MerchantUrls GetGetMerchantUrls(PaymentRequest request)
        {
            var additional  = new Dictionary <string, object>(request.Additional, StringComparer.OrdinalIgnoreCase);
            var callbackUrl = PaymentHelper.GetCallbackUrl(this, nameof(Notify), Context);

            return(new MerchantUrls
            {
                Back = GetValue(additional, "back", Setting.Back),
                Cancel = GetValue(additional, "cancel", Setting.Cancel),
                Error = GetValue(additional, "error", Setting.Error),
                Failure = GetValue(additional, "failure", Setting.Failure),
                StatusUpdate = UrlHelper.AppendQueryString(callbackUrl, "secretToken", request.Id.ToString()),
                Success = GetValue(additional, "success", Setting.Success)
            });
        }
Пример #8
0
        public static T Get <T>(string url, Dictionary <string, string> query, Dictionary <string, string> headers)
        {
            if (query != null)
            {
                url = UrlHelper.AppendQueryString(url, query);
            }
            using (var client = new WebClient())
            {
                client.Headers.Add("user-agent", DefaultUserAgent);
                AddHeader(client.Headers, headers);

                client.Proxy    = null;
                client.Encoding = Encoding.UTF8;

                var backstring = client.DownloadString(url);

                return(ProcessApiResponse <T>(backstring));
            }
        }
Пример #9
0
        private static async Task <string> _get(string url, Dictionary <string, string> query = null, IDictionary <string, object> headers = null)
        {
            try
            {
                if (query != null)
                {
                    url = UrlHelper.AppendQueryString(url, query);
                }

                HttpClient client = HttpClientHelper.Client;

                var requestMessage = new HttpRequestMessage
                {
                    RequestUri = new Uri(url),
                    Method     = HttpMethod.Get
                };

                if (headers != null)
                {
                    foreach (var item in headers)
                    {
                        requestMessage.Headers.Add(item.Key, item.Value?.ToString());
                    }
                }

                var response = await client.SendAsync(requestMessage);

                var byteArray = await response.Content.ReadAsByteArrayAsync();

                return(Encoding.UTF8.GetString(byteArray, 0, byteArray.Length));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }