use of de.danoeh.antennapod.net.sync.model.SyncServiceException in project AntennaPod by AntennaPod.
the class GpodnetService method getEpisodeActionChanges.
/**
* Returns all subscription changes of a specific device.
* <p/>
* This method requires authentication.
*
* @param timestamp A timestamp that can be used to receive all changes since a
* specific point in time.
* @throws SyncServiceException If there is an authentication error.
*/
@Override
public EpisodeActionChanges getEpisodeActionChanges(long timestamp) throws SyncServiceException {
requireLoggedIn();
String params = String.format(Locale.US, "since=%d", timestamp);
String path = String.format("/api/2/episodes/%s.json", username);
try {
URL url = new URI(baseScheme, null, baseHost, basePort, path, params, null).toURL();
Request.Builder request = new Request.Builder().url(url);
String response = executeRequest(request);
JSONObject json = new JSONObject(response);
return ResponseMapper.readEpisodeActionsFromJsonObject(json);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new IllegalStateException(e);
} catch (JSONException | MalformedURLException e) {
e.printStackTrace();
throw new SyncServiceException(e);
}
}
use of de.danoeh.antennapod.net.sync.model.SyncServiceException in project AntennaPod by AntennaPod.
the class SyncService method doWork.
@Override
@NonNull
public Result doWork() {
ISyncService activeSyncProvider = getActiveSyncProvider();
if (activeSyncProvider == null) {
return Result.success();
}
SynchronizationSettings.updateLastSynchronizationAttempt();
setCurrentlyActive(true);
try {
activeSyncProvider.login();
syncSubscriptions(activeSyncProvider);
waitForDownloadServiceCompleted();
syncEpisodeActions(activeSyncProvider);
activeSyncProvider.logout();
clearErrorNotifications();
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_success));
SynchronizationSettings.setLastSynchronizationAttemptSuccess(true);
return Result.success();
} catch (Exception e) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_error));
SynchronizationSettings.setLastSynchronizationAttemptSuccess(false);
Log.e(TAG, Log.getStackTraceString(e));
if (e instanceof SyncServiceException) {
if (getRunAttemptCount() % 3 == 2) {
// Do not spam users with notification and retry before notifying
updateErrorNotification(e);
}
return Result.retry();
} else {
updateErrorNotification(e);
return Result.failure();
}
} finally {
setCurrentlyActive(false);
}
}
use of de.danoeh.antennapod.net.sync.model.SyncServiceException in project AntennaPod by AntennaPod.
the class GpodnetService method uploadEpisodeActionsPartial.
private UploadChangesResponse uploadEpisodeActionsPartial(List<EpisodeAction> episodeActions, int from, int to) throws SyncServiceException {
try {
Log.d(TAG, "Uploading partial actions " + from + " to " + to + " of " + episodeActions.size());
URL url = new URI(baseScheme, null, baseHost, basePort, String.format("/api/2/episodes/%s.json", username), null, null).toURL();
final JSONArray list = new JSONArray();
for (int i = from; i < to; i++) {
EpisodeAction episodeAction = episodeActions.get(i);
JSONObject obj = episodeAction.writeToJsonObject();
if (obj != null) {
obj.put("device", deviceId);
list.put(obj);
}
}
RequestBody body = RequestBody.create(JSON, list.toString());
Request.Builder request = new Request.Builder().post(body).url(url);
final String response = executeRequest(request);
return GpodnetEpisodeActionPostResponse.fromJSONObject(response);
} catch (JSONException | MalformedURLException | URISyntaxException e) {
e.printStackTrace();
throw new SyncServiceException(e);
}
}
use of de.danoeh.antennapod.net.sync.model.SyncServiceException in project AntennaPod by AntennaPod.
the class NextcloudSyncService method getSubscriptionChanges.
@Override
public SubscriptionChanges getSubscriptionChanges(long lastSync) throws SyncServiceException {
try {
HttpUrl.Builder url = makeUrl("/index.php/apps/gpoddersync/subscriptions");
url.addQueryParameter("since", "" + lastSync);
String responseString = performRequest(url, "GET", null);
JSONObject json = new JSONObject(responseString);
return ResponseMapper.readSubscriptionChangesFromJsonObject(json);
} catch (JSONException | MalformedURLException e) {
e.printStackTrace();
throw new SyncServiceException(e);
} catch (Exception e) {
e.printStackTrace();
throw new SyncServiceException(e);
}
}
use of de.danoeh.antennapod.net.sync.model.SyncServiceException in project AntennaPod by AntennaPod.
the class NextcloudSyncService method getEpisodeActionChanges.
@Override
public EpisodeActionChanges getEpisodeActionChanges(long timestamp) throws SyncServiceException {
try {
HttpUrl.Builder uri = makeUrl("/index.php/apps/gpoddersync/episode_action");
uri.addQueryParameter("since", "" + timestamp);
String responseString = performRequest(uri, "GET", null);
JSONObject json = new JSONObject(responseString);
return ResponseMapper.readEpisodeActionsFromJsonObject(json);
} catch (JSONException | MalformedURLException e) {
e.printStackTrace();
throw new SyncServiceException(e);
} catch (Exception e) {
e.printStackTrace();
throw new SyncServiceException(e);
}
}
Aggregations