README.md 2.55 KB
Newer Older
Melroy van den Berg's avatar
Melroy van den Berg committed
1
2
# Metacritic API

Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
3
4
Using this Metacritic API, you are able to search games on [metacritic.com](http://www.metacritic.com).

Melroy van den Berg's avatar
Melroy van den Berg committed
5
It will give you back the metacritic score, users score, genres, rating, developers and much more (see below for an example).
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
6
7
8
The output is in [JSON format](http://us.php.net/manual/en/function.json-decode.php), so it is easy to parse in both PHP or other languages.

By default it uses the URL prefix: "http://www.metacritic.com/game/pc/". If you want to search for Playstation 3 games, just change it to:
Melroy van den Berg's avatar
Melroy van den Berg committed
9
"http://www.metacritic.com/game/playstation-3". See [metacritic.php](metacritic.php) file.
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
10

Melroy van den Berg's avatar
Melroy van den Berg committed
11
## Example
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
12
13
14
15

Searching on the PC game called "The Elder Scrolls V: Skyrim", 
will give the following JSON output:

Melroy van den Berg's avatar
Melroy van den Berg committed
16
```json
Melroy van den Berg's avatar
Melroy van den Berg committed
17
{
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
18
19
  "name": "The Elder Scrolls V: Skyrim",
  "metascritic_score": 94,
Melroy van den Berg's avatar
Melroy van den Berg committed
20
  "users_score": 8.2,
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
21
  "rating": "M",
Melroy van den Berg's avatar
Melroy van den Berg committed
22
23
24
25
26
27
28
29
30
  "genres": [
    "Role-Playing",
    "First-Person",
    "First-Person",
    "Western-Style"
  ],
  "developers": [
    "Bethesda Game Studios"
  ],
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
31
  "publishers": "Bethesda Softworks",
Melroy van den Berg's avatar
Melroy van den Berg committed
32
33
34
35
36
37
38
39
40
  "release_date": "Nov 10, 2011",
  "also_on": [
    "PlayStation 3",
    "Xbox 360"
  ],
  "also_on_url": [
    "/game/playstation-3/the-elder-scrolls-v-skyrim",
    "/game/xbox-360/the-elder-scrolls-v-skyrim"
  ],
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
41
42
  "thumbnail_url": "http://static.metacritic.com/images/products/games/7/5988ee04196a686e107b46174f94a3ae-98.jpg",
  "cheat_url": "http://www.gamefaqs.com/console/pc/code/615805.html"
Merrin Macleod's avatar
Merrin Macleod committed
43
44
}
```
Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
45

Melroy van den Berg's avatar
Melroy van den Berg committed
46
47
## On error

Melroy van den Berg's avatar
Melroy van den Berg committed
48
49
When for some reason the page couldn't be loaded / found or parsed, you will get the following JSON response:

Melroy van den Berg's avatar
Melroy van den Berg committed
50
```json
Melroy van den Berg's avatar
Melroy van den Berg committed
51
{"error":"Page could not be loaded!"}
Melroy van den Berg's avatar
Melroy van den Berg committed
52
53
```

Melroy van den Berg's avatar
Melroy van den Berg committed
54
55
Or when metacritic.php is directly called, without input you will get: `{"error": "Game title is empty"}`

Melroy van den Berg's avatar
Melroy van den Berg committed
56
57
## Code example

Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
58
59
Please, see [example.php](example.php)

60
61
62
63
64
65
66
Another way to access the API is to directly call [metacritic.php](metacritic.php) via the website URL:
```sh
metacritic.php?game_title=Halo%202
```

Be-aware that the game title needs to be [URL encoded](https://www.w3schools.com/tags/ref_urlencode.asp) to work.

Melroy van den Berg's avatar
Add API    
Melroy van den Berg committed
67
Have fun!
Administrator's avatar
Administrator committed
68

Melroy van den Berg's avatar
Melroy van den Berg committed
69
70
71
72
73
74
75
76
77
78
## CI/CD

Code quality is checked in GitLab CI/CD, to avoid regression.

Currently in the pipeline:

* [Psalm](https://psalm.dev/) - Static analysis tool for PHP
* [Phpcs](https://github.com/squizlabs/PHP_CodeSniffer) - PHP coding style standard (`phpcbf` command for auto-fix)
* [Phpmetrics](https://phpmetrics.github.io/PhpMetrics/) - PHP metrics for complexity, object oriented, maintainability and more.
  * [Latest Metrics Report](https://gitlab.melroy.org/melroy/metacritic_api/-/jobs/artifacts/master/file/report/index.html?job=phpmetrics)