public string GetShortURL(string longUrl) { var jsonCoverter = new JsonUtcConverter(); WebRequest request = WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyCdO7g2yHUU_CyufRND_MWvQmPubImrb2g"); request.Method = "POST"; request.ContentType = "application/json"; var jsonData = jsonCoverter.Serilize(new GoogleUrlShortnerMessage { longUrl = longUrl }); string requestData = jsonData; byte[] requestRawData = Encoding.ASCII.GetBytes(requestData); request.ContentLength = requestRawData.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(requestRawData, 0, requestRawData.Length); requestStream.Close(); WebResponse response = request.GetResponse(); StreamReader responseReader = new StreamReader(response.GetResponseStream()); string responseData = responseReader.ReadToEnd(); responseReader.Close(); var shortnerResult = JsonConvert.DeserializeObject <GoogleUrlShortnerResponse>(responseData); return(shortnerResult.id); }
public ActionResult sampleSend() { var jsonCoverter = new JsonUtcConverter(); var testClass = new SimpleTestClassForJsonNetConverterTest(); testClass.Date = new DateTime(2013, 1, 2, 3, 4, 5); testClass.Lead = 250; return(Content(jsonCoverter.Serilize(testClass), "application/json")); }
public void CanSerilize() { var jsonCoverter = new JsonUtcConverter(); var testClass = new SimpleTestClassForJsonNetConverterTest(); testClass.Date = new DateTime(2013, 1, 2, 3, 4, 5); testClass.String = "test string"; var result = jsonCoverter.Serilize(testClass); Assert.AreEqual("{\"Date\":\"2013-01-02T03:04:05Z\",\"String\":\"test string\"}", result); }
public ActionResult SendSms() { var jsonCoverter = new JsonUtcConverter(); var tokenRepository = new Repository <Token>(db => context.Token, context); var userRepository = new Repository <InsideUser>(db => context.InsideUser, context); var accessTokenProvider = new AccessTokenProvider(tokenRepository, userRepository); var url = accessTokenProvider.GenerateAccessUrl(User.Identity.GetUserId(), "/report/" + 10 + "/contact/" + 111818); var shortUrl = GetShortURL(url); string AccountSid = "ACf527710731ad6e3852be97b937c418b5"; string AuthToken = "51653777a7b97d349e0da8cb966359a1"; var twilio = new TwilioRestClient(AccountSid, AuthToken); var message = twilio.SendMessage("+46769438884", "0722524969", "Du har fått ett nytt telefonsamtal från 0722524969: " + shortUrl); return(Content(jsonCoverter.Serilize(message), "application/json")); }