Skip to content

Commit

Permalink
Orianna should pretty much never throw a 429 anymore, and should handle
Browse files Browse the repository at this point in the history
responding to them from the server (if the rate limiter gets out of
sync) automatically. You still need to set your rate limit correctly, or
face the wrath of Riot.
  • Loading branch information
robrua committed Mar 27, 2015
1 parent 9d5a37a commit e90caa2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Standard Java
<dependency>
<groupId>com.robrua</groupId>
<artifactId>orianna</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>
</dependency>
```

Expand All @@ -47,7 +47,7 @@ Android
<dependency>
<groupId>com.robrua</groupId>
<artifactId>orianna-android</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>
</dependency>
```

Expand All @@ -60,7 +60,7 @@ repositories {
}
dependencies {
compile 'com.robrua:orianna:2.1.3'
compile 'com.robrua:orianna:2.1.4'
}
```

Expand All @@ -71,7 +71,7 @@ repositories {
}
dependencies {
compile 'com.robrua:orianna-android:2.1.3'
compile 'com.robrua:orianna-android:2.1.4'
}
```

Expand Down Expand Up @@ -225,7 +225,7 @@ public class Example {
[Found Here](http://robrua.github.io/Orianna/)

## Download
[Check Releases](https://github.com/robrua/Orianna/releases)
[Releases](https://github.com/robrua/Orianna/releases)/[Snapshot](http://robrua.com/orianna)

## Questions/Contributions
Feel free to send pull requests or to contact me via github or email ([email protected]).
Expand Down
2 changes: 1 addition & 1 deletion android-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>orianna-android</artifactId>
<version>2.1.4-SNAPSHOT</version>
<version>2.1.4</version>
<packaging>jar</packaging>

<parent>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>orianna</artifactId>
<version>2.1.4-SNAPSHOT</version>
<version>2.1.4</version>
<packaging>jar</packaging>

<parent>
Expand Down
17 changes: 13 additions & 4 deletions src/com/robrua/orianna/api/dto/BaseRiotAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ static String get(final URI uri, final boolean staticServer) {
rateLimiter.waitForCall();
}

boolean registered = false;

// Send request to Riot and register call
try {
final HttpGet get = new HttpGet(uri);
Expand All @@ -208,7 +210,13 @@ static String get(final URI uri, final boolean staticServer) {
// Force rate limiter to wait after a 429
final int retryAfter = Integer.parseInt(response.getFirstHeader("Retry-After").getValue()) + 1;
rateLimiter.resetIn(retryAfter * 1000L);
throw new APIException(uri.toString(), 429);

// Release resources and exit from rate limited call, then
// retry call
response.close();
rateLimiter.registerCall();
registered = true;
return get(uri, staticServer);
}
else if(response.getStatusLine().getStatusCode() != 200) {
throw new APIException(uri.toString(), response.getStatusLine().getStatusCode());
Expand All @@ -217,15 +225,16 @@ else if(response.getStatusLine().getStatusCode() != 200) {
return content;
}
finally {
response.close();
if(!registered) {
response.close();
}
}
}
catch(final IOException e) {
e.printStackTrace();
throw new OriannaException("Request to Riot server failed! Report this to the Orianna team.");
}
finally {
if(!staticServer) {
if(!staticServer && !registered) {
rateLimiter.registerCall();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/com/robrua/orianna/type/core/staticdata/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.regex.Pattern;

import com.robrua.orianna.type.core.OriannaObject;
import com.robrua.orianna.type.exception.OriannaException;

public class Item extends OriannaObject<com.robrua.orianna.type.dto.staticdata.Item> {
private static final Map<String, Pattern> PATTERNS = getScrapedStatPatterns();
Expand Down Expand Up @@ -323,7 +324,7 @@ private void scrapeStats() {
clazz.getDeclaredField(stat).set(stats, Double.parseDouble(matcher.group(1)));
}
catch(IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
throw new OriannaException("Error while scraping for Item stats. Report this to the Orianna team.");
}
}
}
Expand Down

0 comments on commit e90caa2

Please sign in to comment.