public async Task<IEnumerable<Models.Products.ProductSuggestItemOutputModel>> GetSuggestSimilarDocumentsAsync(int id, string offerType = null, string domainLanguage = "fr", int take = 3)
        {
            using (var dclient = this.CreateClient())
            {
                var client = dclient.Client;
                var parameters = new Dictionary<string, string>();
                var dico = new Dictionary<string, string>(){
                { "domainLanguage", domainLanguage },
                { "take", take.ToString() },
                { "offerType", offerType }
            };

                var queryString = dico.ToQueryString();
                var url = "api/v2/products/{id}/suggests/similar".Replace("{id}", id.ToString());
                if (!string.IsNullOrEmpty(queryString))
                    url = url + "?" + queryString;
                var response = await client.GetAsync(this.GetUri(url)).ConfigureAwait(false);

                await this.HandleResponseAsync(response).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                    return (await this.GetObjectAsync<IEnumerable<Models.Products.ProductSuggestItemOutputModel>>(response.Content).ConfigureAwait(false));
                return Enumerable.Empty<Models.Products.ProductSuggestItemOutputModel>();
            }
        }
Example #2
0
 public override string ToString()
 {
     Dictionary<string, string> parameters = new Dictionary<string, string>();
     if (Lat.HasValue && Lon.HasValue)
     {
         parameters.Add("cp", string.Format("{0}~{1}", Lat.Value, Lon.Value));
     }
     if (Zoom.HasValue)
     {
         parameters.Add("lvl", Zoom.Value.ToString());
     }
     if (!String.IsNullOrWhiteSpace(Query))
     {
         parameters.Add("q", Query);
     }
     if (!String.IsNullOrWhiteSpace(Where))
     {
         parameters.Add("where", Where);
     }
     if (TrafficOn.HasValue)
     {
         parameters.Add("trfc", TrafficOn.Value ? "1" : "0");
     }
     if (RoadView.HasValue)
     {
         parameters.Add("sty", RoadView.Value ? "r" : "a");
     }
     return parameters.ToQueryString("bingmaps://dreamteam-mobile.com/");
 }
 public void ToQueryString()
 {
     var Collection = new Dictionary<string, string>();
     Collection.Add("A", "1");
     Collection.Add("B", "2");
     Assert.Equal("?A=1&B=2", Collection.ToQueryString());
 }
Example #4
0
        public async Task<RootAuth> AuthASync(string login, string password)
        {
            var postData = new Dictionary<string, string>();

            postData.Add("login", login);

            var md5Password = MD5CryptoServiceProvider.GetMd5String(password);

            postData.Add("password", md5Password);

            var options = "?" + postData.ToQueryString();

            RootAuth response;

            try
            {
                response = await Post<RootAuth>(AuthUrl + options, null);

                ValidateResponse(response);
            }
            catch (ConnectionException ex)
            {
                if (!string.IsNullOrEmpty(ex.ResponseContent))
                    ValidateResponse(ex.ResponseContent);

                throw;
            }
            
            return response;
        }
Example #5
0
        public async Task<byte[]> GetEpisodePictureASync(int episodeId, int width, int height)
        {
            var postData = new Dictionary<string, string>();

            postData.Add("id", episodeId);

            if (width != 0)
                postData.Add("width", width);

            if (height != 0)
                postData.Add("height", height);

            postData.Add("picked", "show");

            var options = "?" + postData.ToQueryString();

            var response = await Get(EpisodeUrl + options);

            if (response.StatusCode == HttpStatusCode.NotFound)
                return null;

            var stream = await response.Content.ReadAsBufferAsync();

            var byteArray = stream.ToArray();

            return byteArray.Length == 0 ? null : byteArray;
        }
        public void ToQueryStringOneValue()
        {
            var dict = new Dictionary<string, string>();
            dict["foo"] = "bar";

            Assert.AreEqual("?foo=bar",
                             dict.ToQueryString());
        }
        public void ToQueryStringUnsafeValues()
        {
            var dict = new Dictionary<string, string>();
            dict["foo"] = "#?&%=";

            Assert.AreEqual("?foo=%23%3F%26%25%3D",
                             dict.ToQueryString());
        }
