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;
//www.java2s.comimport android.content.Context;
import com.android.volley.Response;
import com.cloudmine.api.CMApiCredentials;
import com.cloudmine.api.CMSessionToken;
import com.cloudmine.api.rest.options.CMSortOptions;
import com.cloudmine.api.rest.response.CMObjectResponse;
/**
* A builder for creating complex object load requests
* <br>
* Copyright CloudMine LLC. All rights reserved<br>
* See LICENSE file included with SDK for details.
*/publicclass ObjectLoadRequestBuilder extends RequestBuilder<ObjectLoadRequestBuilder, BaseObjectLoadRequest, CMObjectResponse>{
private CMURLBuilder urlBuilder = BaseObjectLoadRequest.BASE_URL.copy();
private CMApiCredentials credentials = null;
public ObjectLoadRequestBuilder(CMSessionToken sessionToken, Response.Listener<CMObjectResponse> success) {
this(sessionToken, success, null);
}
public ObjectLoadRequestBuilder(CMSessionToken sessionToken, Response.Listener<CMObjectResponse> success, Response.ErrorListener error) {
super(sessionToken, success, error);
}
public ObjectLoadRequestBuilder(Response.Listener< CMObjectResponse > success) {
this(success, null);
}
public ObjectLoadRequestBuilder(Response.Listener< CMObjectResponse > success, Response.ErrorListener error) {
super(success, error);
}
@Override
public BaseObjectLoadRequest build() {
returnnew BaseObjectLoadRequest(urlBuilder, sessionToken, credentials, serverFunction, successListener, errorListener);
}
public ObjectLoadRequestBuilder search(String searchQuery) {
urlBuilder.removeAction(BaseObjectLoadRequest.BASE_ENDPOINT);
urlBuilder.search(searchQuery);
returnthis;
}
public ObjectLoadRequestBuilder startAt(int skip) {
urlBuilder.addQuery("skip", skip);
returnthis;
}
public ObjectLoadRequestBuilder sortBy(String sortField) {
urlBuilder.addQuery("sort", sortField);
returnthis;
}
public ObjectLoadRequestBuilder sortBy(String sortField, CMSortOptions.SortDirection sortDirection) {
urlBuilder.addQuery("sort", sortField + ":" + sortDirection.toString());
returnthis;
}
public ObjectLoadRequestBuilder limit(int limit) {
urlBuilder.addQuery("limit", limit);
returnthis;
}
public ObjectLoadRequestBuilder getCount() {
urlBuilder.addQuery("count", "true");
returnthis;
}
public ObjectLoadRequestBuilder getShared() {
urlBuilder.addQuery("shared", "true");
returnthis;
}
public ObjectLoadRequestBuilder useCredentials(CMApiCredentials credentials) {
this.credentials = credentials;
returnthis;
}
public ObjectLoadRequestBuilder getSharedOnly() {
urlBuilder.addQuery("shared_only", "true");
returnthis;
}
public BaseObjectLoadRequest run(Context context) {
BaseObjectLoadRequest request = build();
SharedRequestQueueHolders.getRequestQueue(context).add(request);
return request;
}
}