@Override public RequestURI set(final URI uri) { return new SearchURI(this.address.set(uri)); } @Override
final String response = this.request .uri() .set( URI.create( new Href(PsFacebook.ACCESS_TOKEN_URL)
final String response = this.request .uri() .set( URI.create( new Href(PsFacebook.ACCESS_TOKEN_URL)
/** * Jump to a new location. * @param uri Destination to jump to * @return New request */ @SuppressWarnings("PMD.UseConcurrentHashMap") public Request jump(final URI uri) { Request req = this.back().uri() .set(this.back().uri().get().resolve(uri)) .back(); final Map<String, List<String>> headers = this.headers(); if (headers.containsKey(HttpHeaders.SET_COOKIE)) { for (final String header : headers.get(HttpHeaders.SET_COOKIE)) { for (final HttpCookie cookie : HttpCookie.parse(header)) { req = req.header( HttpHeaders.COOKIE, String.format( "%s=%s", cookie.getName(), cookie.getValue() ) ); } } } return req; }
/** * Get user name from Twitter, with the token provided. * @param tkn Twitter access token * @return The user found in Twitter * @throws IOException If fails */ private Identity identity(final String tkn) throws IOException { return parse( this.user .uri() .set( URI.create( new Href(PsTwitter.VERIFY_URL) .with(PsTwitter.ACCESS_TOKEN, tkn) .toString() ) ) .back() .header("accept", "application/json") .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class) .json() .readObject() ); }
/** * Get user name from Twitter, with the token provided. * @param tkn Twitter access token * @return The user found in Twitter * @throws IOException If fails */ private Identity identity(final String tkn) throws IOException { return parse( this.user .uri() .set( URI.create( new Href(PsTwitter.VERIFY_URL) .with(PsTwitter.ACCESS_TOKEN, tkn) .toString() ) ) .back() .header("accept", "application/json") .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class) .json() .readObject() ); }
@Override public ReleaseAsset upload( final byte[] content, final String type, final String name ) throws IOException { return this.get( this.request.uri() .set(URI.create("https://uploads.github.com")) .path("/repos") .path(this.owner.repo().coordinates().user()) .path(this.owner.repo().coordinates().repo()) .path("/releases") .path(String.valueOf(this.owner.number())) .path("/assets") .queryParam("name", name) .back() .method(Request.POST) .reset(HttpHeaders.CONTENT_TYPE) .header(HttpHeaders.CONTENT_TYPE, type) .body().set(content).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readObject().getInt("id") ); }