· 5 years ago · Aug 27, 2020, 04:54 PM
1@RemoteAction
2public static Map<String, object> sendGBRequest(string request)
3
4//public static String sendGBRequest(string request)
5{
6 Map<String, object> returnData = new Map<String, object>();
7
8 // get the api key in static resource
9 StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'gb_api_key' LIMIT 1];
10 String apiKey = sr.Body.toString();
11
12 request = request.replace(' ','%20'); // #JOSH
13 HttpRequest req = new HttpRequest();
14 req.setTimeout(60000);
15 req.setMethod('GET');
16 req.setEndpoint('https://www.giantbomb.com/api/search/?format=json&api_key=' + apiKey + '&query=' + request + '&resources=game');
17
18 // System.debug(req + ' ' + request);
19
20 Http routeHTTP = new Http();
21 HttpResponse res = routeHTTP.send(req);
22 returnData = (Map<String,object>) JSON.deserializeuntyped(res.getBody());
23 return returnData;
24
25}
26
27@RemoteAction
28public static Map<String, object> sendGBRequestGame(string request)
29
30{
31 Map<String, object> returnData = new Map<String, object>();
32
33 // get the api key in static resource
34 StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'gb_api_key' LIMIT 1];
35 String apiKey = sr.Body.toString();
36
37 HttpRequest req = new HttpRequest();
38 req.setTimeout(60000);
39 req.setMethod('GET');
40 req.setEndpoint('https://www.giantbomb.com/api/game/' + request + '/?api_key=' + apiKey + '&format=json');
41
42 Http routeHTTP = new Http();
43 HttpResponse res = routeHTTP.send(req);
44 returnData = (Map<String,object>) JSON.deserializeuntyped(res.getBody());
45 return returnData;
46}