Skip to content

Commit

Permalink
Merge branch 'hotfix/5.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomeaux committed Apr 15, 2016
2 parents 6c82f58 + fdf0c49 commit 2d0f339
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 214 deletions.
19 changes: 12 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
Release Notes
=============

Version 5.2.5
-------------
* Really fix the disappearing collection
* Bug fixes

Version 5.2.4
-------------
* Fix for disappearing collection
* Bug fixes
* Fix for disappearing collection
* Bug fixes

Version 5.2.3
-------------
* Bug fixes
* Bug fixes

Version 5.2.2
-------------
* Improve H-Index calculations
* Bug fixes
* Improve H-Index calculations
* Bug fixes

Version 5.2.1
-------------
* Fix play logging issues
* Fix crash when filtering by subtype
* Fix play logging issues
* Fix crash when filtering by subtype

Version 5.2
-----------
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ android {
applicationId "com.boardgamegeek"
minSdkVersion 9
targetSdkVersion 23
versionCode 56
versionName "5.2.4"
versionCode 57
versionName "5.2.5"
buildConfigField "String", "BRANCH", "\"" + getBranchName() + "\""
}
buildTypes {
Expand Down
29 changes: 8 additions & 21 deletions app/src/main/java/com/boardgamegeek/io/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@

import com.boardgamegeek.BuildConfig;
import com.boardgamegeek.auth.Authenticator;
import com.squareup.okhttp.OkHttpClient;

import java.io.IOException;

import retrofit.ErrorHandler;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.RestAdapter.Builder;
import retrofit.RestAdapter.LogLevel;
import retrofit.RetrofitError;
import retrofit.android.AndroidLog;
import retrofit.client.Response;
import retrofit.client.OkClient;
import retrofit.converter.Converter;
import retrofit.converter.SimpleXMLConverter;

public class Adapter {
private static final boolean DEBUG = BuildConfig.DEBUG;
private static final int COLLECTION_REQUEST_PROCESSING = 202;
private static final int API_RATE_EXCEEDED = 503;

public static BggService create() {
return createBuilder().build().create(BggService.class);
Expand All @@ -44,31 +42,20 @@ public static BggService createForPost(Context context, Converter converter) {
}

private static Builder createBuilder() {
return createBuilderWithoutConverter().setConverter(new BggXMLConverter());
return createBuilderWithoutConverter().setConverter(new SimpleXMLConverter(false));
}

private static Builder createBuilderWithoutConverter() {
ErrorHandler errorHandler = new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError cause) {
Response r = cause.getResponse();
if (r != null) {
if (r.getStatus() == COLLECTION_REQUEST_PROCESSING) {
return new RetryableException(cause);
} else if (r.getStatus() == API_RATE_EXCEEDED) {
return new RetryableException(cause);
}
}
return cause;
}
};
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new RetryInterceptor());

Builder builder = new RestAdapter.Builder()
.setEndpoint("https://www.boardgamegeek.com/")
.setErrorHandler(errorHandler);
.setClient(new OkClient(client));
if (DEBUG) {
builder.setLog(new AndroidLog("BGG-retrofit")).setLogLevel(LogLevel.FULL);
}

return builder;
}

Expand Down
57 changes: 0 additions & 57 deletions app/src/main/java/com/boardgamegeek/io/BggXMLConverter.java

This file was deleted.

18 changes: 4 additions & 14 deletions app/src/main/java/com/boardgamegeek/io/BuddyCollectionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@

import com.boardgamegeek.model.CollectionResponse;

