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

Conversations   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendMessage() 0 18 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
    /**
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