@Override public Request header(final String name, final Object value) { return this.base.header(name, value); }
@Override public Request header(final String name, final Object value) { return this.base.header(name, value); }
@Override public Request header(final String name, final Object value) { return this.base.header(name, value); }
/** * Public ctor, for authentication with OAuth2 token. * @param token OAuth token */ public RtGithub( final String token) { this( RtGithub.REQUEST.header( HttpHeaders.AUTHORIZATION, String.format("token %s", token) ) ); }
@Override public Request header(final String name, final Object value) { return new SearchRequest(this.request.header(name, value)); } @Override
/** * Public ctor. * @param uri Home page URI * @param token Authentication token */ public RtUser(@NotNull final URI uri, @NotNull final String token) { this.request = new JdkRequest(uri) .through(CookieOptimizingWire.class) .header(HttpHeaders.COOKIE, String.format("PsCookie=%s", token)) .header(HttpHeaders.ACCEPT, MediaType.TEXT_XML); }
/** * Public ctor, for HTTP Basic Authentication. * @param user User name * @param pwd Password * @since 0.4 */ public RtGithub( final String user, final String pwd) { this( RtGithub.REQUEST.header( HttpHeaders.AUTHORIZATION, String.format( "Basic %s", DatatypeConverter.printBase64Binary( String.format("%s:%s", user, pwd) .getBytes(StandardCharsets.UTF_8) ) ) ) ); }
/** * Ctor. * @param urn Owner URN * @param token Security token */ public RtSttc(final URN urn, final String token) { this.request = new JdkRequest("http://www.stateful.co") .through(OneMinuteWire.class) .through(RetryWire.class) .through(VerboseWire.class) .through(CachingWire.class, "((POST|PUT|PATCH) .*|.*\\?.*)") .header("X-Sttc-URN", urn.toString()) .header("X-Sttc-Token", token) .header(HttpHeaders.ACCEPT, MediaType.TEXT_XML) .header(HttpHeaders.USER_AGENT, "java-sdk.stateful.co"); }
/** * Send request and return response. * @param entity The entity to POST * @return The response */ private Request request(final String entity) { return new JdkRequest(this.uri) .method(Request.POST) .body().set(entity).back() .header(HttpHeaders.USER_AGENT, AbstractBaseValidator.USER_AGENT) .header(HttpHeaders.ACCEPT, "application/soap+xml") .header( HttpHeaders.CONTENT_TYPE, Logger.format( "%s; boundary=%s", MediaType.MULTIPART_FORM_DATA, AbstractBaseValidator.BOUNDARY ) ); }
/** * Send request and return response. * @param entity The entity to POST * @return The response */ private Request request(final String entity) { return new JdkRequest(this.uri) .method(Request.POST) .body().set(entity).back() .header(HttpHeaders.USER_AGENT, AbstractBaseValidator.USER_AGENT) .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML) .header( HttpHeaders.CONTENT_TYPE, Logger.format( "%s; charset=%s", MediaType.TEXT_HTML, StandardCharsets.UTF_8 ) ); }
/** * Ctor. * @param req RESTful API entry point */ RtUserEmails(final Request req) { this.request = req.header("Accept", "application/vnd.github.v3") .uri().path("/user/emails").back(); }
@Override public InputStream raw() throws IOException { return new ByteArrayInputStream( this.request.reset(HttpHeaders.ACCEPT) .header( HttpHeaders.ACCEPT, "application/vnd.github.v3.raw" ).fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK).binary() ); } }
/** * Get raw release asset content. * * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a> * @return Stream with content * @throws IOException If some problem inside. */ @Override public InputStream raw() throws IOException { return new ByteArrayInputStream( this.request.method(Request.GET) .reset(HttpHeaders.ACCEPT).header( HttpHeaders.ACCEPT, "application/vnd.github.v3.raw" ) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .binary() ); }
@Override public long incrementAndGet(final long delta) throws IOException { final long start = System.currentTimeMillis(); final long value = Long.parseLong( this.front("increment").method(Request.GET) .uri().queryParam("value", delta).back() .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body() ); Logger.info( this, "counter \"%s\" incremented by %d to %d in %[ms]s", this.label, delta, value, System.currentTimeMillis() - start ); return value; }
@Override public String patch( final String base, final String head) throws IOException { return this.comp.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.patch") .uri() .path(String.format("%s...%s", base, head)) .back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); }
@Override public String diff( final String base, final String head) throws IOException { return this.comp.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.diff") .uri() .path(String.format("%s...%s", base, head)) .back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); }
@Override public String template( final String name) throws IOException { return this.request.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.raw") .uri().path(name).back().fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); } }
@Override public void write(final InputStream stream, final String ctype, final String etag) throws IOException { this.request.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .rel("/page/links/link[@rel='upload']/@href") .uri() .queryParam("name", this.name()) .queryParam("ctype", ctype) .queryParam("etag", etag) .back() .body().set(IOUtils.toByteArray(stream)).back() .method(Request.POST) .header( HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED ) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_SEE_OTHER); Logger.info(this, "attachment '%s' written", this.attachment); }
@Override public String raw( final String text) throws IOException { return this.request .body() .set(text) .back() .uri().path("raw").back() .reset(HttpHeaders.CONTENT_TYPE) .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .assertHeader( HttpHeaders.CONTENT_TYPE, Matchers.everyItem( Matchers.startsWith(MediaType.TEXT_HTML) ) ) .body(); }
/** * Retrieve PsLinkedin access token. * @param home Home of this page * @param code PsLinkedin "authorization code" * @return The token * @throws IOException If failed */ private String token(final String home, final String code) throws IOException { final String uri = this.tkhref.toString(); return new JdkRequest(uri) .method("POST") .header("Accept", "application/xml") .body() .formParam("grant_type", "authorization_code") .formParam("client_id", this.app) .formParam("redirect_uri", home) .formParam("client_secret", this.key) .formParam(PsLinkedin.CODE, code) .back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class) .json().readObject().getString("access_token"); }