/** * A thin wrapper around the HTTP methods. */ public Response api(Request request) throws IOException { try { if (request.getMethod() == null) { throw new IOException("We only support GET, PUT, PATCH, POST and DELETE."); } switch (request.getMethod()) { case GET: return get(request); case POST: return post(request); case PUT: return put(request); case PATCH: return patch(request); case DELETE: return delete(request); default: throw new IOException("We only support GET, PUT, PATCH, POST and DELETE."); } } catch (IOException ex) { throw ex; } catch (URISyntaxException ex) { StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); throw new IOException(errors.toString()); } }
/** * Class api sets up the request to the SendGrid API, this is main interface. * @param request the request object. * @return the response object. * @throws IOException in case of a network error. */ public Response api(Request request) throws IOException { Request req = new Request(); req.setMethod(request.getMethod()); req.setBaseUri(this.host); req.setEndpoint("/" + version + "/" + request.getEndpoint()); req.setBody(request.getBody()); for (Map.Entry<String, String> header : this.requestHeaders.entrySet()) { req.addHeader(header.getKey(), header.getValue()); } for (Map.Entry<String, String> queryParam : request.getQueryParams().entrySet()) { req.addQueryParam(queryParam.getKey(), queryParam.getValue()); } return makeCall(req); }
/** * Class api sets up the request to the SendGrid API, this is main interface. * @param request the request object. * @return the response object. * @throws IOException in case of a network error. */ public Response api(Request request) throws IOException { Request req = new Request(); req.setMethod(request.getMethod()); req.setBaseUri(this.host); req.setEndpoint("/" + version + "/" + request.getEndpoint()); req.setBody(request.getBody()); for (Map.Entry<String, String> header : this.requestHeaders.entrySet()) { req.addHeader(header.getKey(), header.getValue()); } for (Map.Entry<String, String> queryParam : request.getQueryParams().entrySet()) { req.addQueryParam(queryParam.getKey(), queryParam.getValue()); } return makeCall(req); }