Completed
Push — master ( 45a0cb...675a3f )
by dotzero
02:05
created

Widgets::apiList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace AmoCRM\Models;
4
5
/**
6
 * Class Widgets
7
 *
8
 * Класс модель для работы с Виджетами
9
 *
10
 * @package AmoCRM\Models
11
 * @version 0.3.5
12
 * @author dotzero <[email protected]>
13
 * @link http://www.dotzero.ru/
14
 * @link https://github.com/dotzero/amocrm-php
15
 *
16
 * For the full copyright and license information, please view the LICENSE
17
 * file that was distributed with this source code.
18
 */
19
class Widgets extends Base
20
{
21
    /**
22
     * Список виджетов
23
     *
24
     * Метод для получения списка доступных для установки виджетов.
25
     *
26
     * @link https://developers.amocrm.ru/rest_api/widgets/list.php
27
     * @param array $parameters Массив параметров к amoCRM API
28
     * @return array Ответ amoCRM API
29
     */
30 1
    public function apiList($parameters = [])
31
    {
32 1
        $response = $this->getRequest('/private/api/v2/json/widgets/list', $parameters);
33
34 1
        return isset($response['widgets']) ? $response['widgets'] : [];
35
    }
36
37
    /**
38
     * Включение виджетов
39
     *
40
     * Метод позволяет включать виджеты по одному или пакетно,
41
     * а также обновлять данные включённых и выключенных виджетов.
42
     *
43
     * @link https://developers.amocrm.ru/rest_api/widgets/set.php
44
     * @param array $parameters Массив параметров к amoCRM API
45
     * @return array Ответ amoCRM API
46
     * @throws \AmoCRM\Exception
47
     */
48 1
    public function apiInstall($parameters)
49
    {
50
        $parameters = [
51
            'widgets' => [
52 1
                'install' => $parameters,
53 1
            ],
54 1
        ];
55
56 1
        $response = $this->postRequest('/private/api/v2/json/widgets/set', $parameters);
57
58 1
        return isset($response['widgets']) ? $response['widgets'] : [];
59
    }
60
61
    /**
62
     * Выключение виджетов
63
     *
64
     * Метод позволяет выключать виджеты по одному или пакетно,
65
     * а также обновлять данные включённых и выключенных виджетов.
66
     *
67
     * @link https://developers.amocrm.ru/rest_api/widgets/set.php
68
     * @param array $parameters Массив параметров к amoCRM API
69
     * @return array Ответ amoCRM API
70
     * @throws \AmoCRM\Exception
71
     */
72 1
    public function apiUninstall($parameters)
73
    {
74
        $parameters = [
75
            'widgets' => [
76 1
                'uninstall' => $parameters,
77 1
            ],
78 1
        ];
79
80 1
        $response = $this->postRequest('/private/api/v2/json/widgets/set', $parameters);
81
82 1
        return isset($response['widgets']) ? $response['widgets'] : [];
83
    }
84
}