本文整理汇总了Java中com.koushikdutta.ion.Response.getResult方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getResult方法的具体用法?Java Response.getResult怎么用?Java Response.getResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.koushikdutta.ion.Response
的用法示例。
在下文中一共展示了Response.getResult方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
@Override
protected String doInBackground(Void... voids) {
Log.d(TAG, "setting pin" + port.getPinNumber() + " state on " + arduino.getStatusUrl() + " to " + pinState);
Response<String> status;
try {
status = Ion.with(AHC.getContext())
.load(arduino.getPinStateUrl(port.getPinNumber(), pinState))
.asString()
.withResponse()
.get(Constants.STATUS_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (status.getHeaders().code() == 200) {
return status.getResult();
}
return null;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "could not get arduino status", e);
exception = e;
return null;
}
}
示例2: doInBackground
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
@Override
protected ArduinoStatusResponse doInBackground(Void... voids) {
Log.d(TAG, "checking status on " + arduino.getStatusUrl());
Response<ArduinoStatusResponse> status;
try {
status = Ion.with(AHC.getContext())
.load(arduino.getStatusUrl())
.as(ArduinoStatusResponse.class)
.withResponse()
.get(Constants.STATUS_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (status.getHeaders().code() == 200) {
return status.getResult();
}
return null;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "could not get arduino status", e);
exception = e;
return null;
}
}
示例3: getUsers
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Get the users from the addressbook server
* @return a {@link List} of registered {@link User}s
*/
public List<User> getUsers()
{
try
{
Response<List<User>> response = Ion.with(this.mContext)
.load(this.buildUsersUrl())
.as(User.listType)
.withResponse()
.get();
return response.getResult();
}
catch (Exception ex)
{
return null;
}
}
示例4: getContacts
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Get contacts from a session state
* @param session state to be used to fetch users from
* @return a {@link List} of {@link Contact}s
*/
public List<Contact> getContacts(Session session)
{
try
{
Response<List<Contact>> response = Ion.with(this.mContext)
.load(this.buildContactsUrl())
.setHeader("cookie", session.id == null ? "" : "sid=" + session.id)
.as(Contact.listType)
.withResponse()
.get();
return response.getResult();
}
catch (Exception ex)
{
return null;
}
}
示例5: login
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Logs a user in
* @param username to be used to log in
* @param password to be used to log in
* @return the {@link Session} state
* @throws LoginException when the username or password is empty or null
* @throws ServerException when there is a problem on the server
*/
public Session login(String username, String password) throws LoginException, ServerException
{
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(password))
throw new LoginException("Username and password required");
if (TextUtils.isEmpty(username))
throw new LoginException("Username required");
if (TextUtils.isEmpty(password))
throw new LoginException("Password required");
Response<JsonObject> response = null;
try
{
response = this.buildLoginResponse(username, password).get();
}
catch (Exception e)
{
throw new ServerException(e.getMessage());
}
if (response != null && response.getResult() != null)
{
JsonObject jobj = response.getResult();
if (response.getHeaders().getResponseCode() == 200)
{
return this.mGson.fromJson(jobj, Session.class);
}
else
{
Result result = this.mGson.fromJson(jobj, Result.class);
throw new ServerException(result.message)
.setStatusCode(result.status);
}
}
// XXX: strange case
throw new LoginException(null);
}
示例6: detectService
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Checks if the given URL exposes a supported API endpoint.
*
* @param context Android {@link Context}.
* @param uri URL to test.
* @param timeout Timeout in milliseconds.
* @return Detected endpoint URL. null, if no supported endpoint URL was detected.
*/
@Nullable
public static String detectService(@NonNull Context context, @NonNull Uri uri, int timeout) {
final String endpointUrl = Uri.withAppendedPath(uri, "/index.php?page=dapi&s=post&q=index")
.toString();
try {
final Response<DataEmitter> response = Ion.with(context)
.load(endpointUrl)
.setTimeout(timeout)
.userAgent(SearchClient.USER_AGENT)
.followRedirect(false)
.noCache()
.asDataEmitter()
.withResponse()
.get();
// Close the connection.
final DataEmitter dataEmitter = response.getResult();
if (dataEmitter != null) dataEmitter.close();
if (response.getHeaders().code() == 200) {
return uri.toString();
}
} catch (InterruptedException | ExecutionException ignored) {
}
return null;
}
示例7: detectService
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Checks if the given URL exposes a supported API endpoint.
*
* @param context Android {@link Context}.
* @param uri URL to test.
* @param timeout Timeout in milliseconds.
* @return Detected endpoint URL. null, if no supported endpoint URL was detected.
*/
@Nullable
public static String detectService(@NonNull Context context, @NonNull Uri uri, int timeout) {
final String endpointUrl = Uri.withAppendedPath(uri, "/post/index.xml").toString();
try {
final Response<DataEmitter> response = Ion.with(context)
.load(endpointUrl)
.setTimeout(timeout)
.userAgent(SearchClient.USER_AGENT)
.followRedirect(false)
.noCache()
.asDataEmitter()
.withResponse()
.get();
// Close the connection.
final DataEmitter dataEmitter = response.getResult();
if (dataEmitter != null) dataEmitter.close();
if (response.getHeaders().code() == 200) {
return uri.toString();
}
} catch (InterruptedException | ExecutionException ignored) {
}
return null;
}
示例8: detectService
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Checks if the given URL exposes a supported API endpoint.
*
* @param context Android {@link Context}.
* @param uri URL to test.
* @param timeout Timeout in milliseconds.
* @return Detected endpoint URL. null, if no supported endpoint URL was detected.
*/
@Nullable
public static String detectService(@NonNull Context context, @NonNull Uri uri, int timeout) {
final String endpointUrl = Uri.withAppendedPath(uri, "/posts.xml").toString();
try {
final Response<DataEmitter> response = Ion.with(context)
.load(endpointUrl)
.setTimeout(timeout)
.userAgent(SearchClient.USER_AGENT)
.followRedirect(false)
.noCache()
.asDataEmitter()
.withResponse()
.get();
// Close the connection.
final DataEmitter dataEmitter = response.getResult();
if (dataEmitter != null) dataEmitter.close();
if (response.getHeaders().code() == 200) {
return uri.toString();
}
} catch (InterruptedException | ExecutionException ignored) {
}
return null;
}
示例9: detectService
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
/**
* Checks if the given URL exposes a supported API endpoint.
*
* @param context Android {@link Context}.
* @param uri URL to test.
* @param timeout Timeout in milliseconds.
* @return Detected endpoint URL. null, if no supported endpoint URL was detected.
*/
@Nullable
public static String detectService(@NonNull Context context, @NonNull Uri uri, int timeout) {
final String endpointUrl = Uri.withAppendedPath(uri, "/api/danbooru/find_posts/index.xml")
.toString();
try {
final Response<DataEmitter> response = Ion.with(context)
.load(endpointUrl)
.setTimeout(timeout)
.userAgent(SearchClient.USER_AGENT)
.followRedirect(false)
.noCache()
.asDataEmitter()
.withResponse()
.get();
// Close the connection.
final DataEmitter dataEmitter = response.getResult();
if (dataEmitter != null) dataEmitter.close();
if (response.getHeaders().code() == 200) {
return uri.toString();
}
} catch (InterruptedException | ExecutionException ignored) {
}
return null;
}
示例10: received
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
private boolean received(Response<JsonObject> result) {
JsonObject jsonResult = result.getResult();
return jsonResult != null &&
!jsonResult.get("received").isJsonNull() &&
jsonResult.get("received").getAsBoolean();
}
示例11: received
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
private boolean received(Response<JsonObject> result) {
JsonObject jsonResult = result.getResult();
return jsonResult != null &&
!jsonResult.get(DOWNLOAD_URL_KEY).isJsonNull();
}
示例12: uploadContact
import com.koushikdutta.ion.Response; //导入方法依赖的package包/类
public Contact uploadContact(Session session, Contact contact) throws ServerException
{
Response<JsonObject> response = null;
try
{
response = Ion.with(this.mContext)
.load(this.buildContactsUrl())
.setHeader("cookie", session.id == null ? "" : "sid=" + session.id)
.setJsonPojoBody(contact)
.asJsonObject()
.withResponse()
.get();
}
catch (Exception ex)
{
throw new ServerException(ex.getMessage());
}
if (response != null && response.getResult() != null)
{
JsonObject jobj = response.getResult();
if (response.getHeaders().getResponseCode() == 200)
{
return this.mGson.fromJson(jobj, Contact.class);
}
else
{
Result result = this.mGson.fromJson(jobj, Result.class);
JsonElement jsonErrors = jobj.get("errors");
// error fields placeholder
Contact fieldErrors = this.mGson.fromJson(jsonErrors, Contact.class);
ServerException exception = new ServerException(result.message);
exception.setStatusCode(result.status);
if (fieldErrors != null)
{
if (fieldErrors.name != null)
exception.putError(Contact.CONTACT_NAME, fieldErrors.name);
if (fieldErrors.phone != null)
exception.putError(Contact.CONTACT_PHONE, fieldErrors.phone);
}
throw exception;
}
}
// XXX: strange case
throw new ServerException(response.getException().getMessage());
}