本文整理汇总了Java中com.koushikdutta.ion.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.koushikdutta.ion包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.koushikdutta.ion.Response; //导入依赖的package包/类
@Override public void get(final Context context, String team, final RecyclerView recyclerView) {
String urlFull = ApiConstraints.TEAM.concat(team);
api.getArray(urlFull).setCallback(new FutureCallback<Response<JsonArray>>() {
@Override public void onCompleted(Exception e, Response<JsonArray> result) {
if (e != null) {
return;
}
int code = result.getHeaders().code();
switch (code) {
case 200:
Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
TypeToken listType = new TypeToken<List<Team>>() {
};
List<Team> teams = (List<Team>) gson.fromJson(result.getResult(), listType.getType());
SearchTeamAdapter teamAdapter = new SearchTeamAdapter(context, teams, teamRepository);
recyclerView.setAdapter(teamAdapter);
break;
case 404:
break;
}
}
});
}
示例2: get
import com.koushikdutta.ion.Response; //导入依赖的package包/类
@Override public void get(String team) {
String urlFull = ApiConstraints.TEAM_PLAYERS.concat(team);
api.getObject(urlFull).setCallback(new FutureCallback<Response<JsonObject>>() {
@Override public void onCompleted(Exception e, Response<JsonObject> result) {
if (e == null) {
return;
}
int code = result.getHeaders().code();
switch (code) {
case 200:
// deserialize
// save
break;
case 404:
break;
}
}
});
}
示例3: onCompleted
import com.koushikdutta.ion.Response; //导入依赖的package包/类
@Override
public void onCompleted(Exception e, Response<JsonObject> result) {
if (e != null || !httpStatusCodeOk(result) || !received(result)) {
Log.v(AppaloosaAnalytics.ANALYTICS_LOG_TAG, "An error occurred when sending Appaloosa-Store analytics");
new Thread(new Runnable() {
@Override
public void run() {
retry(sentData, currentBatchSendAttemptNb);
}
}).start();
} else {
AnalyticsServices.sending = false;
Log.v(AppaloosaAnalytics.ANALYTICS_LOG_TAG, "Analytics sent");
AnalyticsServices.deleteEventsSent(eventIds);
}
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: 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;
}
}
示例7: 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;
}
}
示例8: reverse
import com.koushikdutta.ion.Response; //导入依赖的package包/类
public static void reverse(final double lat, final double lng, @NonNull final ReverseCallback callback) {
Ion.with(App.get())
.load("http://nominatim.openstreetmap.org/reverse?format=json&[email protected]&lat=" + lat +
"&lon=" + lng + "&accept-language=" + Utils.getLocale().getLanguage())
.as(OSMReverse.class).withResponse().setCallback(new FutureCallback<Response<OSMReverse>>() {
@Override
public void onCompleted(@Nullable Exception e, Response<OSMReverse> response) {
if (e != null) e.printStackTrace();
OSMReverse result = response == null ? null : response.getResult();
Entry entry = new Entry();
if (result != null && result.address != null) {
entry.setCountry(result.address.country);
entry.setName(result.address.county);
entry.setLat(result.lat);
entry.setLng(result.lon);
} else {
entry.setName("Unknown");
entry.setCountry("Unknown");
entry.setLat(lat);
entry.setLng(lng);
}
callback.onResult(entry);
}
});
}
示例9: onCompleted
import com.koushikdutta.ion.Response; //导入依赖的package包/类
@Override
public void onCompleted(Exception e, Response<JsonObject> result) {
if (e != null) {
Log.w(Appaloosa.APPALOOSA_LOG_TAG, Appaloosa.getApplicationContext().getResources().getString(R.string.get_download_url_error));
} else if (result != null && httpStatusCodeOk(result) && received(result)) {
String downloadUrl = result.getResult().get(DOWNLOAD_URL_KEY).getAsString();
autoUpdateService.downloadAPK(this.mobileApplicationUpdate, downloadUrl);
}
}
示例10: onReadArticlesBefore
import com.koushikdutta.ion.Response; //导入依赖的package包/类
@Override
protected void onReadArticlesBefore(final String type, String uniqueId, final long timestamp) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onReadArticlesBefore for: " + type + " before " + new Date(timestamp) + " with uniqueId" + uniqueId);
if (type.equals("all")) {
uniqueId = "user%2F-%2Fstate%2Fcom.google%2Freading-list";
}
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String authKey = sharedPref.getString(SharedPreferenceKeys.AUTH, null);
final long timestampNs = timestamp * 1000;
final String finalUniqueId = uniqueId;
Ion.with(this).load("https://theoldreader.com/reader/api/0/mark-all-as-read")
.setHeader("Authorization: GoogleLogin auth", authKey)
.setBodyParameter("s", uniqueId)
.setBodyParameter("ts", String.valueOf(timestampNs))
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
@Override
public void onCompleted(Exception e, Response<String> result) {
if (e != null) {
onReadArticlesBeforeFailed(type, finalUniqueId, timestamp);
}
try {
Log.w("TOR", "Sending mark as read before: " + result.getHeaders().code() + " => " + result.getResult());
} catch (Exception e1) {
}
}
});
//
}
示例11: 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);
}
示例12: buildLoginResponse
import com.koushikdutta.ion.Response; //导入依赖的package包/类
private Future<Response<JsonObject>> buildLoginResponse(String username, String password)
{
return Ion.with(this.mContext)
.load(this.buildLoginUrl())
.setBodyParameter("username", username)
.setBodyParameter("password", password)
.asJsonObject()
.withResponse();
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}