-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
82 lines (65 loc) · 2.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const request = require('request');
const API_URL = 'https://api.football-data.org';
class FootballAPi {
constructor(key, plan) {
this.api = key,
this.plan = plan
}
fetch(path) {
return {
url: `${API_URL}${path}`,
headers: {
'X-Auth-Token': this.api,
'Access-Control-Allow-Methods': "GET",
'Access-Control-Allow-Origin': "*",
'Access-Control-Allow-Headers': "x-auth-token, x-response-control",
'Content-Length': 0
},
json: true
}
}
competitions(callback) {
return request(this.fetch(`/v2/competitions/?plan=${this.plan}`), callback)
}
competition(id, callback) {
return request(this.fetch(`/v2/competitions/${id}`), callback)
}
teams(id, season, callback) {
return request(this.fetch(`/v2/competitions/${id}/teams/?season=${season}`), callback)
}
standings(id, callback) {
return request(this.fetch(`/v2/competitions/${id}/standings`), callback)
}
matchCompetition(id, season, callback) {
return request(this.fetch(`/v2/competitions/${id}/matches/?season=${season}`), callback)
}
scorersCompetition(id, limit, callback) {
return request(this.fetch(`/v2/competitions/${id}/scorers/?limit=${limit}`), callback)
}
matchCompetitions(idCompetitions, callback) {
const competitionsIds = idCompetitions.join(',')
return request(this.fetch(`/v2/matches/?competitions=${competitionsIds}`), callback)
}
match(id, callback) {
return request(this.fetch(`/v2/matches/${id}`), callback)
}
matchTeam(id, from, to, callback) {
return request(this.fetch(`/v2/teams/${id}/matches/?dateFrom=${from}?dateTo=${to}`))
}
team(id, callback) {
return request(this.fetch(`/v2/teams/${id}`), callback)
}
areas(callback) {
return request(this.fetch(`/v2/areas/`), callback)
}
area(id, callback) {
return request(this.fetch(`/v2/areas/${id}`), callback)
}
player(id, callback) {
return request(this.fetch(`/v2/players/${id}`), callback)
}
playerMatches(id, from, to, idCompetitions, callback) {
return request(this.fetch(`/v2/players/${id}/matches/?dateFrom=${from}?dateTo=${to}?competitions=${idCompetitions.join(',')}`), callback)
}
}
module.exports = FootballAPi;