File tree Expand file tree Collapse file tree 6 files changed +57
-1
lines changed Expand file tree Collapse file tree 6 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 22
22
))->withAccessToken (
23
23
$ config ['access_token ' ]['token ' ],
24
24
$ config ['access_token ' ]['secret ' ]
25
- )->profile ()->done (function (ProfileInterface $ profile ) use ($ argv ) {
25
+ )->profile ()->then (function (ProfileInterface $ profile ) use ($ argv ) {
26
+ echo 'Fetched profile ' , PHP_EOL ;
26
27
resource_pretty_print ($ profile );
27
28
$ emojis = [
28
29
'😈 ' ,
72
73
'🎵 ' ,
73
74
'🎶 ' ,
74
75
];
76
+ echo 'Setting new name ' , PHP_EOL ;
75
77
$ profile = $ profile ->withName (sprintf (
76
78
$ argv [1 ],
77
79
$ emojis [random_int (0 , count ($ emojis ) - 1 )]
78
80
));
79
81
resource_pretty_print ($ profile );
82
+
83
+ echo 'Updating profile ' , PHP_EOL ;
84
+ return $ profile ->putProfile ();
85
+ })->done (function (ProfileInterface $ profile ) {
86
+ echo 'Profile updated ' , PHP_EOL ;
87
+ resource_pretty_print ($ profile );
80
88
});
81
89
82
90
$ loop ->run ();
Original file line number Diff line number Diff line change 3
3
namespace ApiClients \Client \Twitter \Resource \Async ;
4
4
5
5
use ApiClients \Client \Twitter \Resource \Profile as BaseProfile ;
6
+ use ApiClients \Foundation \Hydrator \CommandBus \Command \HydrateCommand ;
7
+ use ApiClients \Foundation \Transport \CommandBus \Command \RequestCommand ;
8
+ use Psr \Http \Message \ResponseInterface ;
9
+ use React \Promise \PromiseInterface ;
10
+ use RingCentral \Psr7 \Request ;
11
+ use function React \Promise \resolve ;
6
12
7
13
class Profile extends BaseProfile
8
14
{
15
+ public function putProfile (): PromiseInterface
16
+ {
17
+ $ fields = [];
18
+ foreach ($ this ->changedFields as $ field ) {
19
+ $ fields [$ field ] = $ this ->$ field ;
20
+ }
21
+
22
+ $ uri = 'account/update_profile.json? ' . http_build_query ($ fields );
23
+
24
+ return $ this ->handleCommand (new RequestCommand (
25
+ new Request ('POST ' , $ uri )
26
+ ))->then (function (ResponseInterface $ response ) {
27
+ return resolve ($ this ->handleCommand (new HydrateCommand ('Profile ' , $ response ->getBody ()->getJson ())));
28
+ });
29
+ }
30
+
9
31
public function refresh () : Profile
10
32
{
11
33
throw new \Exception ('TODO: create refresh method! ' );
Original file line number Diff line number Diff line change @@ -71,4 +71,9 @@ public function withName(string $name): ProfileInterface
71
71
{
72
72
return clone $ this ;
73
73
}
74
+
75
+ public function putProfile ()
76
+ {
77
+
78
+ }
74
79
}
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ abstract class Profile extends AbstractResource implements ProfileInterface
45
45
*/
46
46
protected $ description ;
47
47
48
+ /**
49
+ * @var array
50
+ */
51
+ protected $ changedFields = [];
52
+
48
53
/**
49
54
* @return int
50
55
*/
@@ -109,6 +114,12 @@ public function withName(string $name): ProfileInterface
109
114
{
110
115
$ clone = clone $ this ;
111
116
$ clone ->name = $ name ;
117
+ $ clone ->changedFields ['name ' ] = 'name ' ;
112
118
return $ clone ;
113
119
}
120
+
121
+ public function putProfile ()
122
+ {
123
+
124
+ }
114
125
}
Original file line number Diff line number Diff line change @@ -48,4 +48,9 @@ public function description() : string;
48
48
* @return static
49
49
*/
50
50
public function withName (string $ name );
51
+
52
+ /**
53
+ * @return static
54
+ */
55
+ public function putProfile ();
51
56
}
Original file line number Diff line number Diff line change 8
8
9
9
class Profile extends BaseProfile
10
10
{
11
+ public function putProfile ()
12
+ {
13
+ // TODO: Implement putProfile() method.
14
+ }
15
+
11
16
public function refresh () : Profile
12
17
{
13
18
return $ this ->wait ($ this ->handleCommand (new BuildAsyncFromSyncCommand (self ::HYDRATE_CLASS , $ this ))->then (function (ProfileInterface $ profile ) {
You can’t perform that action at this time.
0 commit comments