bin/movies.js   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 1.4

Size

Lines of Code 84
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 84
ccs 25
cts 25
cp 1
crap 0
rs 10
wmc 14
mnd 1
bc 14
fnc 10
bpm 1.4
cpm 1.4
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A __.requestAPI 0 7 1
A movies.js ➔ ??? 0 66 1
1
/**
2
 * Movies
3
 */
4
'use strict'
5
6 1
const request = require('request-promise')
7
8 1
const __ = {
9
  params: {},
10
11
  requestAPI: function (url) {
12 6
    return request({
13
      uri: url,
14
      qs: this.params,
15
      json: true
16
    })
17
  }
18
}
19
20 1
const Movies = () => {
21 1
  const proto = {
22
    endpoint: {
23
      list: 'https://yts.ag/api/v2/list_movies.json',
24
      details: 'https://yts.ag/api/v2/movie_details.json'
25
    },
26
27
    setEndpoint: function (endpoint) {
28 3
      if (typeof endpoint !== 'object') {
29 1
        throw new Error('endpoint must be an object')
30
      }
31
32 2
      for (let i in endpoint) {
33 2
        this.endpoint[i] = endpoint[i]
34
      }
35
36 2
      return this
37
    },
38
39
    setParams: function (params) {
40 6
      if (typeof params !== 'object') {
41 1
        throw new Error('params must be an object')
42
      }
43
44 5
      __.params = {}
45
46 5
      for (let i in params) {
47 7
        __.params[i] = params[i]
48
      }
49
50 5
      return this
51
    },
52
53
    get: function () {
54 5
      return __.requestAPI(this.endpoint.list)
55
    },
56
57
    findByGenre: function (genre) {
58 1
      return this.setParams({genres: genre}).get()
59
    },
60
61
    findByQuality: function (quality) {
62 1
      return this.setParams({quality: quality}).get()
63
    },
64
65
    findByRating: function (rating) {
66 1
      return this.setParams({minimum_rating: rating}).get()
67
    },
68
69
    search: function (term) {
70 1
      return this.setParams({query_term: term}).get()
71
    },
72
73
    findByID: function (id) {
74 1
      this.setParams({
75
        movie_id: id,
76
        with_images: true,
77
        with_cast: true
78
      })
79
80 1
      return __.requestAPI(this.endpoint.details)
81
    }
82
  }
83
84 1
  return Object.create(proto)
85
}
86
87
module.exports = Movies()
88