1<?php
2/**
3 * This file is part of the Tmdb PHP API created by Michael Roterman.
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @package Tmdb
9 * @author Michael Roterman <michael@wtfz.net>
10 * @copyright (c) 2013, Michael Roterman
11 * @version 0.0.1
12 */
13namespace Tmdb\Api;
14
15/**
16 * Class Lists
17 * @package Tmdb\Api
18 * @see http://docs.themoviedb.apiary.io/#lists
19 */
20class Lists extends AbstractApi
21{
22    /**
23     * Get a list by id.
24     *
25     * @param  string $list_id
26     * @param  array  $parameters
27     * @param  array  $headers
28     * @return mixed
29     */
30    public function getList($list_id, array $parameters = [], array $headers = [])
31    {
32        return $this->get('list/' . $list_id, $parameters, $headers);
33    }
34
35    /**
36     * This method lets users create a new list. A valid session id is required.
37     *
38     * @param  string $name
39     * @param  string $description
40     * @param  array  $parameters
41     * @param  array  $headers
42     * @return mixed
43     */
44    public function createList($name, $description, array $parameters = [], array $headers = [])
45    {
46        return $this->postJson('list', ['name' => $name, 'description' => $description], $parameters, $headers);
47    }
48
49    /**
50     * Check to see if a movie ID is already added to a list.
51     *
52     * @param  string $id
53     * @param  int    $movieId
54     * @param  array  $parameters
55     * @param  array  $headers
56     * @return mixed
57     */
58    public function getItemStatus($id, $movieId, array $parameters = [], array $headers = [])
59    {
60        return $this->get(
61            'list/' . $id . '/item_status',
62            array_merge($parameters, ['movie_id' => $movieId]),
63            $headers
64        );
65    }
66
67    /**
68     * This method lets users add new movies to a list that they created. A valid session id is required.
69     *
70     * @param  string $id
71     * @param  string $mediaId
72     * @return mixed
73     */
74    public function addMediaToList($id, $mediaId)
75    {
76        return $this->postJson('list/' . $id . '/add_item', ['media_id' => $mediaId]);
77    }
78
79    /**
80     * This method lets users delete movies from a list that they created. A valid session id is required.
81     *
82     * @param  string $id
83     * @param  string $mediaId
84     * @return mixed
85     */
86    public function removeMediaFromList($id, $mediaId)
87    {
88        return $this->postJson('list/' . $id . '/remove_item', ['media_id' => $mediaId]);
89    }
90
91    /**
92     * This method lets users delete a list that they created. A valid session id is required.
93     *
94     * @param  string $id
95     * @return mixed
96     */
97    public function deleteList($id)
98    {
99        return $this->delete('list/' . $id);
100    }
101
102    /**
103     * Clear all of the items within a list.
104     *
105     * This is a irreversible action and should be treated with caution.
106     * A valid session id is required.
107     *
108     * @param  string  $id
109     * @param  boolean $confirm
110     * @return mixed
111     */
112    public function clearList($id, $confirm)
113    {
114        return $this->post(
115            'list/'.$id.'/clear',
116            null,
117            ['confirm' => (bool) $confirm === true ? 'true':'false']
118        );
119    }
120}
121