Completed
Push — master ( f63129...3a8a63 )
by Sergey
03:49
created

Conversations::sendMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
namespace seregazhuk\PinterestBot\Api\Providers;
3
4
use seregazhuk\PinterestBot\Api\Request;
5
use seregazhuk\PinterestBot\Helpers\UrlHelper;
6
7
class Conversations extends Provider
8
{
9
    protected $loginRequired = ['last', 'sendMessage'];
10
11
    /**
12
     * Send message to a user
13
     *
14
     * @param $userId
15
     * @param $text
16
     *
17
     * @return bool
18
     */
19
    public function sendMessage($userId, $text)
20
    {
21
        $requestOptions = array(
22
            "user_ids" => array($userId),
23
            "emails"   => array(),
24
            "text"     => $text,
25
        );
26
27
        return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_SEND_MESSAGE);
28
    }
29
30
    /**
31
     * Get last user conversations
32
     *
33
     * @return array|bool
34
     */
35
    public function last()
36
    {
37
        $this->request->checkLoggedIn();
38
        $data = Request::createRequestData();
39
        $query = UrlHelper::buildRequestString($data);
40
        $response = $this->request->exec(UrlHelper::RESOURCE_GET_LAST_CONVERSATIONS.'?'.$query);
41
42
        return $this->response->getData($response);
43
    }
44
}
45