Completed
Push — master ( 7d378c...9da044 )
by Sergey
03:36 queued 01:11
created

User::deactivate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use seregazhuk\PinterestBot\Api\Response;
6
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
7
use seregazhuk\PinterestBot\Api\Traits\UploadsImages;
8
9
class User extends Provider
10
{
11
    use UploadsImages;
12
13
    /**
14
     * @var array
15
     */
16
    protected $loginRequiredFor = [
17
        'invite',
18
        'profile',
19
        'username',
20
        'isBanned',
21
        'deactivate',
22
        'convertToBusiness',
23
    ];
24
25
    /**
26
     * Updates or returns user profile info. Gets associative array as a param. Available keys of array are:
27
     * 'last_name', 'first_name', 'username', 'about', 'location' and 'website_url'.
28
     * You can also change user avatar by passing 'profile_image'.
29
     *
30
     * @param array $userInfo If empty returns current user profile.
31
     *
32
     * @return bool|array
33
     */
34
    public function profile($userInfo = [])
35
    {
36
        if(empty($userInfo)) {
37
            return $this->execGetRequest([], UrlBuilder::RESOURCE_GET_USER_SETTINGS);
38
        }
39
40
        if (isset($userInfo['profile_image'])) {
41
            $userInfo['profile_image_url'] = $this->upload($userInfo['profile_image']);
42
        }
43
44
        return $this->execPostRequest($userInfo, UrlBuilder::RESOURCE_UPDATE_USER_SETTINGS);
45
    }
46
47
    /**
48
     * Checks if current user is banned
49
     *
50
     * @return bool
51
     */
52
    public function isBanned()
53
    {
54
        $profile = $this->profile();
55
56
       return isset($profile['is_write_banned']) ?
57
           (bool)$profile['is_write_banned'] :
58
           false;
59
    }
60
61
    /**
62
     * Returns current user username
63
     *
64
     * @return string
65
     */
66
    public function username()
67
    {
68
        $profile = $this->profile();
69
70
        return isset($profile['username']) ? $profile['username'] : '';
71
    }
72
73
    /**
74
     * Deactivates your account.
75
     *
76
     * @param string $reason
77
     * @param string $explanation
78
     * @return bool
79
     */
80
    public function deactivate($reason = 'other', $explanation = '')
81
    {
82
        $profile = $this->profile();
83
84
        if(!isset($profile['id'])) return false;
85
86
        $request = [
87
            'user_id'     => $profile['id'],
88
            'reason'      => $reason,
89
            'explanation' => $explanation,
90
        ];
91
92
        return $this->execPostRequest($request, UrlBuilder::RESOURCE_DEACTIVATE_ACCOUNT);
93
    }
94
95
    /**
96
     * Send invite to email
97
     * @param string $email
98
     * @return bool|Response
99
     */
100
    public function invite($email)
101
    {
102
        $data = [
103
            'email' => $email,
104
            'type'  => 'email',
105
        ];
106
107
        return $this->execPostRequest($data, UrlBuilder::RESOURCE_INVITE);
108
    }
109
}
110