Completed
Push — master ( 314dd1...511805 )
by Sergey
05:05
created

Conversations   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B sendMessage() 0 30 4
1
<?php
2
namespace seregazhuk\PinterestBot\Providers;
3
4
use seregazhuk\PinterestBot\Helpers\UrlHelper;
5
6
class Conversations extends Provider
7
{
8
    /**
9
     * Send message to a user
10
     *
11
     * @param $userId
12
     * @param $text
13
     *
14
     * @return bool
15
     */
16
    public function sendMessage($userId, $text)
17
    {
18
        $this->request->checkLoggedIn();
19
20
        $data = array(
21
            "options" => array(
22
                "user_ids" => array(
23
                    $userId,
24
                ),
25
                "emails" => array(),
26
                "text" => $text,
27
            ),
28
            "context" => new \stdClass(),
29
        );
30
31
        $dataJson = json_encode($data);
32
33
        $post = array(
34
            'data' => $dataJson,
35
        );
36
37
        $postString = UrlHelper::buildRequestString($post);
38
        $res        = $this->request->exec(UrlHelper::RESOURCE_SEND_MESSAGE, $postString);
39
40
        if ($res === null || !isset($res['resource_response']) || $res['resource_response']['error'] !== null) {
41
            return false;
42
        }
43
44
        return true;
45
    }
46
}
47