Total Complexity | 11 |
Complexity/F | 1 |
Lines of Code | 63 |
Function Count | 11 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 19.05% |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
1 | 4 | import App from "app"; |
|
2 | |||
3 | function Movies() { |
||
4 | this.serviceName = "Movies"; |
||
5 | this.basepath = "//api.themoviedb.org/3/"; |
||
6 | |||
7 | this.Request = App.ServicesContainer.get("AJAX"); |
||
8 | this.EM = App.EventManager; |
||
9 | } |
||
10 | |||
11 | /** |
||
12 | * @param {Object} complement |
||
13 | * @return {Object} |
||
14 | */ |
||
15 | 4 | Movies.prototype.makePayload = function (complement = {}) { |
|
16 | return Object.assign({ |
||
17 | api_key: App.config("tmdb_api_key"), |
||
18 | language: App.config("language") |
||
19 | }, complement); |
||
20 | } |
||
21 | |||
22 | 4 | Movies.prototype.search = function (term, page = 1) { |
|
23 | return new Promise((resolve, reject) => { |
||
24 | const payload = this.makePayload({ |
||
25 | query: term, |
||
26 | page: page |
||
27 | }); |
||
28 | |||
29 | this.Request.send('get', this.basepath + "search/multi", payload, (res) =>{ |
||
30 | resolve(res.body.results); |
||
31 | }, (err) => { |
||
32 | reject(err); |
||
33 | }); |
||
34 | }); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param {String} type (person|tv|movie) |
||
39 | * @param {Number} id |
||
40 | * @return {Promise} |
||
41 | */ |
||
42 | Movies.prototype.get = function (type, id) { |
||
43 | return new Promise((resolve, reject) => { |
||
44 | this.Request.send( |
||
45 | 'get', |
||
46 | `${this.basepath}${type}/${id}`, |
||
47 | this.makePayload(), |
||
48 | res => resolve(res.body), |
||
49 | err => reject(err) |
||
50 | ); |
||
51 | }); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param {String} path |
||
56 | * @param {String|Number} width |
||
57 | * @reutrn {String} |
||
58 | */ |
||
59 | 4 | Movies.prototype.getPosterURL = (path, width = 300) => { |
|
60 | return `http://image.tmdb.org/t/p/w${width}/${path}`; |
||
61 | } |
||
62 | |||
63 | export default Movies; |
||
64 |