use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class FaceBookAccess method anonymousLogin.
/**
* Some simple queries for public data can work just fine with anonymous login without requiring the whole
* OAuth process, they still need a facebook application though
* @param appid the id of the application
* @param clientSecret the client secret for the application
*/
public static void anonymousLogin(String appid, String clientSecret) {
ConnectionRequest req = new ConnectionRequest();
req.setPost(false);
req.setUrl("https://graph.facebook.com/oauth/access_token");
req.addArgument("client_id", appid);
req.addArgument("client_secret", clientSecret);
req.addArgument("grant_type", "client_credentials");
NetworkManager.getInstance().addToQueueAndWait(req);
if (req.getResponseData() != null) {
token = new String(req.getResponseData());
token = token.substring(token.indexOf('=') + 1);
}
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudStorage method deleteAllCloudFilesBefore.
/**
* Deletes all the cloud files before the given time stamp for the given
* development account. Notice that this method is meant for internal use
* and not for distributable apps since it includes your developer account.
* This method works in a background server process and returns immediately.
* @param timestamp the timestamp since epoch (as in System.currentTimemillis).
* @param developerAccount your developer email
* @param developerPassword your developer password
* @deprecated this API is currently deprecated due to Googles cloud storage deprection
*/
public void deleteAllCloudFilesBefore(long timestamp, String developerAccount, String developerPassword) {
if (CloudPersona.getCurrentPersona().getToken() == null) {
return;
}
ConnectionRequest req = new ConnectionRequest();
req.setPost(false);
req.setFailSilently(true);
req.setUrl(SERVER_URL + "/purgeCloudFiles");
req.addArgument("d", "" + timestamp);
req.addArgument("u", developerAccount);
req.addArgument("p", developerPassword);
NetworkManager.getInstance().addToQueue(req);
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class CloudStorage method uploadCloudFileImpl.
private String uploadCloudFileImpl(String mimeType, String file, InputStream data, int dataSize) throws CloudException, IOException {
String token = CloudPersona.getCurrentPersona().getToken();
if (token == null || token.length() == 0) {
if (!CloudPersona.createAnonymous()) {
throw new CloudException(RETURN_CODE_FAIL_SERVER_ERROR, "Error creating anonymous login");
}
token = CloudPersona.getCurrentPersona().getToken();
}
ConnectionRequest req = new ConnectionRequest();
req.setPost(false);
req.setUrl(SERVER_URL + "/fileStoreURLRequest");
// req.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
NetworkManager.getInstance().addToQueueAndWait(req);
int rc = req.getResponseCode();
if (rc != 200) {
if (rc == 420) {
throw new CloudException(RETURN_CODE_FAIL_QUOTA_EXCEEDED);
}
throw new CloudException(RETURN_CODE_FAIL_SERVER_ERROR);
}
String d = new String(req.getResponseData());
MultipartRequest uploadReq = new MultipartRequest();
uploadReq.setUrl(d);
uploadReq.setManualRedirect(false);
uploadReq.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
uploadReq.addArgument("t", CloudPersona.getCurrentPersona().getToken());
uploadReq.addArgument("pk", Display.getInstance().getProperty("package_name", null));
if (data == null) {
int pos = file.lastIndexOf('/');
String shortName = file;
if (pos > -1) {
shortName = file.substring(pos);
}
uploadReq.addData(shortName, file, mimeType);
} else {
uploadReq.addData(file, data, dataSize, mimeType);
}
NetworkManager.getInstance().addToQueueAndWait(uploadReq);
if (uploadReq.getResponseCode() != 200) {
throw new CloudException(RETURN_CODE_FAIL_SERVER_ERROR);
}
String r = new String(uploadReq.getResponseData());
if ("ERROR".equals(r)) {
throw new CloudException(RETURN_CODE_FAIL_SERVER_ERROR);
}
return r;
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class SliderBridge method bindProgress.
/**
* Allows binding progress to an arbitrary slider
*
* @param sources the source connection request (null for all network activity)
* @param s the slider
*/
public static void bindProgress(final ConnectionRequest[] sources, final Slider s) {
Vector v = null;
int portions = 100;
if (sources != null) {
v = new Vector();
int slen = sources.length;
for (int iter = 0; iter < slen; iter++) {
v.addElement(sources[iter]);
}
portions = portions / slen;
}
final Vector sourceVec = v;
final int portionPerSource = portions;
NetworkManager.getInstance().addProgressListener(new ActionListener() {
private float currentLength;
private int soFar;
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent evt) {
if (sources != null) {
if (!sourceVec.contains(evt.getSource())) {
return;
}
}
NetworkEvent e = (NetworkEvent) evt;
switch(e.getProgressType()) {
case NetworkEvent.PROGRESS_TYPE_COMPLETED:
s.setInfinite(false);
// s.setProgress(s.getMaxValue());
soFar += portionPerSource;
s.setProgress(soFar);
if (sources != null) {
NetworkManager.getInstance().removeProgressListener(this);
}
break;
case NetworkEvent.PROGRESS_TYPE_INITIALIZING:
s.setInfinite(true);
break;
case NetworkEvent.PROGRESS_TYPE_INPUT:
case NetworkEvent.PROGRESS_TYPE_OUTPUT:
if (e.getLength() > 0) {
currentLength = e.getLength();
// s.setMaxValue(1000);
s.setInfinite(false);
float sentReceived = e.getSentReceived();
sentReceived = sentReceived / currentLength * portionPerSource;
s.setProgress((int) sentReceived + soFar);
// s.setProgress(e.getSentReceived());
// s.setMaxValue(e.getLength());
} else {
s.setInfinite(true);
}
break;
}
}
});
}
use of com.codename1.io.ConnectionRequest in project CodenameOne by codenameone.
the class RequestBuilder method getAsJsonMap.
/**
* Executes the request synchronously
*
* @return Response Object
*/
public Response<Map> getAsJsonMap() {
ConnectionRequest request = createRequest(true);
CN.addToQueueAndWait(request);
Map response = ((Connection) request).json;
return new Response(request.getResponseCode(), response, request.getResponseErrorMessage());
}
Aggregations