public user getUser() throws IOException, URISyntaxException { URI uri = new URI("http://api.huddle.dev/" + "entry/"); HttpGet httpget = new HttpGet(uri); httpget.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); HttpResponse response = httpClient.execute(httpget); user user; user = xml.parseXmlUser(response.getEntity().getContent()); return user; }
@Override public void createFolder(URI uri, String name, String desc) throws IOException { HttpPost httpPost = new HttpPost(uri); httpPost.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); httpPost.addHeader("Content-Type", "application/vnd.huddle.data+xml"); // set the body to post StringEntity entity = new StringEntity("<folder title=" + name + " description=" + desc + "/>"); httpPost.setEntity(entity); httpClient.execute(httpPost); }
@Override public folder getFolders(URI uri) throws IOException { HttpGet httpget = new HttpGet(uri); httpget.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); HttpResponse response = httpClient.execute(httpget); folder folder; folder = xml.parseXmlFolder(response.getEntity().getContent()); return folder; }
@Override public void uploadToFile(URI document, File file) throws IOException { HttpPut httpPut = new HttpPut(document); httpPut.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); httpPut.addHeader("Content-Type", "multipart/form-data"); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("filename", new FileBody(file)); httpPut.setEntity(entity); httpClient.execute(httpPut); }
@Override public document createFile(URI uri, String name, String desc) throws IOException { HttpPost httpPost = new HttpPost(uri); httpPost.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); httpPost.addHeader("Content-Type", "application/vnd.huddle.data+xml"); // set the body to post StringEntity entity = new StringEntity( "<document title=" + "\"" + name + "\"" + " description=" + "\"" + desc + "\"" + "/>"); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost); document document = xml.parseXmlDocuments(response.getEntity().getContent()); return document; }
@Override public void deleteContent(URI uri) throws IOException { HttpDelete httpDelete = new HttpDelete(uri); httpDelete.addHeader("Authorization", "OAuth2 " + tokenClient.getAccessToken()); httpClient.execute(httpDelete); }