public RestAPIResponse Ingest(string endpoint, dynamic data, Method method = Method.POST) { RestClient client; client = new RestClient(_baseUrl); client.Authenticator = _auth; client.UserAgent = _userAgent; var request = new RestRequest(endpoint, method); RestAPIResponse result = null; if (data != null) { request.AddParameter("application/json", APIHelpers.SerializeToJsonLD(data), ParameterType.RequestBody); } IRestResponse response = client.Execute(request); result = new RestAPIResponse() { RateLimit = APIHelpers.ParseRateLimitHeaders(response.Headers), StatusCode = response.StatusCode }; result.Data = APIHelpers.DeserializeResponse(response.Content); switch ((int)response.StatusCode) { // Ok status codes case 200: case 201: case 202: case 204: break; //Error status codes case 400: case 401: case 403: case 404: case 405: case 409: case 413: case 416: case 500: case 503: throw new RestAPIException(result, (APIHelpers.HasAttr(result.Data, "error")) ? result.Data.error : "The request failed, please see the Data & StatusCode properties for more details."); case 429: throw new TooManyRequestsException(result, (APIHelpers.HasAttr(result.Data, "error")) ? result.Data.error : "The request failed because you've exceeded your API request limit."); } return(result); }
public RestAPIResponse Ingest(string endpoint, dynamic data, Method method = Method.POST) { string response = null; RestAPIResponse result = new RestAPIResponse(); string body = APIHelpers.SerializeToJsonLD(data); response = "{\"accepted\":1, \"total_message_bytes\": 1691 }"; result.StatusCode = HttpStatusCode.OK; result.Data = APIHelpers.DeserializeResponse(response); return(result); }