@Component public class ApiClient extends RestTemplate
Provides a simple interface for interacting with the public Guild
Wars 2 API. Whenever possible, methods of this interface will return simple
objects. However, if there is a possibility for an error being returned by
the remote API, then the resulting object of this client's method will be
wrapped in an Optional
. In all such cases,
an instance of GwApiError
will be thrown.
This error can either be ignored, or it can be trapped with a
try...catch
construct.
You can either instantiate this class directly, or use the
getInstance()
method to retrieve a static instance.
logger
Constructor and Description |
---|
ApiClient() |
Modifier and Type | Method and Description |
---|---|
String |
getBaseUrl()
Utility method mainly used for testing.
|
Build |
getBuild()
Retrieve the current build number for Guild Wars 2.
|
ColorsList |
getColors()
Retrieve the list of colors localized to the English language.
|
ColorsList |
getColors(String lang)
Retrieve the list of colors localized to the specified language.
|
Continents |
getContinents()
Retrieve the list of continents.
|
com.google.common.base.Optional<EventDetails> |
getEventDetails()
Retrieve the full list of events and their details localized to the
English language.
|
com.google.common.base.Optional<EventDetails> |
getEventDetailsForEventId(String eventId)
Retrieve the details for a given event identifier.
|
com.google.common.base.Optional<EventDetails> |
getEventDetailsForEventIdInLang(String eventId,
String lang)
Retrieve a list of event details as described in
API:1/event_details.
|
EventNamesList |
getEventNames()
Retrieve a list of event names localized to the English language.
|
EventNamesList |
getEventNamesForLang(String lang)
Retrieve a list of event names localized to the given language abbreviation.
|
WorldEventsStatusList |
getEventStatuses()
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForEvent(String eventId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForMap(int mapId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForMapAndEvent(int mapId,
String eventId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForWorld(int worldId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForWorldAndEvent(int worldId,
String eventId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForWorldAndMap(int worldId,
int mapId)
Retrieve a list of event statuses.
|
WorldEventsStatusList |
getEventStatusesForWorldAndMapAndEvent(int worldId,
int mapId,
String eventId)
Retrieve a list of event statuses from
/v1/events.
|
Files |
getFiles()
Retrieve a list of commonly requested game asset files.
|
com.google.common.base.Optional<Floor> |
getFloorInLang(int continentId,
int floorId,
String lang)
Retrieve details about a map floor given the appropriate
continentId , floorId , and lang . |
com.google.common.base.Optional<Guild> |
getGuildDetailsForGuildId(String guildId)
Retrieves details for a guild with the specified
guildId . |
com.google.common.base.Optional<Guild> |
getGuildDetailsForGuildName(String name)
Retrieves details for a guild with the specified
name . |
static ApiClient |
getInstance()
A factory method to get a static instance of
ApiClient . |
com.google.common.base.Optional<Item> |
getItemDetails(int itemId)
Retrieves details for a specified item localized to the English language.
|
com.google.common.base.Optional<Item> |
getItemDetailsInLang(int itemId,
String lang)
Retrieves details for a specified item localized to the specified
language.
|
ItemIdList |
getItems()
Retrieves a list of all known item identifiers.
|
com.google.common.base.Optional<Map> |
getMap(int mapId)
Retrieve the details for a given
mapId localized
to the English language. |
com.google.common.base.Optional<Map> |
getMapInLang(int mapId,
String lang)
Retrieve the details for a given
mapId localized to the
specified lang . |
MapNamesList |
getMapNames()
Retrieve a list of map names and their associated map identifiers.
|
MapNamesList |
getMapNamesInLang(String lang)
Retrieve a list of map names and their associated map identifiers.
|
com.google.common.base.Optional<MapsList> |
getMaps()
Retrieve the complete list of maps localized to the English
language.
|
com.google.common.base.Optional<MapsList> |
getMapsInLang(int mapId,
String lang)
Retrieves a list of maps for the specified
mapId and
localized to the specified lang . |
com.google.common.base.Optional<MapsList> |
getMapsInLang(String lang)
Retrieve the complete list of maps localized to the specified
language.
|
com.google.common.base.Optional<MatchDetails> |
getMatchDetails(String matchId)
Retrieve details for a specific WvW
matchId . |
MatchesList |
getMatches()
Retrieve a list of World vs World matches that are currently running.
|
com.google.common.base.Optional<Floor> |
getMistsFloor(int floorId)
Retrieve details about a map floor on the "Mists" continent.
|
com.google.common.base.Optional<Floor> |
getMistsFloorInLang(int floorId,
String lang)
Retrieve details about a map floor on the "Mists" continent.
|
ObjectiveNamesList |
getObjectiveNames()
Retrieve a list of World vs World
ObjectiveName s localized to the
English language. |
ObjectiveNamesList |
getObjectiveNamesInLang(String lang)
Retrieve a list of World vs World
ObjectiveName s localized to the
specified lang . |
com.google.common.base.Optional<Recipe> |
getRecipe(int recipeId)
Retrieve details for a specific recipe localized to the English language.
|
com.google.common.base.Optional<Recipe> |
getRecipeInLang(int recipeId,
String lang)
Retrieve details about a specific recipe identified by
recipeId . |
RecipesList |
getRecipes()
Retrieve the list of
Recipe
identifiers. |
com.google.common.base.Optional<Floor> |
getTyriaFloor(int floorId)
Retrieve details about a map floor on the "Tyria" continent.
|
com.google.common.base.Optional<Floor> |
getTyriaFloorInLang(int floorId,
String lang)
Retrieve details about a map floor on the "Tyria" continent.
|
WorldNamesList |
getWorldNames()
Retrieve a list of available game world (server) names localized to
the English language.
|
WorldNamesList |
getWorldNamesInLang(String lang)
Retrieve a list of the available game world (server) names localized to
the specified
lang . |
acceptHeaderRequestCallback, delete, delete, delete, doExecute, exchange, exchange, exchange, exchange, exchange, exchange, execute, execute, execute, getErrorHandler, getForEntity, getForEntity, getForEntity, getForObject, getForObject, getForObject, getMessageConverters, headersExtractor, headForHeaders, headForHeaders, headForHeaders, httpEntityCallback, httpEntityCallback, optionsForAllow, optionsForAllow, optionsForAllow, postForEntity, postForEntity, postForEntity, postForLocation, postForLocation, postForLocation, postForObject, postForObject, postForObject, put, put, put, responseEntityExtractor, setErrorHandler, setMessageConverters
getInterceptors, getRequestFactory, setInterceptors
createRequest, setRequestFactory
public static ApiClient getInstance()
ApiClient
.public String getBaseUrl()
public Build getBuild()
Build
.public ColorsList getColors()
ColorsList
.public ColorsList getColors(String lang)
lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".ColorsList
.public Continents getContinents()
Continents
.public com.google.common.base.Optional<EventDetails> getEventDetails()
getEventDetailsForEventId(String)
for a
better method to use.EventDetails
wrapped in an Optional
. If there was an
error, then the Optional
will be empty. In this case, a
GwApiError
will be thrown. You can trap
that exception if you need more details.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<EventDetails> getEventDetailsForEventId(String eventId)
getEventNames()
. The
details will be localized to the English language. For a different
localization use
getEventDetailsForEventIdInLang(String, String)
.eventId
- The event identifier to lookup.EventDetails
wrapped in an Optional
. If there was an
error, then the Optional
will be empty. In this case, a
GwApiError
will be thrown. You can trap
that exception if you need more details.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<EventDetails> getEventDetailsForEventIdInLang(String eventId, String lang)
eventId
is given, a full list of event details will be
retrieved -- this will be slow.eventId
- A valid event identifier.
See getEventNamesForLang(String)
for a way to get a list of valid identifiers.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".EventDetails
wrapped in an Optional
. If there was an
error, then the Optional
will be empty. In this case, a
GwApiError
will be thrown. You can trap
that exception if you need more details.{@link
- com.jrfom.gw2.api.model.GwApiError}public EventNamesList getEventNames()
EventNamesList
.public EventNamesList getEventNamesForLang(String lang)
null
), or the abbreviation is
invalid, then the names will be localized to English ("en").lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".EventNamesList
.public WorldEventsStatusList getEventStatuses()
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
Important: this method literally returns all possible event statuses across all game worlds and game maps. It is extremely unlikely that you want this, and it is a very slow process. You should really use one of the narrower methods for getting event statuses.
public WorldEventsStatusList getEventStatusesForWorld(int worldId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be a list that is constrained to only one world. It will be all events for that world across all game maps.
worldId
- A valid world id or -1
for all worlds.public WorldEventsStatusList getEventStatusesForMap(int mapId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be list that is constrained to only a certain game map. The list will consists of all events in that map for all game worlds.
mapId
- A valid map id or -1
for all maps.public WorldEventsStatusList getEventStatusesForWorldAndMap(int worldId, int mapId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be a list that is constrained to a specific map on a specific world. Thus, this should be a fast response.
worldId
- A valid world id or -1
for all worlds.mapId
- A valid map id or -1
for all maps.public WorldEventsStatusList getEventStatusesForEvent(String eventId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be a list of event statuses for a single event across all game worlds and, potentially, all game maps.
eventId
- A valid event identifier.
See getEventNamesForLang(String)
for a way to get a list of valid identifiers.eventId
or a list of all
possible event statuses if the eventId
is invalid. Hint: use a
valid event identifier. You don't want the full list.public WorldEventsStatusList getEventStatusesForWorldAndEvent(int worldId, String eventId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be a list that is constrained to a specific game world, but will contain all events with the given event identifier.
worldId
- A valid world id or -1
for all worlds.eventId
- A valid event identifier.
See getEventNamesForLang(String)
for a way to get a list of valid identifiers.public WorldEventsStatusList getEventStatusesForMapAndEvent(int mapId, String eventId)
Retrieve a list of event statuses. See
getEventStatusesForWorldAndMapAndEvent(int, int, String)
for full details.
The result of this method will be list of event statuses that are constrained to a specific game map but across all game worlds.
mapId
- A valid map id or -1
for all maps.eventId
- A valid event identifier.
See getEventNamesForLang(String)
for a way to get a list of valid identifiers.public WorldEventsStatusList getEventStatusesForWorldAndMapAndEvent(int worldId, int mapId, String eventId)
Retrieve a list of event statuses from /v1/events. This list can be filtered by any combination of the method parameters.
Note: if you give any parameter that is invalid, no
error will be returned by the remote API. If either the worldId
or mapId
are incorrect then an empty list will be returned. If
the only invalid parameter is the eventId
then it will be ignore.
If the only given parameter is the eventId
, that is worldId
and mapId
are -1
, then the whole list of events for every
world and map will be retrieved.
worldId
- A valid world id or -1
for all worlds.mapId
- A valid map id or -1
for all maps.eventId
- A valid event identifier.
See getEventNamesForLang(String)
for a way to get a list of valid identifiers.public com.google.common.base.Optional<Guild> getGuildDetailsForGuildId(String guildId)
Retrieves details for a guild with the specified guildId
.
If the id you supply cannot be found, the remote service will return
an error object. Thus, a GwApiError
will
be thrown. You can trap that error if you would like more details.
Otherwise, simply check for the presence of a value in this method's
result.
guildId
- The UUID for the guild to lookup.Guild
wrapped in
an Optional
on success. On failure, the
Optional
will be empty.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Guild> getGuildDetailsForGuildName(String name)
Retrieves details for a guild with the specified name
. If the
name includes spaces, do not URI encode them. This method will
take care of encoding for you.
If the name you supply cannot be found, the remote service will return
an error object. Thus, a GwApiError
will
be thrown. You can trap that error if you would like more details.
Otherwise, simply check for the presence of a value in this method's
result.
name
- The name of the guild to lookup.Guild
wrapped in
an Optional
on success. On failure, the
Optional
will be empty.{@link
- com.jrfom.gw2.api.model.GwApiError}public ItemIdList getItems()
Retrieves a list of all known item identifiers. Your application should probably cache this result for some amount of time.
See /v1/items for more details.
ItemIdList
.public com.google.common.base.Optional<Item> getItemDetails(int itemId)
getItemDetailsInLang(int, String)
for
more information.itemId
- A valid game item identifier.Item
wrapped
in an Optional
if successful, otherwise an
empty Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Item> getItemDetailsInLang(int itemId, String lang)
Retrieves details for a specified item localized to the specified language. If the given language identifier is invalid, the English language will be used. Possible language identifiers are:
The result of this method will be wrapped in an
Optional
. If an invalid item identifier is
given, then this Optional
will be empty and a
GwApiError
will be thrown (trap it for
more details). Otherwise, the Optional
will contain an instance
of Item
. Possible types for
Item
are:
itemId
- A valid game item identifier.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".Item
wrapped
in an Optional
if successful, otherwise an
empty Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Map> getMap(int mapId)
Retrieve the details for a given mapId
localized
to the English language. See
getMapInLang(int, String)
for
more detail.
mapId
- A valid map id.Map
wrapped in an Optional
or an empty
Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Map> getMapInLang(int mapId, String lang)
Retrieve the details for a given mapId
localized to the
specified lang
.
If the mapId
is invalid then an instance of
GwApiError
will be thrown and an empty
Optional
will be returned.
If an invalid lang
is given, then the default language of
English ("en") will be used instead.
mapId
- A valid map id.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".Map
wrapped in an Optional
or an empty
Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<MapsList> getMaps()
Retrieve the complete list of maps localized to the English
language. See getMapsInLang(int, String)
for more detail.
MapsList
wrapped in an Optional
or an empty
Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<MapsList> getMapsInLang(String lang)
Retrieve the complete list of maps localized to the specified
language. See getMapsInLang(int, String)
for more detail.
lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".MapsList
wrapped in an Optional
or an empty
Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<MapsList> getMapsInLang(int mapId, String lang)
Retrieves a list of maps for the specified mapId
and
localized to the specified lang
. In theory, if you supply a
then you should get back a list with only one element. So, to
retrieve a list of all maps, supply a set to
-1
.
If the is invalid, a GwApiError
will be thrown and an empty Optional
will
be returned.
If the specified lang
is invalid, then the default language of
English ("en") will be used.
mapId
- A valid map id or -1
for all maps.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".MapsList
wrapped in an Optional
or an empty
Optional
.{@link
- com.jrfom.gw2.api.model.GwApiError}public MapNamesList getMapNames()
MapNamesList
.public MapNamesList getMapNamesInLang(String lang)
lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".MapNamesList
.public com.google.common.base.Optional<Floor> getTyriaFloor(int floorId)
Retrieve details about a map floor on the "Tyria" continent. See
getFloorInLang(int, int, String)
for
more deatils.
floorId
- A valid Floor
identifier.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Floor> getTyriaFloorInLang(int floorId, String lang)
Retrieve details about a map floor on the "Tyria" continent. See
getFloorInLang(int, int, String)
for
more deatils.
floorId
- A valid Floor
identifier.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Floor> getMistsFloor(int floorId)
Retrieve details about a map floor on the "Mists" continent. See
getFloorInLang(int, int, String)
for
more deatils.
floorId
- A valid Floor
identifier.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Floor> getMistsFloorInLang(int floorId, String lang)
Retrieve details about a map floor on the "Mists" continent. See
getFloorInLang(int, int, String)
for
more deatils.
floorId
- A valid Floor
identifier.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Floor> getFloorInLang(int continentId, int floorId, String lang)
Retrieve details about a map floor given the appropriate
continentId
, floorId
, and lang
. The given
lang
will localize all strings to said language.
continentId
- A valid Continent
identifier.floorId
- A valid Floor
identifier.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".Floor
wrapped in an Optional
or an empty
Optional
. The empty Optional
will be returned when either
an invalid continentId
or floorId
is given. This method
will not throw an instance of
GwApiError
in such instances. This is
because the remote ArenaNet API does not generate an error in this case.{@link
- com.jrfom.gw2.api.model.GwApiError}public RecipesList getRecipes()
Recipe
identifiers.RecipesList
.public com.google.common.base.Optional<Recipe> getRecipe(int recipeId)
getRecipeInLang(int, String)
for more
details.recipeId
- A valid recipe identifier.Recipe
wrapped in an Optional
or an empty
Optional
. If an empty Optional
was returned, an instance
of GwApiError
was also thrown.{@link
- com.jrfom.gw2.api.model.GwApiError}public com.google.common.base.Optional<Recipe> getRecipeInLang(int recipeId, String lang)
Retrieve details about a specific recipe identified by recipeId
.
The details will be localized to the specified lang
. If an
invalid recipeId
is given, a
GwApiError
will be thrown.
recipeId
- A valid recipe identifier.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".Recipe
wrapped in an Optional
or an empty
Optional
. If an empty Optional
was returned, an instance
of GwApiError
was also thrown.{@link
- com.jrfom.gw2.api.model.GwApiError}public WorldNamesList getWorldNames()
WorldNamesList
.public WorldNamesList getWorldNamesInLang(String lang)
lang
.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".WorldNamesList
.public ObjectiveNamesList getObjectiveNames()
ObjectiveName
s localized to the
English language.ObjectiveNamesList
.public ObjectiveNamesList getObjectiveNamesInLang(String lang)
ObjectiveName
s localized to the
specified lang
.lang
- A valid language abbreviation. For example, "en" for English or
"de" for German. An invalid abbreviation will equate to using
"en".ObjectiveNamesList
.public MatchesList getMatches()
public com.google.common.base.Optional<MatchDetails> getMatchDetails(String matchId)
matchId
. The matchId
can be determined by inspecting the results of
getMatches()
.matchId
- A valid match identifier.MatchDetails
wrapped in an Optional
or an empty
Optional
if the matchId
was invalid. If the matchId
was invalid, an instance of GwApiError
will
haven been thrown.{@link
- com.jrfom.gw2.api.model.GwApiError}public Files getFiles()
GameAssetFile
has methods for retrieving
a URL to the
render service
for that specific asset.Files
.Copyright © 2014. All Rights Reserved.