/// <summary> /// Calls the CatApi and returns a list of images. /// </summary> /// <param name="request">A <see cref="GetRequestBuilder"/> object containing request parameters.</param> /// <exception cref="InvalidRequestException">Thrown if any required parameters are null.</exception> /// <returns>A list of cat images :D</returns> public IEnumerable <GetResponse.Image> GetImages(GetRequestBuilder request) { var uri = request.Build(); var response = Get <GetResponse.Response>(uri); return(response.Data.Images); }
public void GetGreeting_Sync_ServerError() { RestClient client = new RestClient(urlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(-1); GetRequest <int, Greeting> request = requestBuilder.Build(); try { EntityResponse <Greeting> response = client.RestRequestSync(request); } catch (RestliException e) { Assert.IsNotNull(e.Message); Assert.IsNull(e.InnerException); ErrorResponse details = e.details; Assert.IsNotNull(details); Assert.AreEqual(400, details.status); Assert.AreEqual("Negative key.", details.message); Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", details.exceptionClass); Assert.IsTrue(details.hasStackTrace); return; } Assert.Fail("Rest request should throw RestliException"); }
public void BuildComplexUrl_Get() { string expected = String.Format("http://testprefix/foo/1/bar/List(foo,2,3)/baz/(deeper:List(found,it,{0}))/biz/123", complexStringEscapedPath); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("foo/{one}/bar/{list}/baz/{complex}/biz"); requestBuilder.SetID(123); requestBuilder.SetPathKey("one", 1); requestBuilder.SetPathKey("list", new List <object>() { "foo", 2, 3 }); requestBuilder.SetPathKey("complex", new Dictionary <string, object>() { { "deeper", new List <object>() { "found", "it", complexString } } }); GetRequest <int, Greeting> request = requestBuilder.Build(); RequestUrlBuilder <EntityResponse <Greeting> > urlBuilder = new RequestUrlBuilder <EntityResponse <Greeting> >(request, "http://testprefix"); Uri url = urlBuilder.Build(); Assert.AreEqual(expected, url.AbsoluteUri); }
private string GetSignature(DateTime utcNow) { GetRequestBuilder builder = new GetRequestBuilder(_builder); builder.AddParam(_tKey, utcNow.ToString("s")); string signature = _signer.Sign(Constants.GET_METHOD, Host, Path, builder.Build()); return(signature); }
public void GetGreeting_Async_ServerError() { RestClient client = new RestClient(urlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(-1); GetRequest <int, Greeting> request = requestBuilder.Build(); AutoResetEvent blocker = new AutoResetEvent(false); Greeting greeting = null; ClientErrorResponse errorResponse = null; RestliCallback <EntityResponse <Greeting> > .SuccessHandler successHandler = delegate(EntityResponse <Greeting> response) { greeting = response.element; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > .ErrorHandler errorHandler = delegate(ClientErrorResponse response) { errorResponse = response; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > callback = new RestliCallback <EntityResponse <Greeting> >(successHandler, errorHandler); client.RestRequestAsync(request, callback); blocker.WaitOne(); Assert.IsNull(greeting); Assert.IsNotNull(errorResponse); Assert.AreEqual(400, errorResponse.status); RestliException error = errorResponse.error; Assert.IsNotNull(error); Assert.IsNotNull(error.Message); Assert.IsNull(error.InnerException); ErrorResponse details = error.details; Assert.IsNotNull(details); Assert.AreEqual(400, details.status); Assert.AreEqual("Negative key.", details.message); Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", details.exceptionClass); Assert.IsTrue(details.hasStackTrace); }
public override string Build(string method, string path, DateTime utcDateTime, GetRequestBuilder request) { string strDateTime = utcDateTime.ToString("s"); var req = new GetRequestBuilder(request) .AddParam(Constants.AKey, _accessKey) .AddParam(Constants.SMKey, Constants.SMValue) .AddParam(Constants.SVKey, Constants.SVValue) .AddParam(Constants.TKey, strDateTime); string param = req.Build(); string signature = _signer.Sign(method, _host, path, param); string url = $"http://{_host}{path}?{param}&{Constants.SKey}={Uri.EscapeDataString(signature)}"; return(url); }
public void GetGreeting_Sync() { RestClient client = new RestClient(urlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(123); GetRequest <int, Greeting> request = requestBuilder.Build(); EntityResponse <Greeting> response = client.RestRequestSync(request); Greeting greeting = response.element; Assert.IsNotNull(greeting); Assert.AreEqual(123, greeting.id); Assert.AreEqual(Tone.Symbol.SINCERE, greeting.tone.symbol); Assert.AreEqual("Hello World!", greeting.message); }
public void GetGreeting_Async_HttpError() { RestClient client = new RestClient(badUrlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(123); GetRequest <int, Greeting> request = requestBuilder.Build(); AutoResetEvent blocker = new AutoResetEvent(false); Greeting greeting = null; ClientErrorResponse errorResponse = null; RestliCallback <EntityResponse <Greeting> > .SuccessHandler successHandler = delegate(EntityResponse <Greeting> response) { greeting = response.element; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > .ErrorHandler errorHandler = delegate(ClientErrorResponse response) { errorResponse = response; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > callback = new RestliCallback <EntityResponse <Greeting> >(successHandler, errorHandler); client.RestRequestAsync(request, callback); blocker.WaitOne(); Assert.IsNull(greeting); Assert.IsNotNull(errorResponse); Assert.AreEqual(500, errorResponse.status); Assert.IsNotNull(errorResponse.error); Assert.IsNull(errorResponse.error.details); Assert.IsNotNull(errorResponse.error.Message); Assert.IsNotNull(errorResponse.error.InnerException); }
public void GetGreeting_Sync_HttpError() { RestClient client = new RestClient(badUrlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(123); GetRequest <int, Greeting> request = requestBuilder.Build(); try { EntityResponse <Greeting> response = client.RestRequestSync(request); } catch (RestliException e) { Assert.IsNull(e.details); Assert.IsNotNull(e.Message); Assert.IsNotNull(e.InnerException); return; } Assert.Fail("Rest request should throw RestliException"); }
public void GetGreeting_Async() { RestClient client = new RestClient(urlPrefix); GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection"); requestBuilder.SetID(123); GetRequest <int, Greeting> request = requestBuilder.Build(); AutoResetEvent blocker = new AutoResetEvent(false); Greeting greeting = null; ClientErrorResponse errorResponse = null; RestliCallback <EntityResponse <Greeting> > .SuccessHandler successHandler = delegate(EntityResponse <Greeting> response) { greeting = response.element; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > .ErrorHandler errorHandler = delegate(ClientErrorResponse response) { errorResponse = response; blocker.Set(); }; RestliCallback <EntityResponse <Greeting> > callback = new RestliCallback <EntityResponse <Greeting> >(successHandler, errorHandler); client.RestRequestAsync(request, callback); blocker.WaitOne(asyncTimeoutMillis); Assert.IsNull(errorResponse); Assert.IsNotNull(greeting); Assert.AreEqual(123, greeting.id); Assert.AreEqual(Tone.Symbol.SINCERE, greeting.tone.symbol); Assert.AreEqual("Hello World!", greeting.message); }