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

Conversations   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 2
c 4
b 0
f 1
lcom 1
cbo 5
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendMessage() 0 10 1
A last() 0 9 1
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