Example #8
0
        /// <summary>
        /// transform a dictionary into the query string that is translated in byte array then
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public static byte[] PostBytes(Dictionary<string, string> items)
        {
            if (items == null || !items.Any())
                return null;

            var bytes = Encoding.UTF8.GetBytes(items.ToQueryString());

            return bytes.Any() ? bytes : null;
        }
        public void ToQueryStringTwoValues()
        {
            var dict = new Dictionary<string, string>();
            dict["foo"] = "bar";
            dict["ba"] = "zinga";

            Assert.AreEqual("?foo=bar&ba=zinga",
                             dict.ToQueryString());
        }
        public void should_convert_string_dictionary_to_query_string()
        {
            var values = new Dictionary<string, string> {
                {"key1", "value1"},
                {"key2", "value2"}
            };

            values.ToQueryString().Should().Be("key1=value1&key2=value2");
        }
        public void should_encode_values()
        {
            var values = new Dictionary<string, string> {
                {"name", "John Smith"},
                {"email", "[email protected]"}
            };

            values.ToQueryString(encode: true)
                .Should().Be("name=John+Smith&email=email%40website.com");
        }
        public void should_override_default_delimiters_when_writing()
        {
            var values = new Dictionary<string, string> {
                {"key1", "value1"},
                {"key2", "value2"}
            };

            values.ToQueryString(paramDelimiter: ' ', valueDelimiter: '@')
                .Should().Be("[email protected] [email protected]");
        }
Example #13
0
        public static void InitContent(dynamic viewBag, string nameSpace, string page, Dictionary<string, string> dimensions)
        {
            var repository = new ContentRepository(
                new Uri(System.Configuration.ConfigurationManager.AppSettings["NeuCMSServiceURL"])
                );

            var content = repository.GetViewContents(nameSpace,page, dimensions.ToQueryString()).ToList();

            dynamic neuCMSContent = new NeuCMSContent(content);
            viewBag.NeuContent = neuCMSContent;
        }
Example #14
0
        public static string GetObjectUrl(string storageUrl, string containerId, string objectId, Dictionary<string, string> queryParams = null)
        {
            var url = storageUrl + "/" + containerId.Encode() + "/" + objectId.Encode();

            if (queryParams != null)
            {
                url += queryParams.ToQueryString();
            }

            return url;
        }
Example #15
0
        public static string GetAccountUrl(string storageUrl, Dictionary<string, string> queryParams = null)
        {
            var url = storageUrl;

            if (queryParams != null)
            {
                url += queryParams.ToQueryString();
            }

            return url;
        }
        public void NoCredentials()
        {
            var values = new Dictionary<string, string>
            {
                { "realm", rp }
            };

            var client = new HttpClient();

            var result = client.GetAsync(baseAddress + values.ToQueryString()).Result;
            Assert.AreEqual<HttpStatusCode>(HttpStatusCode.Unauthorized, result.StatusCode);
        }
        public void MalformedRealm()
        {
            var values = new Dictionary<string, string>
            {
                { "realm", "malformed" }
            };

            var client = new HttpClient();

            var result = client.GetAsync(baseAddress + values.ToQueryString()).Result;
            Assert.AreEqual<HttpStatusCode>(HttpStatusCode.BadRequest, result.StatusCode);
        }
Example #18
0
        public async Task<bool> UnArchiveASync(int showId)
        {
            var postData = new Dictionary<string, string>();

            postData.Add("id", showId);

            var options = "?" + postData.ToQueryString();

            await Delete(ArchiveUrl + options);

            return true;
        }
Example #19
0
        public void Test()
        {

            var entity = EncryptServerHelper.ShowEncrypt("o8KB3uBl_0QJFEpnFUCnyYMPpZ9Y", "9EAFA395-3AFC-4D41-93CD-F801FBF8C8A3");
            var dictionary = new Dictionary<object, object>
                        {
                            {"Encrypt",entity.Encrypt},
                            {"Sign",entity.Sign},
                        };
            var postDataStr = dictionary.ToQueryString();
            var requset = WebHelper.WebFormPost("http://hyinvite.21move.net/api/BindingUnbundling/", postDataStr);
        }
        public Task<string> GeneratePasswordAsync(int minLength, int maxLength)
        {
            var url = "api/v1/accounts/generated-passwords";
            var dico = new Dictionary<string, string>()
            {
                { "minLength", minLength.ToString() },
                { "maxLength", maxLength.ToString() },
            };
            url = url + "?" + dico.ToQueryString();

            return this.PostWithResultAsync<string>(url, null);
        }
        public void MalformedRealm()
        {
            var values = new Dictionary<string, string>
            {
                { "realm", "malformed" }
            };

            var client = new HttpClient();
            client.SetBasicAuthenticationHeader(Constants.Credentials.ValidUserName, Constants.Credentials.ValidPassword);

            var result = client.GetAsync(baseAddress + values.ToQueryString()).Result;
            Assert.AreEqual<HttpStatusCode>(HttpStatusCode.BadRequest, result.StatusCode);
        }
