Skip to content

Commit c0b1903

Browse files
committed
Merge branch 'v2000'
2 parents 51a73f0 + 30e64da commit c0b1903

7 files changed

+160
-122
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
config.json
22
node_modules
3+
sandbox.js

README.md

+22-64
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ https://www.igdb.com/api
99
IGDB
1010
=
1111

12-
Nodejs Wrapper for IGDB.com API. Requires an API key. Request one from your user settings screen.
12+
Nodejs Wrapper for IGDB.com API. Requires a Mashape.com API key.
1313

14-
Read more: https://www.igdb.com/api/v1/documentation
14+
Read more: https://market.mashape.com/igdbcom/internet-game-database/overview
1515

1616
Setup
1717
-
@@ -23,97 +23,55 @@ Usage
2323
-
2424

2525
**Games**
26-
https://www.igdb.com/api/v1/documentation/games
2726

28-
* `games.index(opts, callback)` Returns all games
27+
* `games(opts)` Returns all games
2928
```javascript
30-
igdb.games.index({ limit: 5, offset: 15 }, output)
29+
igdb.games({ limit: 5, offset: 15, fields: "*" }).then(output)
3130
```
3231

33-
* `games.get(id, callback)` Returns game information
32+
* `games.get({ ids: [3766] })` Returns game information
3433
```javascript
35-
igdb.games.get(3766, output)
34+
igdb.games({ ids: [3766], fields: "*" }).then(output)
3635
```
3736

38-
* `games.meta(callback)` Returns total unique games count. (IE Mass effect (xbox/ps/pc) only counts as 1)
39-
```javascript
40-
igdb.games.meta(output)
41-
```
42-
43-
* `igdb.games.search(searchParamsObject, output)`
37+
* `igdb.games({ search: "zelda", fields: "*" })`
4438

45-
Read details on the search parameters here: https://www.igdb.com/api/v1/documentation/games
39+
Read details on the search parameters here: https://market.mashape.com/igdbcom/internet-game-database/overview#wiki-filters
4640

4741
```javascript
48-
igdb.games.search({
49-
q: 'penguin',
50-
{
42+
igdb.games({
43+
search: 'penguin',
5144
limit: 3,
5245
offset: 4,
5346
filters: {
54-
platforms_eq: 3
47+
"platforms-eq": 3
5548
},
56-
},
57-
output
58-
})
49+
fields: "*"
50+
}).then(output)
5951
```
6052

6153
**Companies**
62-
https://www.igdb.com/api/v1/documentation/companies
6354

64-
* `companies.index(opts, callback)` Returns all companies
55+
* `companies.index(opts).then(output)` Returns all companies
6556
```javascript
66-
igdb.companies.index({ limit: 5, offset: 15 }, output)
57+
igdb.companies({ limit: 5, offset: 15, fields: "*" }).then(output)
6758
```
6859

6960
* `companies.get(id, callback)` Returns game information
7061
```javascript
71-
igdb.companies.get('nintendo', output)
72-
```
73-
74-
* `companies.meta(callback)` Returns total companies count.
75-
```javascript
76-
igdb.companies.meta(output)
77-
```
78-
79-
* `igdb.companies.games(opts, companyId, output)` Returns related games
80-
81-
```javascript
82-
igdb.companies.games({
83-
limit: 3,
84-
offset: 4
85-
}, 'nintendo', output)
62+
igdb.companies({ search: 'nintendo', fields: "*" }).then(output)
8663
```
8764

88-
**People**
89-
https://www.igdb.com/api/v1/documentation/people
65+
Many more data entities are documented here: https://market.mashape.com/igdbcom/internet-game-database
9066

91-
* `people.index(opts, callback)` Returns all people
92-
```javascript
93-
igdb.people.index({ limit: 5, offset: 15 }, output)
94-
```
67+
**Images**
9568

96-
* `people.get(id, callback)` Returns game information
97-
```javascript
98-
igdb.people.get('satoru-iwata', output)
99-
```
69+
A handy image function is included to convert objects with cloudinary_ids to full urls.
10070

101-
* `people.meta(callback)` Returns total people count.
102-
```javascript
103-
igdb.people.meta(output)
10471
```
105-
106-
* `igdb.people.games(opts, personId, output)` Returns related games
107-
108-
```javascript
109-
igdb.people.games({
110-
limit: 3,
111-
offset: 4
112-
}, 'satoru-iwata', output)
72+
igdb.image(cover, "thumb", "jpg")
11373
```
11474

115-
* `igdb.people.titles(personId, output)` Returns job titles for this person
75+
More options are documented here: https://market.mashape.com/igdbcom/internet-game-database/overview#wiki-images
11676

117-
```javascript
118-
igdb.people.titles('satoru-iwata', output)
119-
```
77+
Also check out the sandbox.js file for more examples.

config.json.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"apikey": "API_KEY",
3-
"endpoint": "https://www.igdb.com/api/v1/"
3+
"endpoint": "https://igdbcom-internet-game-database-v1.p.mashape.com/"
44
}

