Completed
Pull Request — master (#19)
by Sergey
03:32
created

Conversations::sendMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4286
cc 1
eloc 11
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
    /**
10
     * Send message to a user
11
     *
12
     * @param $userId
13
     * @param $text
14
     *
15
     * @return bool
16
     */
17
    public function sendMessage($userId, $text)
18
    {
19
        $this->request->checkLoggedIn();
20
        $data = array(
21
            "options" => array(
22
                "user_ids" => array($userId),
23
                "emails"   => array(),
24
                "text"     => $text,
25
            ),
26
        );
27
28
        $request = Request::createRequestData($data);
29
30
        $postString = UrlHelper::buildRequestString($request);
31
        $response = $this->request->exec(UrlHelper::RESOURCE_SEND_MESSAGE, $postString);
32
33
        return $this->response->checkResponse($response);
34
    }
35
36
    /**
37
     * Get last user conversations
38
     * @return array|bool
39
     */
40
    public function last()
41
    {
42
        $this->request->checkLoggedIn();
43
        $data = Request::createRequestData();
44
        $query = UrlHelper::buildRequestString($data);
45
        $response = $this->request->exec(UrlHelper::RESOURCE_GET_LAST_CONVERSATIONS.'?'.$query);
46
47
        return $this->response->getData($response);
48
    }
49
}
50