Example #22
0
		public async Task<Message> DeleteASync(int id)
		{
			var postData = new Dictionary<string, string>();

			postData.Add("id", id);

			var options = "?" + postData.ToQueryString();

			var response = await Delete<RootMessage>(SendDeleteUrl + options);

			ValidateResponse(response);

			return response.Message;
		}
Example #23
0
        public async Task<IList<Show>> SearchASync(string title)
        {
            var postData = new Dictionary<string, string>();

            postData.Add("title", title);

            var options = "?" + postData.ToQueryString();

            var response = await Get<ShowList>(SearchUrl + options);

            ValidateResponse(response);

            return response.Shows;
        }
Example #24
0
		public async Task<IList<Message>> GetDiscussionASync(int id)
		{
			var postData = new Dictionary<string, string>();

			postData.Add("id", id);

			var options = "?" + postData.ToQueryString();

			var response = await Get<MessageList>(DiscussionUrl + options);

			ValidateResponse(response);

			return response.Messages;
		}
Example #25
0
		public async Task<Comment> DeleteAsync(int commentId)
		{
			var postData = new Dictionary<string, string>();

			postData.Add("id", commentId);

			var options = "?" + postData.ToQueryString();

			var response = await Delete<RootComment>(DeleteUrl + options);

			ValidateResponse(response);

			return response.Comment;
		}
Example #26
0
        public async Task<string> GenerateIframeTagAsync(int id, Models.Products.EmbedGenerateModel features)
        {
            var parameters = new Dictionary<string, string>();
            this.generateParameters(parameters, features);

            var queryString = parameters.ToQueryString();
            var url = ApiUrls.EmbedUrl.Replace("{id}", id.ToString());
            if (!string.IsNullOrEmpty(queryString))
                url = url + "?" + queryString;
            var model = await this.GetAsync<Models.Products.EmbedResponse>(url);
            if (model == null)
                return string.Empty;
            return model.Content;
        }
Example #27
0
		public async Task<Member> BlockASync(int memberId)
		{
			var postData = new Dictionary<string, string>();

			postData.Add("id", memberId);

			var options = "?" + postData.ToQueryString();

			var response = await Post<RootMember>(BlockUnblockUrl + options, null);

			ValidateResponse(response);

			return response.Member;
		}
Example #28
0
		public async Task<Member> RemoveASync(int memberId)
		{
			var postData = new Dictionary<string, string>();

			postData.Add("id", memberId);

			var options = "?" + postData.ToQueryString();

			var response = await Delete<RootMember>(AddRemoveUrl + options);

			ValidateResponse(response);

			return response.Member;
		}
 public async Task<ProductCommentsOutput> GetCommentsAsync(int productId, int skip = 0, int take = 5, int repliesTake = 3)
 {
     var url = "api/v1/products/" + productId + "/comments";
     var dico = new Dictionary<string, string>(){
         { "skip", skip.ToString() },
         { "take", take.ToString() },
         { "repliesTake", repliesTake.ToString() }
     };
     url = url + "?" + dico.ToQueryString();
     var model = await this.GetAsync<ProductCommentsOutput>(url);
     if (model == null)
         return new ProductCommentsOutput() { Count = -1, Comments = Enumerable.Empty<ProductCommentOutput>() };
     return model;
 }
        public void ValidUserNameCredential()
        {
            var values = new Dictionary<string, string>
            {
                { "realm", rp }
            };

            var client = new HttpClient();
            client.SetBasicAuthenticationHeader(Constants.Credentials.ValidUserName, Constants.Credentials.ValidPassword);

            var result = client.GetAsync(baseAddress + values.ToQueryString()).Result;
            
            Assert.AreEqual<HttpStatusCode>(HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual<string>("application/json", result.Content.Headers.ContentType.MediaType);
        }