Completed
Push — master ( 3a5b78...5c6f77 )
by Mr
13s queued 11s
created

Leads::getDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 4
dl 0
loc 8
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 10
1
<?php
2
3
namespace UON\Endpoint;
4
5
use UON\Client;
6
7
/**
8
 * Collection of methods for work with leads created by users
9
 *
10
 * @package UON\Endpoint
11
 */
12
class Leads extends Client
13
{
14
    /**
15
     * Create new lead
16
     *
17
     * @link    https://api.u-on.ru/{key}/lead/create.{_format}
18
     * @param   array $parameters List of parameters [r_id_internal, r_dat, status_id, sources etc.]
19
     * @return  array|false
20
     */
21 1
    public function create(array $parameters)
22
    {
23 1
        $endpoint = '/lead/create';
24 1
        return $this->doRequest('post', $endpoint, $parameters);
25
    }
26
27
    /**
28
     * Get leads data by client ID
29
     *
30
     * @link    https://api.u-on.ru/{key}/lead-by-client/{id}.{_format}
31
     * @param   int $id   Unique lead ID
32
     * @param   int $page Number of page, 1 by default
33
     * @return  array|false
34
     */
35
    public function getByClient($id, $page = 1)
36
    {
37
        $endpoint = '/lead-by-client/' . $id . '/' . $page;
38
        return $this->doRequest('get', $endpoint);
39
    }
40
41
    /**
42
     * Get lead by ID
43
     *
44
     * @link    https://api.u-on.ru/{key}/lead/{id}.{_format}
45
     * @param   int $id Unique lead ID
46
     * @return  array|false
47
     */
48
    public function get($id)
49
    {
50
        $endpoint = '/lead/' . $id;
51
        return $this->doRequest('get', $endpoint);
52
    }
53
54
    /**
55
     * Get all leads into dates range (and by sources if needed)
56
     *
57
     * @link    https://api.u-on.ru/{key}/lead/{date_from}/{date_to}.{_format}
58
     * @param   string   $date_from Start of dates range
59
     * @param   string   $date_to   End of dates range
60
     * @param   int      $page      Number of page, 1 by default
61
     * @param   int|null $source_id Source ID, eg ID of SMS or JivoSite
62
     * @return  array|false
63
     */
64 1
    public function getDate($date_from, $date_to, $page = 1, $source_id = null)
65
    {
66 1
        $endpoint = '/leads/' . $date_from . '/' . $date_to;
67 1
        if (null !== $source_id) {
68
            $endpoint .= '/' . $source_id;
69
        }
70 1
        $endpoint .= '/' . $page;
71 1
        return $this->doRequest('get', $endpoint);
72
    }
73
74
    /**
75
     * Get lead data by filters
76
     *
77
     * @link    https://api.u-on.ru/{key}/lead/search.{_format}
78
     * @since   1.8.2
79
     * @param   array $parameters List of parameters
80
     * @return  array|false
81
     */
82
    public function search(array $parameters = [])
83
    {
84
        $endpoint = '/lead/search';
85
        return $this->doRequest('post', $endpoint, $parameters);
86
    }
87
88
}
89