File tree Expand file tree Collapse file tree 14 files changed +373
-0
lines changed Expand file tree Collapse file tree 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
112112 return $ this ->client ->getFromContainer (CommandBusInterface::class);
113113 }
114114
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+
115124 public function user (string $ user ): PromiseInterface
116125 {
117126 return $ this ->client ->handle (new RequestCommand (
Original file line number Diff line number Diff line change 22
33namespace ApiClients \Client \Twitter ;
44
5+ use ApiClients \Client \Twitter \Resource \ProfileInterface ;
56use ApiClients \Client \Twitter \Resource \TweetInterface ;
67use ApiClients \Client \Twitter \Resource \UserInterface ;
78use React \EventLoop \Factory as LoopFactory ;
@@ -68,6 +69,14 @@ public function tweet(string $tweet): TweetInterface
6869 );
6970 }
7071
72+ public function profile (): ProfileInterface
73+ {
74+ return await (
75+ $ this ->client ->profile (),
76+ $ this ->loop
77+ );
78+ }
79+
7180 public function user (string $ tweet ): UserInterface
7281 {
7382 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+ }
You can’t perform that action at this time.
0 commit comments