Skip to content

Commit 1bca92e

Browse files
committed
Working on RestClient
1 parent 4a42f31 commit 1bca92e

File tree

10 files changed

+177
-13
lines changed

10 files changed

+177
-13
lines changed

dota/src/main/java/com/michaelfotiadis/steam/dota2/Dota2Loader.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

gradlew

100644100755
File mode changed.

net/src/main/java/com/michaelfotiadis/steam/net/NetLoader.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.michaelfotiadis.steam.net;
2+
3+
import com.google.gson.Gson;
4+
import com.michaelfotiadis.steam.net.api.Dota2Api;
5+
import com.michaelfotiadis.steam.net.api.GamesApi;
6+
import com.michaelfotiadis.steam.net.api.SteamApi;
7+
import com.michaelfotiadis.steam.net.gson.SteamGson;
8+
9+
public class NetworkLoader {
10+
11+
private static final String ENDPOINT = "https://api.steampowered.com/";
12+
13+
private final RestClient steamRestClient;
14+
15+
public NetworkLoader(final boolean isDebugEnabled) {
16+
17+
final OkHttpFactory okHttpFactory = new OkHttpFactoryImpl(isDebugEnabled);
18+
final Gson gson = SteamGson.get();
19+
this.steamRestClient = new RestClient(ENDPOINT, gson, okHttpFactory);
20+
21+
}
22+
23+
public Dota2Api getDota2Api() {
24+
return this.steamRestClient.getDota2Api();
25+
}
26+
27+
public GamesApi getGamesApi() {
28+
return this.steamRestClient.getGamesApi();
29+
}
30+
31+
public SteamApi getSteamApi() {
32+
return this.steamRestClient.getSteamApi();
33+
}
34+
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.michaelfotiadis.steam.net;
2+
3+
import com.google.gson.Gson;
4+
import com.michaelfotiadis.steam.net.api.Dota2Api;
5+
import com.michaelfotiadis.steam.net.api.GamesApi;
6+
import com.michaelfotiadis.steam.net.api.SteamApi;
7+
8+
import retrofit2.Retrofit;
9+
10+
public class RestClient {
11+
12+
private final Retrofit2Factory mRetrofit2Factory;
13+
14+
public RestClient(final String baseUrl,
15+
final Gson gson,
16+
final OkHttpFactory factory) {
17+
18+
mRetrofit2Factory = new Retrofit2Factory(baseUrl, gson, factory);
19+
20+
}
21+
22+
public Dota2Api getDota2Api() {
23+
return createApi(Dota2Api.class);
24+
}
25+
26+
public GamesApi getGamesApi() {
27+
return createApi(GamesApi.class);
28+
}
29+
30+
public SteamApi getSteamApi() {
31+
return createApi(SteamApi.class);
32+
}
33+
34+
private synchronized <T> T createApi(final Class<T> clazz) {
35+
final Retrofit retrofit = mRetrofit2Factory.create(clazz);
36+
return retrofit.create(clazz);
37+
}
38+
39+
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.michaelfotiadis.steam.net;
2+
3+
import com.google.gson.Gson;
4+
5+
import okhttp3.OkHttpClient;
6+
import retrofit2.Retrofit;
7+
import retrofit2.converter.gson.GsonConverterFactory;
8+
9+
/*package*/ class Retrofit2Factory {
10+
11+
private final String baseUrl;
12+
private final Gson gson;
13+
private final OkHttpFactory httpFactory;
14+
15+
public Retrofit2Factory(final String baseUrl,
16+
final Gson gson,
17+
final OkHttpFactory httpFactory) {
18+
this.baseUrl = baseUrl;
19+
this.httpFactory = httpFactory;
20+
this.gson = gson;
21+
}
22+
23+
public Retrofit create(final Class<?> clazz) {
24+
25+
final retrofit2.Converter.Factory factory = GsonConverterFactory.create(gson);
26+
final OkHttpClient client = httpFactory.create(clazz);
27+
28+
return new Retrofit.Builder()
29+
.baseUrl(this.baseUrl)
30+
.client(client)
31+
.addConverterFactory(factory)
32+
.build();
33+
}
34+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.michaelfotiadis.steam.net.api;
2+
3+
import com.michaelfotiadis.steam.dota2.model.response.MatchDetailsResponse;
4+
import com.michaelfotiadis.steam.dota2.model.response.MatchHistoryResponse;
5+
import com.michaelfotiadis.steam.model.response.AccountResponse;
6+
7+
import retrofit2.Call;
8+
import retrofit2.http.GET;
9+
import retrofit2.http.Query;
10+
11+
public interface Dota2Api {
12+
13+
@GET("IDOTA2Match_570/GetMatchDetails/V001/?format=json")
14+
Call<MatchDetailsResponse> getMatchById(@Query("key") String key,
15+
@Query("match_id") String id);
16+
17+
@GET("ISteamUser/GetPlayerSummaries/v0002/")
18+
Call<AccountResponse> getPlayerById(@Query("key") String key,
19+
@Query("steamids") String id);
20+
21+
@GET("IDOTA2Match_570/GetMatchHistory/V001/")
22+
Call<MatchHistoryResponse> getMatchHistory(@Query("key") String key,
23+
@Query("account_id") String id,
24+
@Query("matches_requested") int matches);
25+
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.michaelfotiadis.steam.net.api;
2+
3+
import com.michaelfotiadis.steam.model.response.LibraryResponse;
4+
5+
import retrofit2.Call;
6+
import retrofit2.http.GET;
7+
import retrofit2.http.Query;
8+
9+
public interface GamesApi {
10+
11+
@GET("IPlayerService/GetOwnedGames/v0001/?format=json")
12+
Call<LibraryResponse> getGamesList(@Query("key") String key,
13+
@Query("steamid") String id,
14+
@Query("include_appinfo") int includeAppInfo,
15+
@Query("include_played_free_games") int includePlayedFreeGames);
16+
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.michaelfotiadis.steam.net.api;
2+
3+
import com.michaelfotiadis.steam.model.api.VanityResponse;
4+
5+
import retrofit2.Call;
6+
import retrofit2.http.GET;
7+
import retrofit2.http.Query;
8+
9+
/**
10+
* Retrofit interface
11+
*/
12+
public interface SteamApi {
13+
14+
@GET("ISteamUser/ResolveVanityURL/v0001/")
15+
Call<VanityResponse> getIdFromVanityUrl(@Query("key") String key,
16+
@Query("vanityurl") String url);
17+
18+
}

sample/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ android {
2323
}
2424

2525
dependencies {
26-
compile fileTree(include: ['*.jar'], dir: 'libs')
26+
27+
compile project(':net')
28+
29+
compile "com.android.support:appcompat-v7:$rootProject.appCompatLibVersion"
30+
2731
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2832
exclude group: 'com.android.support', module: 'support-annotations'
2933
})
30-
compile "com.android.support:appcompat-v7:$rootProject.appCompatLibVersion"
34+
3135
testCompile 'junit:junit:4.12'
32-
compile project(':dota')
36+
3337
}

0 commit comments

Comments
 (0)