Skip to content

Commit a37c33a

Browse files
committed
Merge pull request #9 from mb3364/update-http-lib
Update Dependencies
2 parents 0912c1c + 6bdc618 commit a37c33a

File tree

13 files changed

+128
-103
lines changed

13 files changed

+128
-103
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,18 @@ twitch.auth().setAccessToken("my-access-token-289489");
160160

161161
## Dependencies
162162

163-
* [Java Async HTTP Client](https://github.com/mb3364/java-async-http/releases/tag/v1.0.0) v1.0.0
164-
* [Jackson JSON Processor](http://wiki.fasterxml.com/JacksonHome) ver. 2.4.4
163+
* [Java Async HTTP Client](https://github.com/mb3364/java-async-http/releases/tag/2.1.2) ver. 2.1.2
164+
* [Jackson JSON Processor - Databind](http://wiki.fasterxml.com/JacksonHome) / [Direct Download](http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.4.5/jackson-databind-2.4.5.jar) ver. 2.4.5
165+
166+
## Install
167+
168+
This library and the 2 above mentioned dependencies are required. Direct download links are provided below:
169+
170+
* [Twitch API Wrapper, jar download]()
171+
* [Java Async HTTP Client](https://github.com/mb3364/java-async-http/releases/tag/2.1.2) ver. 2.1.2
172+
* [Jackson JSON Processor - Databind library](http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.4.5/jackson-databind-2.4.5.jar) ver. 2.4.5
173+
174+
The Jackson JSON Processor is also available via Maven repositories.
165175

166176
## Roadmap
167177

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.mb3364.twitch</groupId>
6-
<artifactId>api-wrapper</artifactId>
7-
<version>0.2</version>
6+
<artifactId>twitch-api-wrapper</artifactId>
7+
<version>0.3</version>
88
<packaging>jar</packaging>
99

1010
<name>twitch-api-wrapper</name>
@@ -15,8 +15,8 @@
1515
<!-- Compilation -->
1616
<java.version>1.7</java.version>
1717
<!-- Dependencies -->
18-
<async-http-client.version>1.0.0</async-http-client.version>
19-
<jackson.version>2.4.4</jackson.version>
18+
<async-http-client.version>2.1.2</async-http-client.version>
19+
<jackson.version>2.4.5</jackson.version>
2020
<!-- Test Dependencies -->
2121
<junit.version>4.12</junit.version>
2222
</properties>

src/main/java/com/mb3364/twitch/api/resources/AbstractResource.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
55
import com.mb3364.http.AsyncHttpClient;
6-
import com.mb3364.http.HttpResponse;
7-
import com.mb3364.http.HttpResponseHandler;
6+
import com.mb3364.http.StringHttpResponseHandler;
87
import com.mb3364.twitch.api.handlers.BaseFailureHandler;
98
import com.mb3364.twitch.api.models.Error;
109

1110
import java.io.IOException;
11+
import java.util.List;
12+
import java.util.Map;
1213

1314
/**
1415
* AbstractResource is the abstract base class of a Twitch resource.
@@ -82,7 +83,7 @@ protected String getBaseUrl() {
8283
* Handles HTTP response's from the Twitch API.
8384
* <p>Since all Http failure logic is the same, we handle it all in one place: here.</p>
8485
*/
85-
protected static abstract class TwitchHttpResponseHandler extends HttpResponseHandler {
86+
protected static abstract class TwitchHttpResponseHandler extends StringHttpResponseHandler {
8687

8788
private BaseFailureHandler apiHandler;
8889

@@ -91,13 +92,17 @@ public TwitchHttpResponseHandler(BaseFailureHandler apiHandler) {
9192
}
9293

9394
@Override
94-
public abstract void onSuccess(HttpResponse response);
95+
public abstract void onSuccess(int statusCode, Map<String, List<String>> headers, String content);
9596

9697
@Override
97-
public void onFailure(HttpResponse response) {
98+
public void onFailure(int statusCode, Map<String, List<String>> headers, String content) {
9899
try {
99-
Error error = objectMapper.readValue(response.getContent(), Error.class);
100-
apiHandler.onFailure(response.getStatusCode(), response.getStatusMessage(), error.getMessage());
100+
if (content.length() > 0) {
101+
Error error = objectMapper.readValue(content, Error.class);
102+
apiHandler.onFailure(statusCode, error.getStatusText(), error.getMessage());
103+
} else {
104+
apiHandler.onFailure(statusCode, "", "");
105+
}
101106
} catch (IOException e) {
102107
apiHandler.onFailure(e);
103108
}

src/main/java/com/mb3364/twitch/api/resources/ChannelsResource.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.mb3364.twitch.api.resources;
22

3-
import com.mb3364.http.HttpResponse;
43
import com.mb3364.http.RequestParams;
54
import com.mb3364.twitch.api.auth.Scopes;
65
import com.mb3364.twitch.api.handlers.*;
76
import com.mb3364.twitch.api.models.*;
87

98
import java.io.IOException;
9+
import java.util.List;
10+
import java.util.Map;
1011

1112
/**
1213
* The {@link ChannelsResource} provides the functionality
@@ -37,9 +38,9 @@ public void get(final ChannelResponseHandler handler) {
3738

3839
http.get(url, new TwitchHttpResponseHandler(handler) {
3940
@Override
40-
public void onSuccess(HttpResponse response) {
41+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
4142
try {
42-
Channel value = objectMapper.readValue(response.getContent(), Channel.class);
43+
Channel value = objectMapper.readValue(content, Channel.class);
4344
handler.onSuccess(value);
4445
} catch (IOException e) {
4546
handler.onFailure(e);
@@ -59,9 +60,9 @@ public void get(final String channelName, final ChannelResponseHandler handler)
5960

6061
http.get(url, new TwitchHttpResponseHandler(handler) {
6162
@Override
62-
public void onSuccess(HttpResponse response) {
63+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
6364
try {
64-
Channel value = objectMapper.readValue(response.getContent(), Channel.class);
65+
Channel value = objectMapper.readValue(content, Channel.class);
6566
handler.onSuccess(value);
6667
} catch (IOException e) {
6768
handler.onFailure(e);
@@ -82,9 +83,9 @@ public void getEditors(final String channelName, final UsersResponseHandler hand
8283

8384
http.get(url, new TwitchHttpResponseHandler(handler) {
8485
@Override
85-
public void onSuccess(HttpResponse response) {
86+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
8687
try {
87-
Editors value = objectMapper.readValue(response.getContent(), Editors.class);
88+
Editors value = objectMapper.readValue(content, Editors.class);
8889
handler.onSuccess(value.getUsers());
8990
} catch (IOException e) {
9091
handler.onFailure(e);
@@ -110,25 +111,25 @@ public void put(final String channelName, final RequestParams params, final Chan
110111
String url = String.format("%s/channels/%s", getBaseUrl(), channelName);
111112

112113
if (params.containsKey("status")) {
113-
params.put("channel[status]", params.get("status"));
114+
params.put("channel[status]", params.getString("status"));
114115
params.remove("status");
115116
}
116117

117118
if (params.containsKey("game")) {
118-
params.put("channel[game]", params.get("game"));
119+
params.put("channel[game]", params.getString("game"));
119120
params.remove("game");
120121
}
121122

122123
if (params.containsKey("delay")) {
123-
params.put("channel[delay]", params.get("delay"));
124+
params.put("channel[delay]", params.getString("delay"));
124125
params.remove("delay");
125126
}
126127

127128
http.put(url, params, new TwitchHttpResponseHandler(handler) {
128129
@Override
129-
public void onSuccess(HttpResponse response) {
130+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
130131
try {
131-
Channel value = objectMapper.readValue(response.getContent(), Channel.class);
132+
Channel value = objectMapper.readValue(content, Channel.class);
132133
handler.onSuccess(value);
133134
} catch (IOException e) {
134135
handler.onFailure(e);
@@ -149,9 +150,9 @@ public void resetStreamKey(final String channelName, final ChannelResponseHandle
149150

150151
http.delete(url, new TwitchHttpResponseHandler(handler) {
151152
@Override
152-
public void onSuccess(HttpResponse response) {
153+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
153154
try {
154-
Channel value = objectMapper.readValue(response.getContent(), Channel.class);
155+
Channel value = objectMapper.readValue(content, Channel.class);
155156
handler.onSuccess(value);
156157
} catch (IOException e) {
157158
handler.onFailure(e);
@@ -178,7 +179,7 @@ public void startCommercial(final String channelName, final int length, final Co
178179

179180
http.post(url, params, new TwitchHttpResponseHandler(handler) {
180181
@Override
181-
public void onSuccess(HttpResponse response) {
182+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
182183
handler.onSuccess();
183184
}
184185
});
@@ -195,9 +196,9 @@ public void getTeams(final String channelName, final TeamsResponseHandler handle
195196

196197
http.get(url, new TwitchHttpResponseHandler(handler) {
197198
@Override
198-
public void onSuccess(HttpResponse response) {
199+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
199200
try {
200-
Teams value = objectMapper.readValue(response.getContent(), Teams.class);
201+
Teams value = objectMapper.readValue(content, Teams.class);
201202
handler.onSuccess(value.getTeams());
202203
} catch (IOException e) {
203204
handler.onFailure(e);
@@ -225,9 +226,9 @@ public void getFollows(final String channelName, final RequestParams params, fin
225226

226227
http.get(url, params, new TwitchHttpResponseHandler(handler) {
227228
@Override
228-
public void onSuccess(HttpResponse response) {
229+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
229230
try {
230-
ChannelFollows value = objectMapper.readValue(response.getContent(), ChannelFollows.class);
231+
ChannelFollows value = objectMapper.readValue(content, ChannelFollows.class);
231232
handler.onSuccess(value.getTotal(), value.getFollows());
232233
} catch (IOException e) {
233234
handler.onFailure(e);
@@ -271,9 +272,9 @@ public void getVideos(final String channelName, final RequestParams params, fina
271272

272273
http.get(url, params, new TwitchHttpResponseHandler(handler) {
273274
@Override
274-
public void onSuccess(HttpResponse response) {
275+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
275276
try {
276-
Videos value = objectMapper.readValue(response.getContent(), Videos.class);
277+
Videos value = objectMapper.readValue(content, Videos.class);
277278
handler.onSuccess(value.getTotal(), value.getVideos());
278279
} catch (IOException e) {
279280
handler.onFailure(e);
@@ -314,9 +315,9 @@ public void getSubscriptions(final String channelName, final RequestParams param
314315

315316
http.get(url, params, new TwitchHttpResponseHandler(handler) {
316317
@Override
317-
public void onSuccess(HttpResponse response) {
318+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
318319
try {
319-
ChannelSubscriptions value = objectMapper.readValue(response.getContent(), ChannelSubscriptions.class);
320+
ChannelSubscriptions value = objectMapper.readValue(content, ChannelSubscriptions.class);
320321
handler.onSuccess(value.getTotal(), value.getSubscriptions());
321322
} catch (IOException e) {
322323
handler.onFailure(e);
@@ -350,9 +351,9 @@ public void getSubscription(final String channelName, final String user, final C
350351

351352
http.get(url, new TwitchHttpResponseHandler(handler) {
352353
@Override
353-
public void onSuccess(HttpResponse response) {
354+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
354355
try {
355-
ChannelSubscription value = objectMapper.readValue(response.getContent(), ChannelSubscription.class);
356+
ChannelSubscription value = objectMapper.readValue(content, ChannelSubscription.class);
356357
handler.onSuccess(value);
357358
} catch (IOException e) {
358359
handler.onFailure(e);

src/main/java/com/mb3364/twitch/api/resources/ChatResource.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.mb3364.twitch.api.resources;
22

3-
import com.mb3364.http.HttpResponse;
43
import com.mb3364.twitch.api.handlers.BadgesResponseHandler;
54
import com.mb3364.twitch.api.handlers.EmoticonsResponseHandler;
65
import com.mb3364.twitch.api.models.ChannelBadges;
76
import com.mb3364.twitch.api.models.Emoticons;
87

98
import java.io.IOException;
9+
import java.util.List;
10+
import java.util.Map;
1011

1112
/**
1213
* The {@link ChatResource} provides the functionality
@@ -36,9 +37,9 @@ public void getEmoticons(final EmoticonsResponseHandler handler) {
3637

3738
http.get(url, new TwitchHttpResponseHandler(handler) {
3839
@Override
39-
public void onSuccess(HttpResponse response) {
40+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
4041
try {
41-
Emoticons value = objectMapper.readValue(response.getContent(), Emoticons.class);
42+
Emoticons value = objectMapper.readValue(content, Emoticons.class);
4243
handler.onSuccess(value.getEmoticons());
4344
} catch (IOException e) {
4445
handler.onFailure(e);
@@ -58,9 +59,9 @@ public void getBadges(final String channel, final BadgesResponseHandler handler)
5859

5960
http.get(url, new TwitchHttpResponseHandler(handler) {
6061
@Override
61-
public void onSuccess(HttpResponse response) {
62+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
6263
try {
63-
ChannelBadges value = objectMapper.readValue(response.getContent(), ChannelBadges.class);
64+
ChannelBadges value = objectMapper.readValue(content, ChannelBadges.class);
6465
handler.onSuccess(value);
6566
} catch (IOException e) {
6667
handler.onFailure(e);

src/main/java/com/mb3364/twitch/api/resources/GamesResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.mb3364.twitch.api.resources;
22

3-
import com.mb3364.http.HttpResponse;
43
import com.mb3364.http.RequestParams;
54
import com.mb3364.twitch.api.handlers.TopGamesResponseHandler;
65
import com.mb3364.twitch.api.models.Games;
76

87
import java.io.IOException;
8+
import java.util.List;
9+
import java.util.Map;
910

1011
/**
1112
* The {@link GamesResource} provides the functionality
@@ -40,9 +41,9 @@ public void getTop(final RequestParams params, final TopGamesResponseHandler han
4041

4142
http.get(url, params, new TwitchHttpResponseHandler(handler) {
4243
@Override
43-
public void onSuccess(HttpResponse response) {
44+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
4445
try {
45-
Games value = objectMapper.readValue(response.getContent(), Games.class);
46+
Games value = objectMapper.readValue(content, Games.class);
4647
handler.onSuccess(value.getTotal(), value.getTop());
4748
} catch (IOException e) {
4849
handler.onFailure(e);

src/main/java/com/mb3364/twitch/api/resources/IngestsResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.mb3364.twitch.api.resources;
22

3-
import com.mb3364.http.HttpResponse;
43
import com.mb3364.twitch.api.handlers.IngestsResponseHandler;
54
import com.mb3364.twitch.api.models.Ingests;
65

76
import java.io.IOException;
7+
import java.util.List;
8+
import java.util.Map;
89

910
/**
1011
* The {@link IngestsResource} provides the functionality
@@ -34,9 +35,9 @@ public void get(final IngestsResponseHandler handler) {
3435

3536
http.get(url, new TwitchHttpResponseHandler(handler) {
3637
@Override
37-
public void onSuccess(HttpResponse response) {
38+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
3839
try {
39-
Ingests value = objectMapper.readValue(response.getContent(), Ingests.class);
40+
Ingests value = objectMapper.readValue(content, Ingests.class);
4041
handler.onSuccess(value.getIngests());
4142
} catch (IOException e) {
4243
handler.onFailure(e);

src/main/java/com/mb3364/twitch/api/resources/RootResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.mb3364.twitch.api.resources;
22

3-
import com.mb3364.http.HttpResponse;
43
import com.mb3364.twitch.api.handlers.TokenResponseHandler;
54
import com.mb3364.twitch.api.models.Root;
65

76
import java.io.IOException;
7+
import java.util.List;
8+
import java.util.Map;
89

910
/**
1011
* The {@link RootResource} provides the functionality
@@ -35,9 +36,9 @@ public void get(final TokenResponseHandler handler) {
3536

3637
http.get(url, new TwitchHttpResponseHandler(handler) {
3738
@Override
38-
public void onSuccess(HttpResponse response) {
39+
public void onSuccess(int statusCode, Map<String, List<String>> headers, String content) {
3940
try {
40-
Root value = objectMapper.readValue(response.getContent(), Root.class);
41+
Root value = objectMapper.readValue(content, Root.class);
4142
handler.onSuccess(value.getToken());
4243
} catch (IOException e) {
4344
handler.onFailure(e);

0 commit comments

Comments
 (0)