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

PinnerHelper::createUserDataRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace seregazhuk\PinterestBot\Helpers\Requests;
4
5
use seregazhuk\PinterestBot\Api\Request;
6
7
class PinnerHelper
8
{
9
    /**
10
     * Creates Pinterest API request to get user info according to
11
     * username, API url and bookmarks for pagination
12
     *
13
     * @param string $username
14
     * @param string $sourceUrl
15
     * @param array  $bookmarks
16
     * @return array
17
     */
18
    public static function createUserDataRequest($username, $sourceUrl, $bookmarks)
19
    {
20
        $dataJson = [
21
            "options" => [
22
                "username" => $username,
23
            ]
24
        ];
25
26
        return Request::createRequestData($dataJson, $sourceUrl, $bookmarks);
27
    }
28
29
    /**
30
     * Parses Pinterest API response with pinner name
31
     *
32
     * @param $res
33
     * @return null
34
     */
35
    public static function parseAccountNameResponse($res)
36
    {
37
        if (isset($res['resource_data'][1]['resource']['options']['username'])) {
38
            return $res['resource_data'][1]['resource']['options']['username'];
39
        }
40
41
        return null;
42
    }
43
44
    /**
45
     * Creates Pinterest API request to login
46
     *
47
     * @param string $username
48
     * @param string $password
49
     * @return array
50
     */
51
    public static function createLoginRequest($username, $password)
52
    {
53
        $dataJson = [
54
            "options" => [
55
                "username_or_email" => $username,
56
                "password"          => $password
57
            ],
58
        ];
59
        return Request::createRequestData($dataJson, "/login/");
60
    }
61
}
62