Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d2eda62
Moved java files in request package
MiniClem Feb 22, 2019
3efe99d
Protected access need for Request childs
MiniClem Feb 24, 2019
286349f
method accessor
MiniClem Feb 24, 2019
c2996ed
v1 refactor
MiniClem Feb 24, 2019
d1e1187
v2 Token Info
MiniClem Feb 24, 2019
9605d6c
v2 account creation
MiniClem Feb 24, 2019
238dd31
Requests /account async
MiniClem Feb 24, 2019
1435160
Working on v2 async
MiniClem Feb 24, 2019
9ae1ca8
Guild Api Async
MiniClem Feb 28, 2019
3fea57a
Typos
MiniClem Feb 28, 2019
040f6ce
Item api Async
MiniClem Feb 28, 2019
78f30b5
Itemstats api Async
MiniClem Feb 28, 2019
0661ee5
Legends api Async
MiniClem Feb 28, 2019
3a7b30c
MailCarriers api Async
MiniClem Feb 28, 2019
1ee465d
Maps api Async
MiniClem Feb 28, 2019
b4e4a0b
Masteries api Async
MiniClem Feb 28, 2019
94e7884
Materials api Async
MiniClem Feb 28, 2019
d10fbb8
Minis api Async
MiniClem Feb 28, 2019
01422f6
Nodes api Async
MiniClem Feb 28, 2019
de48054
Outfits api Async
MiniClem Feb 28, 2019
aed4586
Pets api Async
MiniClem Feb 28, 2019
85fd6e1
Professions api Async
MiniClem Feb 28, 2019
4d64f6d
PVP api Async
MiniClem Feb 28, 2019
de435f2
Quaggans api Async
MiniClem Feb 28, 2019
ab8fd64
Races api Async
MiniClem Feb 28, 2019
71fafee
Raids api Async
MiniClem Feb 28, 2019
3ca4b8d
Recipes api Async
MiniClem Feb 28, 2019
4f156c0
Skills api Async
MiniClem Feb 28, 2019
5e1d09d
Skins api Async
MiniClem Feb 28, 2019
b66b55e
Specialization api Async
MiniClem Feb 28, 2019
ca97d76
Stories api Async
MiniClem Feb 28, 2019
8b8896b
Titles api Async
MiniClem Feb 28, 2019
8368c17
Traits api Async
MiniClem Feb 28, 2019
e1e5ce6
Worlds api Async
MiniClem Feb 28, 2019
d8de172
WvW api Async
MiniClem Feb 28, 2019
50698ec
Gw2 Account v2 async
MiniClem Mar 2, 2019
e8fcf8b
Account request async v2
MiniClem Mar 2, 2019
47bac00
Achievemnt request async v2
MiniClem Mar 2, 2019
03072e9
Backstory async request v2
MiniClem Mar 2, 2019
3736e62
Commerce request async v2
MiniClem Mar 2, 2019
11a1112
Guild request async v2
MiniClem Mar 2, 2019
656bf46
Pvp request async v2
MiniClem Mar 2, 2019
cd50611
Recipes request async v2
MiniClem Mar 2, 2019
bc63d5c
Stories request async v2
MiniClem Mar 2, 2019
fd4a505
Wvw request async v2
MiniClem Mar 2, 2019
4f5affa
Wvw request async v1
MiniClem Mar 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ dist/
nbdist/
.nb-gradle/
MiniClemgw2wrapper.iml

gw2wrapper\.iml
5 changes: 4 additions & 1 deletion src/main/java/me/xhsun/guildwars2wrapper/GuildWars2.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
import me.xhsun.guildwars2wrapper.requests.AsynchronousRequest;
import me.xhsun.guildwars2wrapper.requests.GuildWars2API;
import me.xhsun.guildwars2wrapper.requests.SynchronousRequest;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -36,7 +39,7 @@ public String getValue() {
}
private static final String API = "https://api.guildwars2.com";
private static volatile GuildWars2 instance = null;
static volatile LanguageSelect lang = LanguageSelect.English;
public static volatile LanguageSelect lang = LanguageSelect.English;
private volatile GuildWars2API gw2API;
private volatile SynchronousRequest synchronous;
private volatile AsynchronousRequest asynchronous;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.xhsun.guildwars2wrapper;
package me.xhsun.guildwars2wrapper.requests;