index.coffee

-51
This file was deleted.

index.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
var request = require('request'),
2+
config = require('./config');
3+
4+
var perform_request = function(url, resolve, reject){
5+
6+
var options = {
7+
url: url,
8+
headers: {
9+
'Accept': 'application/json',
10+
'X-Mashape-Key': config.apikey
11+
}
12+
};
13+
14+
return request(options, function(error, response, body) {
15+
16+
if(!error){
17+
error = (response.statusCode != 200 ? response.statusCode + " - " + options.url : null);
18+
}
19+
20+
if (error) {
21+
if(reject){
22+
return reject(error);
23+
}else{
24+
throw error;
25+
}
26+
}
27+
28+
if (response.statusCode == 200 && resolve) {
29+
return resolve({
30+
url: options.url,
31+
body: JSON.parse(body),
32+
head: response.headers,
33+
scroll_url: response.headers['X-Next-Page'],
34+
scroll_count: response.headers['X-Count']
35+
});
36+
}
37+
});
38+
}
39+
40+
var get = function(url, fields, opts, resolve, reject) {
41+
url = config.endpoint + url + "/";
42+
if (opts) {
43+
var optUrl = [], filter, param;
44+
for (param in opts) {
45+
var paramValue = opts[param];
46+
if (param == "filters") {
47+
for (filter in paramValue) {
48+
filter_split = filter.split('-')
49+
optUrl.push("filter[" + filter_split.join("][") + "]=" + paramValue[filter]);
50+
}
51+
} else if(param == "ids") {
52+
url += paramValue.join(',')
53+
} else {
54+
optUrl.push(param + "=" + paramValue);
55+
}
56+
}
57+
58+
if(fields){
59+
optUrl.push("fields=" + fields.join(','));
60+
}
61+
62+
url += "?" + optUrl.join('&');
63+
}
64+
65+
return perform_request(url, resolve, reject);
66+
};
67+
68+
var endpoint = function(e){
69+
return function(opts, fields) {
70+
return new Promise(function(resolve, reject){
71+
get(e, fields, opts, resolve, reject);
72+
});
73+
}
74+
}
75+
76+
var endpoints = ["games", "companies", "people", "genres", "keywords", "platforms", "player_perspectives", "pulses", "themes", "franchises", "collections"],
77+
endpoints_obj = {
78+
image: function(image_object, size, filetype){
79+
if(image_object){
80+
return "https://res.cloudinary.com/igdb/image/upload/t_" + (size || "thumb") + "/" + image_object.cloudinary_id + "." + (filetype || "jpg");
81+
}
82+
},
83+
scroll: function(url){
84+
return new Promise(function(resolve, reject){
85+
return perform_request(url, resolve, reject);
86+
});
87+
}
88+
};
89+
90+
for(i = 0; i < endpoints.length; i++){
91+
endpoints_obj[endpoints[i]] = endpoint(endpoints[i]);
92+
}
93+
94+
module.exports = endpoints_obj

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "igdb-api-node",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Nodejs API Wrapper for IGDB.com",
5-
"main": "index.coffee",
5+
"main": "index.js",
66
"scripts": {
7-
"test": "coffee index.coffee"
7+
"test": "node index.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -19,11 +19,10 @@
1919
"author": "",
2020
"license": "MIT",
2121
"bugs": {
22-
"url": "https://github.com/igdb/igdb-api-node/issues"
22+
"url": "https://market.mashape.com/igdbcom/internet-game-database/support"
2323
},
24-
"homepage": "https://github.com/igdb/igdb-api-node",
24+
"homepage": "https://market.mashape.com/igdbcom/internet-game-database/overview",
2525
"dependencies": {
26-
"coffee-script": "^1.9.3",
2726
"request": "^2.60.0"
2827
}
2928
}

sandbox.js.example

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
igdb = require('./index');
2+
3+
function log(res){
4+
for(i in res.body){
5+
game = res.body[i];
6+
game.cover = igdb.image(game.cover, "cover_small");
7+
}
8+
console.log(res.url, JSON.stringify(res.body, null, " "));
9+
}
10+
11+
igdb.platforms({
12+
search: "Atari",
13+
limit: 2
14+
}, ["name"]).then(log);
15+
16+
igdb.games({
17+
search: "zelda",
18+
limit: 5,
19+
offset: 0,
20+
order: "release_dates.date:desc",
21+
filters: {
22+
"release_dates.date-gt": "2010-12-31",
23+
"release_dates.date-lt": "2012-01-01"
24+
}
25+
}, ["name","release_dates.date","rating","hypes","cover"]).then(log);
26+
27+
igdb.games({
28+
ids: [18472, 18228],
29+
}, ["name", "cover"]).then(log);
30+
31+
igdb.companies({
32+
search: "rockstar",
33+
limit: 5,
34+
offset: 0,
35+
order: "name:desc",
36+
field: "name"
37+
}, ["name","logo"]).then(log);

0 commit comments

Comments
 (0)