|
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
|
|
|
'profile', |
|
18
|
|
|
'convertToBusiness', |
|
19
|
|
|
'changePassword', |
|
20
|
|
|
'isBanned', |
|
21
|
|
|
'deactivate', |
|
22
|
|
|
'username', |
|
23
|
|
|
'invite' |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
const REGISTRATION_COMPLETE_EXPERIENCE_ID = '11:10105'; |
|
27
|
|
|
const ACCOUNT_TYPE_OTHER = 'other'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Updates or returns user profile info. Gets associative array as a param. Available keys of array are: |
|
31
|
|
|
* 'last_name', 'first_name', 'username', 'about', 'location' and 'website_url'. |
|
32
|
|
|
* You can also change user avatar by passing 'profile_image'. |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $userInfo If empty returns current user profile. |
|
35
|
|
|
* |
|
36
|
|
|
* @return bool|array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function profile($userInfo = []) |
|
39
|
|
|
{ |
|
40
|
|
|
if(empty($userInfo)) { |
|
41
|
|
|
return $this->execGetRequest([], UrlBuilder::RESOURCE_GET_USER_SETTINGS); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (isset($userInfo['profile_image'])) { |
|
45
|
|
|
$userInfo['profile_image_url'] = $this->upload($userInfo['profile_image']); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->execPostRequest($userInfo, UrlBuilder::RESOURCE_UPDATE_USER_SETTINGS); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Convert your account to a business one. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $businessName |
|
55
|
|
|
* @param string $websiteUrl |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public function convertToBusiness($businessName, $websiteUrl = '') |
|
59
|
|
|
{ |
|
60
|
|
|
$data = [ |
|
61
|
|
|
'business_name' => $businessName, |
|
62
|
|
|
'website_url' => $websiteUrl, |
|
63
|
|
|
'account_type' => self::ACCOUNT_TYPE_OTHER, |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
return $this->execPostRequest($data, UrlBuilder::RESOURCE_CONVERT_TO_BUSINESS); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Checks if current user is banned |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function isBanned() |
|
75
|
|
|
{ |
|
76
|
|
|
$profile = $this->profile(); |
|
77
|
|
|
|
|
78
|
|
|
return isset($profile['is_write_banned']) ? |
|
79
|
|
|
(bool)$profile['is_write_banned'] : |
|
80
|
|
|
false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Returns current user username |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function username() |
|
89
|
|
|
{ |
|
90
|
|
|
$profile = $this->profile(); |
|
91
|
|
|
|
|
92
|
|
|
return isset($profile['username']) ? $profile['username'] : ''; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Deactivates your account. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $reason |
|
99
|
|
|
* @param string $explanation |
|
100
|
|
|
* @return bool |
|
101
|
|
|
*/ |
|
102
|
|
|
public function deactivate($reason = 'other', $explanation = '') |
|
103
|
|
|
{ |
|
104
|
|
|
$profile = $this->profile(); |
|
105
|
|
|
|
|
106
|
|
|
if(!isset($profile['id'])) return false; |
|
107
|
|
|
|
|
108
|
|
|
$request = [ |
|
109
|
|
|
'user_id' => $profile['id'], |
|
110
|
|
|
'reason' => $reason, |
|
111
|
|
|
'explanation' => $explanation, |
|
112
|
|
|
]; |
|
113
|
|
|
|
|
114
|
|
|
return $this->execPostRequest($request, UrlBuilder::RESOURCE_DEACTIVATE_ACCOUNT); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Send invite to email |
|
119
|
|
|
* @param string $email |
|
120
|
|
|
* @return bool|Response |
|
121
|
|
|
*/ |
|
122
|
|
|
public function invite($email) |
|
123
|
|
|
{ |
|
124
|
|
|
$data = [ |
|
125
|
|
|
'email' => $email, |
|
126
|
|
|
'type' => 'email', |
|
127
|
|
|
]; |
|
128
|
|
|
|
|
129
|
|
|
return $this->execPostRequest($data, UrlBuilder::RESOURCE_INVITE); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|