public Article createArticle ( final String title , final String description , final String definedType ) { HttpClient httpClient = null ; try { final String method = "my_data/articles" ; // create an HTTP request to a protected resource final String url = getURL ( endpoint , version , method ) ; // create an HTTP request to a protected resource final HttpPost request = new HttpPost ( url ) ; Gson gson = new Gson ( ) ; JsonObject payload = new JsonObject ( ) ; payload . addProperty ( "title" , title ) ; payload . addProperty ( "description" , description ) ; payload . addProperty ( "defined_type" , definedType ) ; String jsonRequest = gson . toJson ( payload ) ; StringEntity entity = new StringEntity ( jsonRequest ) ; entity . setContentType ( JSON_CONTENT_TYPE ) ; request . setEntity ( entity ) ; // sign the request consumer . sign ( request ) ; // send the request httpClient = HttpClientBuilder . create ( ) . build ( ) ; HttpResponse response = httpClient . execute ( request ) ; HttpEntity responseEntity = response . getEntity ( ) ; String json = EntityUtils . toString ( responseEntity ) ; Article article = readArticleFromJson ( json ) ; return article ; } catch ( OAuthCommunicationException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( OAuthMessageSignerException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( OAuthExpectationFailedException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( ClientProtocolException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } catch ( IOException e ) { throw new FigShareClientException ( "Failed to get articles: " + e . getMessage ( ) , e ) ; } }
Create an article .