Skip to content

Commit f611e55

Browse files
author
husnjak
committed
2 parents 4501bb7 + 43aa383 commit f611e55

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

README.md

+46-46
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ APIWrapper wrapper = new APIWrapper(context, "YOUR_API_KEY");
4242

4343
## Usage
4444
All API endpoints are available as methods in the APIWrapper object. Each method has the following signature:
45-
### wrapper.endpoint(Map<Operator, String>)
45+
### wrapper.endpoint(Parameters, onSuccessCallback)
4646
__Arguments__
47-
* Operator - An object specifying an operation, ex. expander, filter, ordering etc. These Operations can be found in the API documentation under References: (https://igdb.github.io/api/references/)
48-
* String - The String is the accompaying data for the Operator, ex. game ids "1,2,3,4,5" OR fields "id,name,rating"
47+
* Parameters - An object specifying the operations to be performed, ex. expander, filter, ordering etc. These Operations can be found in the API documentation under References: (https://igdb.github.io/api/references/)
48+
* onSuccessCallback - The callback is used to return to the previous method once the wrapper has retrieved the desired data from the API.
4949

5050
__Example__
5151
* Requesting games from API
5252
``` java
5353
APIWrapper wrapper = new APIWrapper(context, "YOUR_API_KEY");
54-
Map<APIWrapper.Operator, String> args = new HashMap<>();
55-
args.put(APIWrapper.Operator.FIELDS,“*”);
56-
args.put(APIWrapper.Operator.ORDER, "published_at:desc");
57-
58-
wrapper.games(args, new onSuccessCallback(){
54+
Parameters params = new Parameters()
55+
.addFields("*")
56+
.addorder("published_at:desc");
57+
58+
wrapper.games(params, new onSuccessCallback(){
5959
@Override
6060
public void onSuccess(JSONArray result) {
6161
// Do something with resulting JSONArray
@@ -76,12 +76,12 @@ The rest of the endpoints work similarly to the Games endpoint except for two ca
7676
* Requesting search from the API
7777
``` java
7878
APIWrapper wrapper = new APIWrapper(context, "YOUR_API_KEY");
79-
Map<APIWrapper.Operator, String> args = new HashMap<>();
80-
args.put(APIWrapper.Operator.SEARCH, "SeachQuery");
81-
args.put(APIWrapper.Operator.FIELDS,“*”);
82-
args.put(APIWrapper.Operator.ORDER, "published_at:desc");
79+
Parameters params = new Parameters()
80+
.addSearch("searchQuery")
81+
.addFields("*")
82+
.addOrder("published_at:desc");
8383

84-
wrapper.search(APIWrapper.Endpoint.GAMES, args, new onSuccessCallback(){
84+
wrapper.search(APIWrapper.Endpoint.GAMES, params, new onSuccessCallback(){
8585
@Override
8686
public void onSuccess(JSONArray result) {
8787
// Do something with resulting JSONArray
@@ -102,12 +102,12 @@ The search endpoint need an extra parameter, Endpoint, as you can search any end
102102
* Filtering a request result
103103
``` java
104104
APIWrapper wrapper = new APIWrapper(context, "YOUR_API_KEY");
105-
Map<APIWrapper.Operator, String> args = new HashMap<>();
106-
args.put(APIWrapper.Operator.FIELDS,“*”);
107-
args.put(APIWrapper.Operator.FILTER, "[themes][not_in]=42");
108-
args.put(APIWrapper.Operator.ORDER, "published_at:desc");
105+
Parameters params = new Parameters()
106+
.addFields("*")
107+
.addFilter("[themes][not_in]=42")
108+
.addOrder("published_at:desc");
109109

110-
wrapper.games(args, new onSuccessCallback(){
110+
wrapper.games(params, new onSuccessCallback(){
111111
@Override
112112
public void onSuccess(JSONArray result) {
113113
// Do something with resulting JSONArray
@@ -138,12 +138,12 @@ APIWrapper wrapper = new APIWrapper(context, "YOUR_API_KEY");
138138
/*
139139
Search for up to two Atari platforms and return their names
140140
*/
141-
Map<APIWrapper.Operator, String> args = new HashMap<>();
142-
args.put(APIWrapper.Operator.SEARCH,“Atari”);
143-
args.put(APIWrapper.Operator.FIELDS,“name”);
144-
args.put(APIWrapper.Operator.LIMIT,“2);
141+
Parameters params = new Parameters()
142+
.addSearch("Atari")
143+
.addFields("name")
144+
.addLimit("2");
145145

146-
wrapper.search(APIWrapper.Endpoint.PLATFORMS, args, new onSuccessCallback(){
146+
wrapper.search(APIWrapper.Endpoint.PLATFORMS, params, new onSuccessCallback(){
147147
@Override
148148
public void onSuccess(JSONArray result) {
149149
// JSONArray containing 2 Atari platforms
@@ -162,16 +162,16 @@ https://api-2445582011268.apicast.io/platforms/?search=Atari&fields=name&limit=2
162162
Search for up to five Zelda games with release dates between 1 Jan and
163163
31 Dec 2011, sorted by release date in descending order.
164164
*/
165-
Map<APIWrapper.Operator, String> args = new HashMap<>();
166-
args.put(APIWrapper.Operator.SEARCH,“Zelda”);
167-
args.put(APIWrapper.Operator.FIELDS,“name,release_dates.date,rating,hypes,cover”);
168-
args.put(APIWrapper.Operator.FILTER,“[release_dates.date][gt]=2010-12-31”);
169-
args.put(APIWrapper.Operator.FILTER,“[release_dates.date][lt]=2012-01-01”);
170-
args.put(APIWrapper.Operator.LIMIT,“2”);
171-
args.put(APIWrapper.Operator.OFFSET,“0”);
172-
args.put(APIWrapper.Operator.ORDER,“release_dates.date:desc”);
173-
174-
wrapper.search(APIWrapper.Endpoint.PLATFORMS, args, new onSuccessCallback(){
165+
Parameters params = new Parameters()
166+
.addSearch("Zelda")
167+
.addFields(“name,release_dates.date,rating,hypes,cover”)
168+
.addFilter("[release_dates.date][gt]=2010-12-31”)
169+
.addFilter(“[release_dates.date][lt]=2012-01-01”)
170+
.addLimit("2")
171+
.addOffset("0")
172+
.addOrder(“release_dates.date:desc”);
173+
174+
wrapper.search(APIWrapper.Endpoint.PLATFORMS, params, new onSuccessCallback(){
175175
@Override
176176
public void onSuccess(JSONArray result) {
177177
// JSONArray containing 5 Zelda games
@@ -189,11 +189,11 @@ https://api-2445582011268.apicast.io/games/?search=Zelda&fields=name,release_dat
189189
/*
190190
Search for two specific games by their IDs
191191
*/
192-
Map<APIWrapper.Operator, String> args = new HashMap<>();
193-
args.put(APIWrapper.Operator.IDS,18472,18228”);
194-
args.put(APIWrapper.Operator.FIELDS,“name,cover”);
192+
Parameters params = new Parameters()
193+
.addIds(“18472,18228”)
194+
.addFields(“name,cover”);
195195
196-
wrapper.games(args, new onSuccessCallback(){
196+
wrapper.games(params, new onSuccessCallback(){
197197
@Override
198198
public void onSuccess(JSONArray result) {
199199
// JSONArray containing 2 games
@@ -212,15 +212,15 @@ https://api-2445582011268.apicast.io/games/18472,18228?fields=name,cover */
212212
Search for companies with 'rockstar' in their name. Return up to five
213213
results sorted by name in descending order
214214
*/
215-
Map<APIWrapper.Operator, String> args = new HashMap<>();
216-
args.put(APIWrapper.Operator.SEARCH,“rockstar”);
217-
args.put(APIWrapper.Operator.FIELDS,“name,logo”);
218-
args.put(APIWrapper.Operator.FILTER,“[name][in]=rockstar”);
219-
args.put(APIWrapper.Operator.LIMIT,“5”);
220-
args.put(APIWrapper.Operator.OFFSET,“0”);
221-
args.put(APIWrapper.Operator.ORDER,“name:desc”);
222-
223-
wrapper.search(APIWrapper.Endpoint.COMPANIES, args, new onSuccessCallback(){
215+
Parameters params = new Parameters()
216+
.addSearch("rockstar")
217+
.addFields(“name,logo”)
218+
.addFilter(“[name][in]=rockstar”)
219+
.addLimit("5")
220+
.addOffset("0")
221+
.addOrder(“name:desc”);
222+
223+
wrapper.search(APIWrapper.Endpoint.COMPANIES, params, new onSuccessCallback(){
224224
@Override
225225
public void onSuccess(JSONArray result) {
226226
// JSONArray containing five companies with rockstar in their name

0 commit comments

Comments
 (0)