public async Task Update(string id, string accesstoken, string url = null, DateTime?Expires = null, bool BlockiFrame = false) { var jsonObj = new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); if (!string.IsNullOrWhiteSpace(url)) { jsonObj.Add("Url", url); } if (Expires.HasValue) { jsonObj.Add("Expires", Expires.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture)); } if (BlockiFrame) { jsonObj.Add("BlockiFrame", BlockiFrame.ToString().ToLowerInvariant()); } var response = await httpClient.PutAsync(string.Format("{0}?accesstoken={1}", id, accesstoken), new StringContent(jsonObj.ToJSON(0), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new Exception(await response.Content.ReadAsStringAsync()); } }
public async Task Update(string id,string accesstoken,string url=null, DateTime? Expires=null, bool BlockiFrame = false) { var jsonObj = new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); if(!string.IsNullOrWhiteSpace(url)) jsonObj.Add("Url", url); if (Expires.HasValue) jsonObj.Add("Expires", Expires.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture)); if (BlockiFrame) jsonObj.Add("BlockiFrame", BlockiFrame.ToString().ToLowerInvariant()); var response = await httpClient.PutAsync(string.Format("{0}?accesstoken={1}", id, accesstoken), new StringContent(jsonObj.ToJSON(0), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) throw new Exception(await response.Content.ReadAsStringAsync()); }
public void TestSimpleJsonParse() { var response = Signere.no.UrlShortner.Client.SimpleJSON.JSON.Parse( "{\"ShortUrl\":\"http://urlshortner.azurewebsites.net/olpxDWHszd\",\"AccessToken\":\"O2HHKkySwX19\",\"Id\":\"olpxDWHszd\"}") ; ; Console.WriteLine(response.ToString()); var tmp=new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); tmp.Add("Url", "http://wiki.unity3d.com/index.php/SimpleJSON"); tmp.Add("Expires",DateTime.UtcNow.AddDays(1).ToString("s", System.Globalization.CultureInfo.InvariantCulture)); tmp.Add("BlockiFrame",true.ToString().ToLowerInvariant()); Console.WriteLine(tmp.ToJSON(0)); }
public void TestSimpleJsonParse() { var response = Signere.no.UrlShortner.Client.SimpleJSON.JSON.Parse( "{\"ShortUrl\":\"http://urlshortner.azurewebsites.net/olpxDWHszd\",\"AccessToken\":\"O2HHKkySwX19\",\"Id\":\"olpxDWHszd\"}") ; ; Console.WriteLine(response.ToString()); var tmp = new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); tmp.Add("Url", "http://wiki.unity3d.com/index.php/SimpleJSON"); tmp.Add("Expires", DateTime.UtcNow.AddDays(1).ToString("s", System.Globalization.CultureInfo.InvariantCulture)); tmp.Add("BlockiFrame", true.ToString().ToLowerInvariant()); Console.WriteLine(tmp.ToJSON(0)); }
public async Task<UrlEntityResponse> Create(string url, DateTime? Expires = null, bool BlockiFrame = false, bool permanentRedirect = false, string prefix = null, string accessToken = null) { var jsonObj = new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); jsonObj.Add("Url",url); if(Expires.HasValue) jsonObj.Add("Expires", Expires.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture)); if(permanentRedirect) jsonObj.Add("PermanentRedirect", new SimpleJSON.JSONData(true)); if (BlockiFrame) jsonObj.Add("BlockiFrame", new SimpleJSON.JSONData(true)); if (!string.IsNullOrWhiteSpace(accessToken)) jsonObj.Add("AccessToken",accessToken); if (!string.IsNullOrWhiteSpace(prefix)) jsonObj.Add("Prefix", prefix); var response=await httpClient.PostAsync("",new StringContent(jsonObj.ToJSON(0), Encoding.UTF8,"application/json")); if(!response.IsSuccessStatusCode) throw new ApplicationException("Error creating short url: "+ response.StatusCode + " "+ await response.Content.ReadAsStringAsync()); var responseJson = SimpleJSON.JSON.Parse(await response.Content.ReadAsStringAsync()); return new UrlEntityResponse() {AccessToken = responseJson["AccessToken"],Id= responseJson["Id"],ShortUrl = responseJson["ShortUrl"]}; }
public async Task <UrlEntityResponse> Create(string url, DateTime?Expires = null, bool BlockiFrame = false, bool permanentRedirect = false, string prefix = null, string accessToken = null) { var jsonObj = new Signere.no.UrlShortner.Client.SimpleJSON.JSONClass(); jsonObj.Add("Url", url); if (Expires.HasValue) { jsonObj.Add("Expires", Expires.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture)); } if (permanentRedirect) { jsonObj.Add("PermanentRedirect", new SimpleJSON.JSONData(true)); } if (BlockiFrame) { jsonObj.Add("BlockiFrame", new SimpleJSON.JSONData(true)); } if (!string.IsNullOrWhiteSpace(accessToken)) { jsonObj.Add("AccessToken", accessToken); } if (!string.IsNullOrWhiteSpace(prefix)) { jsonObj.Add("Prefix", prefix); } var response = await httpClient.PostAsync("", new StringContent(jsonObj.ToJSON(0), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new ApplicationException("Error creating short url: " + response.StatusCode + " " + await response.Content.ReadAsStringAsync()); } var responseJson = SimpleJSON.JSON.Parse(await response.Content.ReadAsStringAsync()); return(new UrlEntityResponse() { AccessToken = responseJson["AccessToken"], Id = responseJson["Id"], ShortUrl = responseJson["ShortUrl"] }); }