use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method deletePlaylist.
/*****************************************************************************
* Creates a JSONObject object that contains the delete command for the
* specified playlist and adds it to the JSONArray that will pass the the
* command on to Google's servers.
*
* @param context The context to use while deleting the playlist.
* @param playlistId The playlistId of the playlist to delete.
* @throws JSONException
* @throws IllegalArgumentException
*****************************************************************************/
public static final String deletePlaylist(Context context, String playlistId) throws JSONException, IllegalArgumentException {
JSONObject jsonParam = new JSONObject();
JSONArray mutationsArray = new JSONArray();
mutationsArray.put(new JSONObject().put("delete", playlistId));
jsonParam.put("mutations", mutationsArray);
mHttpClient.setUserAgent(mMobileClientUserAgent);
String result = mHttpClient.post(context, "https://www.googleapis.com/sj/v1.1/playlistbatch?alt=json&hl=en_US", new ByteArrayEntity(jsonParam.toString().getBytes()), "application/json");
mHttpClient.setUserAgent(mWebClientUserAgent);
return result;
}
use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method reorderPlaylistEntryWebClient.
/**************************************************************************************
* Reorders the specified song (within the specified playlist) to a new position.
*
* @param context The context to use during the reordering process.
* @param playlistId The id of the playlist which contains the song to be reordered.
* @param movedSongId The id of the song that is being reordered.
* @param movedEntryId The entryId of the song that is being reordered.
* @param afterEntryId The entryId of the song that is before the new position.
* @param beforeEntryId The entryId of the song that is after the new position.
* @return Returns the JSON response of the reorder task.
* @throws JSONException
**************************************************************************************/
public static final String reorderPlaylistEntryWebClient(Context context, String playlistId, ArrayList<String> movedSongId, ArrayList<String> movedEntryId, String afterEntryId, String beforeEntryId) throws JSONException {
JSONObject jsonParam = new JSONObject();
jsonParam.put("playlistId", playlistId);
jsonParam.put("movedSongIds", movedSongId);
jsonParam.put("movedEntryIds", movedEntryId);
jsonParam.put("afterEntryId", afterEntryId);
jsonParam.put("beforeEntryId", beforeEntryId);
String jsonParamString = jsonParam.toString();
jsonParamString = jsonParamString.replace("\"[", "[\"");
jsonParamString = jsonParamString.replace("]\"", "\"]");
JSONForm form = new JSONForm();
form.addField("json", jsonParamString);
form.close();
String result = mHttpClient.post(context, "https://play.google.com/music/services/changeplaylistorder?u=0&xt=" + getXtCookieValue(), new ByteArrayEntity(form.toString().getBytes()), form.getContentType());
return result;
}
use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method getSongs.
/***************************************************************************************
* <p>
* Queries Google's servers for a list of all songs in the current Google account's
* music library.
* </p>
*
* @deprecated The use of this method is highly discouraged as it sends/fetches large
* amounts of data from Google's servers. All of this data is readily available via the
* Google Play Music app's public ContentProvider. This method uses the WebClient
* endpoint.
*
* @param context The context to use during the download process.
* @param continuationToken The token that will return the next set of songs (only 1000
* songs are returned per request).
* @return
* @throws JSONException
***************************************************************************************/
public static final ArrayList<WebClientSongsSchema> getSongs(Context context, String continuationToken) throws JSONException {
JSONForm form = new JSONForm();
form.addField("json", "{\"continuationToken\":\"" + continuationToken + "\"}");
form.close();
String response = mHttpClient.post(context, "https://play.google.com/music/services/loadalltracks?u=0&xt=" + getXtCookieValue(), new ByteArrayEntity(form.toString().getBytes()), form.getContentType());
JSONObject jsonObject = new JSONObject(response);
WebClientPlaylistsSchema playlist = new WebClientPlaylistsSchema().fromJsonObject(jsonObject);
ArrayList<WebClientSongsSchema> chunkedSongList = new ArrayList<WebClientSongsSchema>();
chunkedSongList.addAll(playlist.getPlaylist());
if (!TextUtils.isEmpty(playlist.getContinuationToken())) {
chunkedSongList.addAll(getSongs(context, playlist.getContinuationToken()));
}
return chunkedSongList;
}
use of org.apache.http.entity.ByteArrayEntity in project platformlayer by platformlayer.
the class MetricClientImpl method sendMetrics.
// TODO: Throw on failure??
@Override
public boolean sendMetrics(MetricTreeObject tree) {
if (tags != null) {
tree.mergeTree(tags);
}
URI url = metricBaseUrl.resolve("api/metric/").resolve(project);
HttpPost request = new HttpPost(url);
HttpResponse response = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
metricTreeSerializer.serialize(tree, baos);
baos.close();
byte[] data = baos.toByteArray();
log.debug("POSTing " + new String(data));
// TODO: Stream body? We'd just need a custom ByteArrayEntity class
request.setEntity(new ByteArrayEntity(data));
response = httpClient.execute(request);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != 200) {
log.warn("Error writing to PlatformLayer metrics server: " + statusLine);
return false;
} else {
EntityUtils.consume(response.getEntity());
response = null;
// consumeResponse(request, response);
log.debug("Posted metrics");
return true;
}
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug("Error writing to PlatformLayer metrics server", e);
}
log.warn("Error writing to PlatformLayer metrics server {}", e.getMessage());
return false;
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.warn("Error consuming response", e);
}
}
}
}
use of org.apache.http.entity.ByteArrayEntity in project voldemort by voldemort.
the class HttpStore method executeRequest.
private DataInputStream executeRequest(HttpPost method, ByteArrayOutputStream output) {
HttpResponse response = null;
try {
method.setEntity(new ByteArrayEntity(output.toByteArray()));
response = httpClient.execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpURLConnection.HTTP_OK) {
String message = response.getStatusLine().getReasonPhrase();
VoldemortIOUtils.closeQuietly(response);
throw new UnreachableStoreException("HTTP request to store " + getName() + " returned status code " + statusCode + " " + message);
}
return new DataInputStream(response.getEntity().getContent());
} catch (IOException e) {
VoldemortIOUtils.closeQuietly(response);
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for " + getName(), e);
}
}
Aggregations