import me.xhsun.guildwars2wrapper.GuildWars2;
import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
import me.xhsun.guildwars2wrapper.model.v1.AllWvWMatchOverview;
Expand Down Expand Up @@ -48,7 +49,7 @@
*/

public class AsynchronousRequest extends Request {
AsynchronousRequest(GuildWars2API gw2API) {
public AsynchronousRequest(GuildWars2API gw2API) {
super(gw2API);
}

Expand Down Expand Up @@ -620,6 +621,7 @@ public void getBackStoryQuestionInfo(int[] ids, Callback<List<BackStoryQuestion>
gw2API.getBackStoryQuestionInfo(processIds(ids), GuildWars2.lang.getValue()).enqueue(callback);
}

//Builds
/**
* For more info on build API go <a href="https://wiki.guildwars2.com/wiki/API:2/build">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
Expand Down Expand Up @@ -1796,7 +1798,7 @@ public void getMailCarrierInfo(int[] ids, Callback<List<MailCarrier>> callback)
//Maps

/**
* For more info on mail carriers API go <a href="https://wiki.guildwars2.com/wiki/API:2/mailcarriers">here</a><br/>
* For more info on map API go <a href="https://wiki.guildwars2.com/wiki/API:2/maps">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
*
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
Expand All @@ -1808,7 +1810,7 @@ public void getAllMapID(Callback<List<Integer>> callback) throws NullPointerExce
}

/**
* For more info on map API go <a href="https://wiki.guildwars2.com/wiki/API:2/mailcarriers">here</a><br/>
* For more info on map API go <a href="https://wiki.guildwars2.com/wiki/API:2/maps">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
*
* @param ids list of map id
Expand Down Expand Up @@ -2178,7 +2180,7 @@ public void getPvPSeasonLeaderBoardInfo(String id, String type, World.Region reg
//PvP Standings

/**
* For more info on pvp season API go <a href="https://wiki.guildwars2.com/wiki/API:2/pvp/seasons">here</a><br/>
* For more info on pvp season API go <a href="https://wiki.guildwars2.com/wiki/API:2/pvp/standings">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
*
* @param api Guild Wars 2 API key
Expand Down Expand Up @@ -2728,7 +2730,7 @@ public void getWvWMatchStat(String[] ids, Callback<List<WvWMatchStat>> callback)
//WvW Objectives

/**
* For more info on WvW abilities API go <a href="https://wiki.guildwars2.com/wiki/API:2/wvw/abilities">here</a><br/>
* For more info on WvW objectives API go <a href="https://wiki.guildwars2.com/wiki/API:2/wvw/objectives">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
*
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
Expand All @@ -2740,7 +2742,7 @@ public void getAllWvWObjectiveID(Callback<List<String>> callback) throws NullPoi
}

/**
* For more info on WvW abilities API go <a href="https://wiki.guildwars2.com/wiki/API:2/wvw/abilities">here</a><br/>
* For more info on WvW objectives API go <a href="https://wiki.guildwars2.com/wiki/API:2/wvw/objectives">here</a><br/>
* Give user the access to {@link Callback#onResponse(Call, Response)} and {@link Callback#onFailure(Call, Throwable)} methods for custom interactions
*
* @param ids list of WvW objective id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.xhsun.guildwars2wrapper;
package me.xhsun.guildwars2wrapper.requests;

import java.util.*;

Expand Down Expand Up @@ -27,7 +27,7 @@
* @author xhsun
* @since 2017-02-07
*/
interface GuildWars2API {
public interface GuildWars2API {
//API:1
//Event Detail (lang)
@GET("/v1/event_details.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.xhsun.guildwars2wrapper;
package me.xhsun.guildwars2wrapper.requests;

import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
Expand All @@ -14,35 +14,35 @@
* @since 2017-06-04
*/

abstract class Request {
GuildWars2API gw2API;
public abstract class Request {
protected GuildWars2API gw2API;

Request(GuildWars2API gw2API) {
protected Request(GuildWars2API gw2API) {
this.gw2API = gw2API;
}

//convert list of ids to comma separated list
String processIds(int[] list) throws GuildWars2Exception {
protected String processIds(int[] list) throws GuildWars2Exception {
if (list.length > 200) throw new GuildWars2Exception(ErrorCode.ID, "Exceeded upper limit (200 ids) for id list");
StringBuilder ids = new StringBuilder();
for (int id : list) ids.append(id).append(",");
return ids.toString().trim().substring(0, ids.length() - 1);
}

String processIds(String[] list) throws GuildWars2Exception {
protected String processIds(String[] list) throws GuildWars2Exception {
if (list.length > 200) throw new GuildWars2Exception(ErrorCode.ID, "Exceeded upper limit (200 ids) for id list");
StringBuilder ids = new StringBuilder();
for (String id : list) ids.append(id).append(",");
return ids.toString().trim().substring(0, ids.length() - 1);
}

void isValueValid(long value) throws GuildWars2Exception {
protected void isValueValid(long value) throws GuildWars2Exception {
if (value > 0) return;
throw new GuildWars2Exception(ErrorCode.Other, "Invalid Value");
}

//throw error base on error code and error response
void throwError(int code, ResponseBody body) throws GuildWars2Exception {
protected void throwError(int code, ResponseBody body) throws GuildWars2Exception {
try {
String respond;
if (body == null) respond = "";
Expand All @@ -55,7 +55,7 @@ void throwError(int code, ResponseBody body) throws GuildWars2Exception {
}

//check if parameters are valid or not
void isParamValid(ParamChecker... items) throws GuildWars2Exception {
protected void isParamValid(ParamChecker... items) throws GuildWars2Exception {
for (ParamChecker c : items) {
if (c.type != ParamType.IDS && c.type != ParamType.STR_IDS) {
if (c.value == null || c.value.equals("")) {
Expand Down Expand Up @@ -90,27 +90,27 @@ void isParamValid(ParamChecker... items) throws GuildWars2Exception {
}

//for helping with throwing appropriate if parameters are invalid
class ParamChecker {
protected class ParamChecker {
ParamType type;
String value;
int[] ids;
String[] str_id;

ParamChecker(ParamType t, String s) {
public ParamChecker(ParamType t, String s) {
type = t;
value = s;
}

ParamChecker(int[] i) {
public ParamChecker(int[] i) {
type = ParamType.IDS;
ids = i;
}

ParamChecker(String[] i) {
public ParamChecker(String[] i) {
type = ParamType.STR_IDS;
str_id = i;
}
}

enum ParamType {API, CHAR, GUILD, ID, IDS, STR_IDS}
protected enum ParamType {API, CHAR, GUILD, ID, IDS, STR_IDS}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.xhsun.guildwars2wrapper;
package me.xhsun.guildwars2wrapper.requests;

import me.xhsun.guildwars2wrapper.GuildWars2;
import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
import me.xhsun.guildwars2wrapper.model.v1.AllWvWMatchOverview;
Expand Down Expand Up @@ -44,7 +45,7 @@
*/

public class SynchronousRequest extends Request {
SynchronousRequest(GuildWars2API gw2API) {
public SynchronousRequest(GuildWars2API gw2API) {
super(gw2API);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package me.xhsun.guildwars2wrapper.requests.v1;

import java.io.IOException;
import me.xhsun.guildwars2wrapper.GuildWars2;
import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
import me.xhsun.guildwars2wrapper.model.v1.EventDetail;
import me.xhsun.guildwars2wrapper.requests.GuildWars2API;
import me.xhsun.guildwars2wrapper.requests.Request;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EventDetails extends Request {

protected EventDetails(GuildWars2API gw2API) {
super(gw2API);
}

// ASYNC
/**
* For more info on event detail API go <a href="https://wiki.guildwars2.com/wiki/API:1/event_details">here</a><br/>
*
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
* @throws NullPointerException if given {@link Callback} is null
* @see EventDetail event detail
*/
public void getAllEventDetailedInfo(Callback<EventDetail> callback) throws NullPointerException {
gw2API.getAllEventDetailedInfo(GuildWars2.lang.getValue()).enqueue(callback);
}

/**
* For more info on event detail API go <a href="https://wiki.guildwars2.com/wiki/API:1/event_details">here</a><br/>
*
* @param id event id
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
* @throws GuildWars2Exception invalid id
* @throws NullPointerException if given {@link Callback} is null
* @see EventDetail event detail
*/
public void getEventDetailedInfo(String id, Callback<EventDetail> callback) throws GuildWars2Exception, NullPointerException {
isParamValid(new ParamChecker(ParamType.ID, id));
gw2API.getEventDetailedInfo(id, GuildWars2.lang.getValue()).enqueue(callback);
}

//SYNC
/**
* For more info on event detail API go <a href="https://wiki.guildwars2.com/wiki/API:1/event_details">here</a><br/>
*
* @return event details
* @throws GuildWars2Exception see {@link ErrorCode} for detail
* @see EventDetail event detail
*/
public EventDetail getAllEventDetailedInfo() throws GuildWars2Exception {
try {
Response<EventDetail> response = gw2API.getAllEventDetailedInfo(GuildWars2.lang.getValue()).execute();
if (!response.isSuccessful()) throwError(response.code(), response.errorBody());
return response.body();
} catch (IOException e) {
throw new GuildWars2Exception(ErrorCode.Network, "Network Error: " + e.getMessage());
}
}

/**
* For more info on event detail API go <a href="https://wiki.guildwars2.com/wiki/API:1/event_details">here</a><br/>
*
* @param id event id
* @return event details
* @throws GuildWars2Exception see {@link ErrorCode} for detail
* @see EventDetail event detail
*/
public EventDetail getEventDetailedInfo(String id) throws GuildWars2Exception {
isParamValid(new ParamChecker(ParamType.ID, id));
try {
Response<EventDetail> response = gw2API.getEventDetailedInfo(id, GuildWars2.lang.getValue()).execute();
if (!response.isSuccessful()) throwError(response.code(), response.errorBody());
return response.body();
} catch (IOException e) {
throw new GuildWars2Exception(ErrorCode.Network, "Network Error: " + e.getMessage());
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/me/xhsun/guildwars2wrapper/requests/v1/MapNames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.xhsun.guildwars2wrapper.requests.v1;

import java.io.IOException;
import java.util.List;
import me.xhsun.guildwars2wrapper.GuildWars2;
import me.xhsun.guildwars2wrapper.error.ErrorCode;
import me.xhsun.guildwars2wrapper.error.GuildWars2Exception;
import me.xhsun.guildwars2wrapper.model.v1.SimpleName;
import me.xhsun.guildwars2wrapper.requests.GuildWars2API;
import me.xhsun.guildwars2wrapper.requests.Request;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MapNames extends Request {

protected MapNames(GuildWars2API gw2API) {
super(gw2API);
}

//ASYNC
/**
* For more info on map names API go <a href="https://wiki.guildwars2.com/wiki/API:1/map_names">here</a><br/>
*
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
* @throws NullPointerException if given {@link Callback} is null
* @see SimpleName map name
*/
public void getAllMapNames(Callback<List<SimpleName>> callback) throws NullPointerException {
gw2API.getAllMapNames(GuildWars2.lang.getValue()).enqueue(callback);
}

//SYNC
/**
* For more info on map name API go <a href="https://wiki.guildwars2.com/wiki/API:1/map_names">here</a><br/>
*
* @return list of names
* @throws GuildWars2Exception see {@link ErrorCode} for detail
* @see SimpleName map name
*/
public List<SimpleName> getAllMapNames() throws GuildWars2Exception {
try {
Response<List<SimpleName>> response = gw2API.getAllMapNames(GuildWars2.lang.getValue()).execute();
if (!response.isSuccessful()) throwError(response.code(), response.errorBody());
return response.body();
} catch (IOException e) {
throw new GuildWars2Exception(ErrorCode.Network, "Network Error: " + e.getMessage());
}
}
}
Loading