Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
done cats API
Browse files Browse the repository at this point in the history
  • Loading branch information
xhsun committed Jun 15, 2017
1 parent 3d57d1d commit 94aad41
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/main/java/me/xhsun/guildwars2wrapper/AsynchronousRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,35 @@ public void getCurrentGameBuild(Callback<GameBuild> callback) throws NullPointer
gw2API.getCurrentGameBuild().enqueue(callback);
}

//Cats

/**
* For more info on cats API go <a href="https://wiki.guildwars2.com/wiki/API:2/cats">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)}
* @throws NullPointerException if given {@link Callback} is empty
* @see Cat cat info
*/
public void getAllCatID(Callback<List<Integer>> callback) throws NullPointerException {
gw2API.getAllCatIDs().enqueue(callback);
}

/**
* For more info on cats API go <a href="https://wiki.guildwars2.com/wiki/API:2/cats">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 cat id
* @param callback callback that is going to be used for {@link Call#enqueue(Callback)}
* @throws GuildWars2Exception empty ID list
* @throws NullPointerException if given {@link Callback} is empty
* @see Cat cat info
*/
public void getCatInfo(int[] ids, Callback<List<Cat>> callback) throws GuildWars2Exception, NullPointerException {
isParamValid(new ParamChecker(ids));
gw2API.getCatInfo(processIds(ids)).enqueue(callback);
}

//Characters
/**
* For more info on Character API go <a href="https://wiki.guildwars2.com/wiki/API:2/characters">here</a><br/>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/me/xhsun/guildwars2wrapper/GuildWars2API.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ interface GuildWars2API {
@GET("/v2/build")
Call<GameBuild> getCurrentGameBuild();

//TODO /v2/cats
//Cats
@GET("/v2/cats")
Call<List<Integer>> getAllCatIDs();

@GET("/v2/cats")
Call<List<Cat>> getCatInfo(@Query("ids") String ids);

//characters
@GET("/v2/characters")
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/me/xhsun/guildwars2wrapper/SynchronousRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,46 @@ public GameBuild getCurrentGameBuild() throws GuildWars2Exception {
}
}

//Cats

/**
* For more info on cats API go <a href="https://wiki.guildwars2.com/wiki/API:2/cats">here</a><br/>
* Get list of all available cat id(s)
*
* @return list of cat id(s)
* @throws GuildWars2Exception see {@link ErrorCode} for detail
* @see Color cat info
*/
public List<Integer> getAllCatID() throws GuildWars2Exception {
try {
Response<List<Integer>> response = gw2API.getAllCatIDs().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 cats API go <a href="https://wiki.guildwars2.com/wiki/API:2/cats">here</a><br/>
* Get cat info for the given cat id(s)
*
* @param ids array of cat id
* @return list of cat info
* @throws GuildWars2Exception see {@link ErrorCode} for detail
* @see Cat cat info
*/
public List<Cat> getCatInfo(int[] ids) throws GuildWars2Exception {
isParamValid(new ParamChecker(ids));
try {
Response<List<Cat>> response = gw2API.getCatInfo(processIds(ids)).execute();
if (!response.isSuccessful()) throwError(response.code(), response.errorBody());
return response.body();
} catch (IOException e) {
throw new GuildWars2Exception(ErrorCode.Network, "Network Error: " + e.getMessage());
}
}

//Characters
/**
* For more info on Character API go <a href="https://wiki.guildwars2.com/wiki/API:2/characters">here</a><br/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package me.xhsun.guildwars2wrapper.model.account;
package me.xhsun.guildwars2wrapper.model;

import me.xhsun.guildwars2wrapper.model.indentifiable.IdentifiableInt;

/**
* <a href="https://wiki.guildwars2.com/wiki/API:2/account/home/cats">Cat</a>
* For more info on cats API go <a href="https://wiki.guildwars2.com/wiki/API:2/cats">here</a><br/>
* Model class for cats
*
* @author xhsun
* @since 2017-06-05
Expand Down

0 comments on commit 94aad41

Please sign in to comment.