Passed
Push — master ( e13259...278427 )
by Luís
01:10
created

src/js/providers/Movies.js   A

Complexity

Total Complexity 11
Complexity/F 1

Size

Lines of Code 63
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 19.05%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 0
c 1
b 1
f 1
nc 1
dl 0
loc 63
ccs 4
cts 21
cp 0.1905
crap 0
rs 10
wmc 11
mnd 0
bc 9
fnc 11
bpm 0.8181
cpm 1
noi 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A Movies.makePayload 0 6 1
A Movies.get 0 11 1
A Movies.search 0 14 1
A Movies.js ➔ ??? 0 3 1
A Movies.js ➔ Movies 0 7 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