public class BuddyCollectionRequest extends RetryableRequest<CollectionResponse> {
public class BuddyCollectionRequest {
private final BggService bggService;
private final String username;
private final ArrayMap<String, String> options;

public BuddyCollectionRequest(BggService service, String username, ArrayMap<String, String> options) {
super(service);
this.bggService = service;
this.username = username;
this.options = options;
}

@Override
protected CollectionResponse request() {
public CollectionResponse execute() {
return bggService.collection(username, options);
}

@Override
protected long getMinWaitTime() {
return 200L;
}

@Override
protected int getMaxRetries() {
return 5;
}
}
18 changes: 4 additions & 14 deletions app/src/main/java/com/boardgamegeek/io/CollectionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@

import com.boardgamegeek.model.CollectionResponse;

public class CollectionRequest extends RetryableRequest<CollectionResponse> {
public class CollectionRequest {
private final BggService bggService;
private final String username;
private final ArrayMap<String, String> options;

public CollectionRequest(BggService service, String username, ArrayMap<String, String> options) {
super(service);
this.bggService = service;
this.username = username;
this.options = options;
}

@Override
protected CollectionResponse request() {
public CollectionResponse execute() {
return bggService.collection(username, options);
}

@Override
protected long getMinWaitTime() {
return 500L;
}

@Override
protected long getMaxWaitTime() {
return 120000L;
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/boardgamegeek/io/PlaysRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@

import com.boardgamegeek.model.PlaysResponse;

public class PlaysRequest extends RetryableRequest<PlaysResponse> {
public class PlaysRequest {
private static final int TYPE_ALL = 0;
public static final int TYPE_MIN = 1;
public static final int TYPE_MAX = 2;

private final BggService bggService;
private final int type;
private final String username;
private final int page;
private final String date;

public PlaysRequest(BggService service, int type, String username, int page, String date) {
super(service);
this.bggService = service;
this.type = type;
this.username = username;
this.date = date;
this.page = page;
}

public PlaysRequest(BggService service, String username, int page) {
super(service);
this.bggService = service;
this.type = TYPE_ALL;
this.username = username;
this.page = page;
this.date = "";
}

@Override
protected PlaysResponse request() {
public PlaysResponse execute() {
if (type == PlaysRequest.TYPE_MIN) {
return bggService.playsByMinDate(username, date, page);
} else if (type == PlaysRequest.TYPE_MAX) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
package com.boardgamegeek.io;


import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;

import timber.log.Timber;

public abstract class RetryableRequest<T> {
public class RetryInterceptor implements Interceptor {
private static final int COLLECTION_REQUEST_PROCESSING = 202;
private static final int API_RATE_EXCEEDED = 503;

private static final int BACKOFF_TYPE_EXPONENTIAL = 0;
private static final int BACKOFF_TYPE_GEOMETRIC = 1;

private static final long MIN_WAIT_TIME = 100L;
private static final long MAX_WAIT_TIME = 60000L;
private static final int MAX_RETRIES = 10;
protected final BggService bggService;

public RetryableRequest(BggService service) {
bggService = service;
}

public T execute() {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
int numberOfRetries = 0;
do {
try {
return request();
} catch (Exception e) {
if (e.getCause() instanceof RetryableException) {
Timber.w(e, "Retry-able exception");
numberOfRetries++;
wait(numberOfRetries);
} else {
Timber.e(e, "Non-retry-able exception");
throw e;
}
Response response = chain.proceed(originalRequest);
final int responseCode = response.code();
if (responseCode == COLLECTION_REQUEST_PROCESSING ||
responseCode == API_RATE_EXCEEDED) {
Timber.i("Retry-able response code %s", responseCode);
numberOfRetries++;
wait(numberOfRetries);
Timber.i("...retrying");
} else {
return response;
}
} while (numberOfRetries < getMaxRetries());
String errorMessage = String.format("Exceeded maximum number of retries: [%s]", getMaxRetries());
Timber.w(errorMessage);
throw new RuntimeException(errorMessage);
Timber.w("Exceeded maximum number of retries of %,d.", getMaxRetries());
return chain.proceed(originalRequest);
}

protected abstract T request();

private void wait(int numberOfRetries) {
long waitTime = calculateWaitTime(numberOfRetries);
Timber.i("...retry #" + numberOfRetries + " in " + waitTime + "ms");
Timber.i("...retry #%1$,d in %2$,dms...", numberOfRetries, waitTime);
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/java/com/boardgamegeek/io/RetryableException.java

This file was deleted.

18 changes: 4 additions & 14 deletions app/src/main/java/com/boardgamegeek/io/ThingRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@

import com.boardgamegeek.model.ThingResponse;

public class ThingRequest extends RetryableRequest<ThingResponse> {
public class ThingRequest {
private final BggService bggService;
private final String ids;

public ThingRequest(BggService service, String ids) {
super(service);
this.bggService = service;
this.ids = ids;
}

@Override
protected ThingResponse request() {
public ThingResponse execute() {
return bggService.thing(ids, 1);
}

@Override
protected long getMinWaitTime() {
return 500L;
}

@Override
protected int getMaxRetries() {
return 5;
}
}
Loading

0 comments on commit 2d0f339

Please sign in to comment.