Copyright (c) 2012 CloudMine LLC, http://cloudmine.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software")...
If you think the Android project cloudmine-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.cloudmine.api.rest;
/*fromwww.java2s.com*/import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.cloudmine.api.CMApiCredentials;
import com.cloudmine.api.CMSessionToken;
import com.cloudmine.api.rest.options.CMServerFunction;
import com.cloudmine.api.rest.response.CMResponse;
import me.cloudmine.annotations.Expand;
import me.cloudmine.annotations.Optional;
import java.util.Map;
/**
* A Request for calling a server side code snippet. For detailed information about our
* server side code environment, view the documentation here: https://cloudmine.me/docs/servercode
* <br>Copyright CloudMine LLC. All rights reserved
* <br> See LICENSE file included with SDK for details.
*/publicclass BaseSnippetRequest extends CloudMineRequest<CMResponse> {
publicstaticfinalint REQUEST_TYPE = 414;
privatestaticfinal String BASE_ENDPOINT = "/run";
privatestatic String getSnippetUrl(String snippetName, Map<String, String> extraParams) {
StringBuilder urlBuilder = new StringBuilder(BASE_ENDPOINT).append("/").append(CMURLBuilder.encode(snippetName));
if(extraParams != null && !extraParams.isEmpty()) {
String separator ="?";
for(Map.Entry<String, String> extraParam : extraParams.entrySet()) {
urlBuilder.append(separator).append(CMURLBuilder.encode(extraParam.getKey())).append("=").append(CMURLBuilder.encode(extraParam.getValue()));
separator = "&";
}
}
return urlBuilder.toString();
}
/**
* Create a new SnippetRequest to run the Java or JavaScript code with the given snippetName
* @param snippetName the name of the snippet to run
* @param extraParams optional parameters that will be passed into the snippet
* @param sessionToken optional, will be passed into the snippet if specified
* @param successListener
* @param errorListener
*/
@Expand
public BaseSnippetRequest(String snippetName, @Optional Map< String, String> extraParams, @Optional CMSessionToken sessionToken, @Optional CMApiCredentials apiCredentials, @Optional Response.Listener<CMResponse> successListener, @Optional Response.ErrorListener errorListener) {
super(Method.GET, getSnippetUrl(snippetName, extraParams), null, sessionToken, apiCredentials, (CMServerFunction)null, successListener, errorListener);
}
@Override
protected Response<CMResponse> parseNetworkResponse(NetworkResponse networkResponse) {
return Response.success(new CMResponse(new String(networkResponse.data), networkResponse.statusCode), getCacheEntry(networkResponse));
}
@Override
publicint getRequestType() {
return REQUEST_TYPE;
}
}