File tree 14 files changed +373
-0
lines changed
14 files changed +373
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use ApiClients \Client \Twitter \AsyncClient ;
4
+ use ApiClients \Client \Twitter \Resource \ProfileInterface ;
5
+ use React \EventLoop \Factory ;
6
+ use function ApiClients \Foundation \resource_pretty_print ;
7
+
8
+ require dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'vendor/autoload.php ' ;
9
+ $ config = require 'resolve_config.php ' ;
10
+
11
+ $ loop = Factory::create ();
12
+ $ client = (new AsyncClient (
13
+ $ config ['consumer ' ]['key ' ],
14
+ $ config ['consumer ' ]['secret ' ],
15
+ $ loop
16
+ ))->withAccessToken (
17
+ $ config ['access_token ' ]['token ' ],
18
+ $ config ['access_token ' ]['secret ' ]
19
+ )->profile ()->done (function (ProfileInterface $ profile ) {
20
+ resource_pretty_print ($ profile );
21
+ });
22
+
23
+ $ loop ->run ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use ApiClients \Client \Twitter \Client ;
4
+ use function ApiClients \Foundation \resource_pretty_print ;
5
+
6
+ require dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'vendor/autoload.php ' ;
7
+ $ config = require 'resolve_config.php ' ;
8
+
9
+ $ client = (new Client (
10
+ $ config ['consumer ' ]['key ' ],
11
+ $ config ['consumer ' ]['secret ' ]
12
+ ))->withAccessToken (
13
+ $ config ['access_token ' ]['token ' ],
14
+ $ config ['access_token ' ]['secret ' ]
15
+ );
16
+
17
+ resource_pretty_print ($ client ->profile ());
Original file line number Diff line number Diff line change @@ -112,6 +112,15 @@ public function getCommandBus(): CommandBusInterface
112
112
return $ this ->client ->getFromContainer (CommandBusInterface::class);
113
113
}
114
114
115
+ public function profile (): PromiseInterface
116
+ {
117
+ return $ this ->client ->handle (new RequestCommand (
118
+ new Request ('GET ' , 'account/verify_credentials.json ' )
119
+ ))->then (function (ResponseInterface $ response ) {
120
+ return resolve ($ this ->client ->handle (new HydrateCommand ('Profile ' , $ response ->getBody ()->getJson ())));
121
+ });
122
+ }
123
+
115
124
public function user (string $ user ): PromiseInterface
116
125
{
117
126
return $ this ->client ->handle (new RequestCommand (
Original file line number Diff line number Diff line change 2
2
3
3
namespace ApiClients \Client \Twitter ;
4
4
5
+ use ApiClients \Client \Twitter \Resource \ProfileInterface ;
5
6
use ApiClients \Client \Twitter \Resource \TweetInterface ;
6
7
use ApiClients \Client \Twitter \Resource \UserInterface ;
7
8
use React \EventLoop \Factory as LoopFactory ;
@@ -68,6 +69,14 @@ public function tweet(string $tweet): TweetInterface
68
69
);
69
70
}
70
71
72
+ public function profile (): ProfileInterface
73
+ {
74
+ return await (
75
+ $ this ->client ->profile (),
76
+ $ this ->loop
77
+ );
78
+ }
79
+
71
80
public function user (string $ tweet ): UserInterface
72
81
{
73
82
return await (
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource \Async ;
4
+
5
+ use ApiClients \Client \Twitter \Resource \EmptyProfile as BaseEmptyProfile ;
6
+
7
+ class EmptyProfile extends BaseEmptyProfile
8
+ {
9
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource \Async ;
4
+
5
+ use ApiClients \Client \Twitter \Resource \Profile as BaseProfile ;
6
+
7
+ class Profile extends BaseProfile
8
+ {
9
+ public function refresh () : Profile
10
+ {
11
+ throw new \Exception ('TODO: create refresh method! ' );
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource ;
4
+
5
+ use ApiClients \Foundation \Resource \EmptyResourceInterface ;
6
+
7
+ abstract class EmptyProfile implements ProfileInterface, EmptyResourceInterface
8
+ {
9
+ /**
10
+ * @return int
11
+ */
12
+ public function id () : int
13
+ {
14
+ return null ;
15
+ }
16
+
17
+ /**
18
+ * @return string
19
+ */
20
+ public function idStr () : string
21
+ {
22
+ return null ;
23
+ }
24
+
25
+ /**
26
+ * @return string
27
+ */
28
+ public function name () : string
29
+ {
30
+ return null ;
31
+ }
32
+
33
+ /**
34
+ * @return string
35
+ */
36
+ public function screenName () : string
37
+ {
38
+ return null ;
39
+ }
40
+
41
+ /**
42
+ * @return string
43
+ */
44
+ public function location () : string
45
+ {
46
+ return null ;
47
+ }
48
+
49
+ /**
50
+ * @return string
51
+ */
52
+ public function profileLocation () : string
53
+ {
54
+ return null ;
55
+ }
56
+
57
+ /**
58
+ * @return string
59
+ */
60
+ public function description () : string
61
+ {
62
+ return null ;
63
+ }
64
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource ;
4
+
5
+ use ApiClients \Foundation \Hydrator \Annotations \EmptyResource ;
6
+ use ApiClients \Foundation \Resource \AbstractResource ;
7
+
8
+ /**
9
+ * @EmptyResource("EmptyProfile")
10
+ */
11
+ abstract class Profile extends AbstractResource implements ProfileInterface
12
+ {
13
+ /**
14
+ * @var int
15
+ */
16
+ protected $ id ;
17
+
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $ id_str ;
22
+
23
+ /**
24
+ * @var string
25
+ */
26
+ protected $ name ;
27
+
28
+ /**
29
+ * @var string
30
+ */
31
+ protected $ screen_name ;
32
+
33
+ /**
34
+ * @var string
35
+ */
36
+ protected $ location ;
37
+
38
+ /**
39
+ * @var string
40
+ */
41
+ protected $ profile_location ;
42
+
43
+ /**
44
+ * @var string
45
+ */
46
+ protected $ description ;
47
+
48
+ /**
49
+ * @return int
50
+ */
51
+ public function id () : int
52
+ {
53
+ return $ this ->id ;
54
+ }
55
+
56
+ /**
57
+ * @return string
58
+ */
59
+ public function idStr () : string
60
+ {
61
+ return $ this ->id_str ;
62
+ }
63
+
64
+ /**
65
+ * @return string
66
+ */
67
+ public function name () : string
68
+ {
69
+ return $ this ->name ;
70
+ }
71
+
72
+ /**
73
+ * @return string
74
+ */
75
+ public function screenName () : string
76
+ {
77
+ return $ this ->screen_name ;
78
+ }
79
+
80
+ /**
81
+ * @return string
82
+ */
83
+ public function location () : string
84
+ {
85
+ return $ this ->location ;
86
+ }
87
+
88
+ /**
89
+ * @return string
90
+ */
91
+ public function profileLocation () : string
92
+ {
93
+ return $ this ->profile_location ;
94
+ }
95
+
96
+ /**
97
+ * @return string
98
+ */
99
+ public function description () : string
100
+ {
101
+ return $ this ->description ;
102
+ }
103
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource ;
4
+
5
+ use ApiClients \Foundation \Resource \ResourceInterface ;
6
+
7
+ interface ProfileInterface extends ResourceInterface
8
+ {
9
+ const HYDRATE_CLASS = 'Profile ' ;
10
+
11
+ /**
12
+ * @return int
13
+ */
14
+ public function id () : int ;
15
+
16
+ /**
17
+ * @return string
18
+ */
19
+ public function idStr () : string ;
20
+
21
+ /**
22
+ * @return string
23
+ */
24
+ public function name () : string ;
25
+
26
+ /**
27
+ * @return string
28
+ */
29
+ public function screenName () : string ;
30
+
31
+ /**
32
+ * @return string
33
+ */
34
+ public function location () : string ;
35
+
36
+ /**
37
+ * @return string
38
+ */
39
+ public function profileLocation () : string ;
40
+
41
+ /**
42
+ * @return string
43
+ */
44
+ public function description () : string ;
45
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource \Sync ;
4
+
5
+ use ApiClients \Client \Twitter \Resource \EmptyProfile as BaseEmptyProfile ;
6
+
7
+ class EmptyProfile extends BaseEmptyProfile
8
+ {
9
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Client \Twitter \Resource \Sync ;
4
+
5
+ use ApiClients \Foundation \Hydrator \CommandBus \Command \BuildAsyncFromSyncCommand ;
6
+ use ApiClients \Client \Twitter \Resource \Profile as BaseProfile ;
7
+ use ApiClients \Client \Twitter \Resource \ProfileInterface ;
8
+
9
+ class Profile extends BaseProfile
10
+ {
11
+ public function refresh () : Profile
12
+ {
13
+ return $ this ->wait ($ this ->handleCommand (new BuildAsyncFromSyncCommand (self ::HYDRATE_CLASS , $ this ))->then (function (ProfileInterface $ profile ) {
14
+ return $ profile ->refresh ();
15
+ }));
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Tests \Client \Twitter \Resource \Async ;
4
+
5
+ use ApiClients \Tools \ResourceTestUtilities \AbstractResourceTest ;
6
+ use ApiClients \Client \Twitter \ApiSettings ;
7
+ use ApiClients \Client \Twitter \Resource \Profile ;
8
+
9
+ class ProfileTest extends AbstractResourceTest
10
+ {
11
+ public function getSyncAsync () : string
12
+ {
13
+ return 'Async ' ;
14
+ }
15
+ public function getClass () : string
16
+ {
17
+ return Profile::class;
18
+ }
19
+ public function getNamespace () : string
20
+ {
21
+ return Apisettings::NAMESPACE ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace ApiClients \Tests \Client \Twitter \Resource \Sync ;
4
+
5
+ use ApiClients \Tools \ResourceTestUtilities \AbstractResourceTest ;
6
+ use ApiClients \Client \Twitter \ApiSettings ;
7
+ use ApiClients \Client \Twitter \Resource \Profile ;
8
+
9
+ class ProfileTest extends AbstractResourceTest
10
+ {
11
+ public function getSyncAsync () : string
12
+ {
13
+ return 'Sync ' ;
14
+ }
15
+ public function getClass () : string
16
+ {
17
+ return Profile::class;
18
+ }
19
+ public function getNamespace () : string
20
+ {
21
+ return Apisettings::NAMESPACE ;
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments