File tree Expand file tree Collapse file tree 4 files changed +61
-9
lines changed
Expand file tree Collapse file tree 4 files changed +61
-9
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ class ApiRequest implements IApiRequest
2929 */
3030 private $ _requestDetail ;
3131
32+ /**
33+ * @var IApiEndpoint
34+ */
35+ protected $ _endpoint ;
36+
3237 /**
3338 * @param IApiRequestDetail $requestDetail
3439 *
@@ -59,9 +64,31 @@ public function getRawResult()
5964 {
6065 if ($ this ->hasConnection ())
6166 {
62- $ this ->setRawResult (
63- $ this ->_getConnection ()->load ($ this )->getRawResult ()
64- );
67+ if ($ this ->_requestDetail ->requiresAuth ())
68+ {
69+ $ this ->_getConnection ()->setToken ($ this ->_endpoint ->getToken ());
70+ try
71+ {
72+ $ result = $ this ->_getConnection ()->load ($ this );
73+ }
74+ catch (\Exception $ e )
75+ {
76+ if ($ e ->getCode () == 403 && stristr ($ e ->getMessage (), 'token ' ))
77+ {
78+ $ result = $ this ->_getConnection ()->load ($ this );
79+ }
80+ else
81+ {
82+ throw $ e ;
83+ }
84+ }
85+ }
86+ else
87+ {
88+ $ result = $ this ->_getConnection ()->load ($ this );
89+ }
90+
91+ $ this ->setRawResult ($ result ->getRawResult ());
6592 }
6693 else
6794 {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ class ApiRequestDetail implements IApiRequestDetail
1111 protected $ _body = '' ;
1212 protected $ _method = 'GET ' ;
1313 protected $ _isAsync = false ;
14+ protected $ _requireAuth = true ;
1415
1516 /**
1617 * @inheritDoc
@@ -230,4 +231,23 @@ public function setAsync($isAsync)
230231 return $ this ;
231232 }
232233
234+ /**
235+ * @param boolean $requireAuth
236+ *
237+ * @return ApiRequestDetail
238+ */
239+ public function setRequireAuth ($ requireAuth )
240+ {
241+ $ this ->_requireAuth = $ requireAuth ;
242+ return $ this ;
243+ }
244+
245+ /**
246+ * @inheritDoc
247+ */
248+ public function requiresAuth ()
249+ {
250+ return (bool )$ this ->_requireAuth ;
251+ }
252+
233253}
Original file line number Diff line number Diff line change 55
66interface IApiEndpoint extends IApiConnectionAware
77{
8- public function setApiDefinition (IApiDefinition $ definition );
9-
108 /**
11- * @return IApiDefinition
9+ * @param IApiDefinition $definition
10+ *
11+ * @return IApiEndpoint|static
1212 */
13- public function getApiDefinition ( );
13+ public function setApiDefinition ( IApiDefinition $ definition );
1414
1515 /**
16- * @return bool
16+ * @return OAuth\Tokens\IToken|null
1717 */
18- public function hasConnection ();
18+ public function getToken ();
1919}
Original file line number Diff line number Diff line change @@ -58,4 +58,9 @@ public function getMethod();
5858 * @return bool
5959 */
6060 public function isAync ();
61+
62+ /**
63+ * @return bool
64+ */
65+ public function requiresAuth ();
6166}
You can’t perform that action at this time.
0 commit comments