8000 added deep transformation of objects to array in request responses · oauth-io/sdk-php@fffbc74 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fffbc74

Browse files
committed
added deep transformation of objects to array in request responses
1 parent 4b29bb7 commit fffbc74

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

src/OAuth_io/Request.php

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ public function initialize($provider) {
1414
$this->provider = $provider;
1515
}
1616

17+
private function object_to_array($obj) {
18+
return json_decode(json_encode($obj), true);
19+
}
20+
1721
private function makeRequest($method, $url, $body_fields = null) {
1822
$response = null;
1923
if (!isset($this->injector->session['oauthio']['auth'][$this->provider])) {
2024
throw new NotAuthenticatedException('The user is not authenticated for that provider');
2125
} else {
2226
$prov_data = $this->injector->session['oauthio']['auth'][$this->provider];
2327
$requester = $this->injector->getRequest();
24-
28+
2529
$tokens = array();
2630

2731
$headers = array(
2832
'k' => $this->injector->config['app_key']
2933
);
30-
34+
3135
if (isset($prov_data['access_token'])) {
3236
$headers['access_token'] = $prov_data['access_token'];
3337
}
@@ -36,30 +40,32 @@ private function makeRequest($method, $url, $body_fields = null) {
3640
$headers['oauth_token_secret'] = $prov_data['oauth_token_secret'];
3741
$headers['oauthv1'] = '1';
3842
}
39-
43+
4044
$response = $requester->make_request(array(
4145
'method' => $method,
42-
'url' => $this->injector->config['oauthd_url'] . '/request/' . $this->provider . '/' . urlencode($url),
43-
'headers' => array('oauthio' => http_build_query($headers)),
46+
'url' => $this->injector->config['oauthd_url'] . '/request/' . $this->provider . '/' . urlencode($url) ,
47+
'headers' => array(
48+
'oauthio' => http_build_query($headers)
49+
) ,
4450
'body' => is_array($body_fields) ? $body_fields : null
4551
));
4652
}
4753
return $response;
4854
}
49-
55+
5056
private function makeMeRequest($filters) {
5157
if (!isset($this->injector->session['oauthio']['auth'][$this->provider])) {
5258
throw new \Exception('Error');
5359
} else {
5460
$prov_data = $this->injector->session['oauthio']['auth'][$this->provider];
5561
$requester = $this->injector->getRequest();
56-
62+
5763
$tokens = array();
5864

5965
$headers = array(
6066
'k' => $this->injector->config['app_key']
6167
);
62-
68+
6369
if (isset($prov_data['access_token'])) {
6470
$headers['access_token'] = $prov_data['access_token'];
6571
}
@@ -68,46 +74,53 @@ private function makeMeRequest($filters) {
6874
$headers['oauth_token_secret'] = $prov_data['oauth_token_secret'];
6975
$headers['oauthv1'] = '1';
7076
}
71-
72-
77+
7378
if (is_array($filters)) {
7479
$filters = array(
7580
'filter' => join(',', $filters)
7681
);
7782
}
78-
83+
7984
$response = $requester->make_request(array(
8085
'method' => 'GE 8000 T',
8186
'url' => $this->injector->config['oauthd_url'] . '/auth/' . $this->provider . '/me',
82-
'headers' => array('oauthio' => http_build_query($headers)),
87+
'headers' => array(
88+
'oauthio' => http_build_query($headers)
89+
) ,
8390
'qs' => is_array($filters) ? $filters : null
8491
));
8592
}
8693
return $response;
8794
}
8895

8996
public function get($url) {
90-
return (array) $this->makeRequest('GET', $url)->body;
97+
$response = $this->makeRequest('GET', $url)->body;
98+
$response = $this->object_to_array($response);
99+
return $response;
91100
}
92101

93102
public function post($url, $fields) {
94-
return (array) $this->makeRequest('POST', $url, $fields)->body;
103+
$response = $this->makeRequest('POST', $url, $fields)->body;
104+
return $this->object_t 685C o_array($response);
95105
}
96106

97107
public function put($url, $fields) {
98-
return (array) $this->makeRequest('PUT', $url, $fields)->body;
108+
$response = $this->makeRequest('PUT', $url, $fields)->body;
109+
return $this->object_to_array($response);
99110
}
100111

101112
public function del($url) {
102-
return (array) $this->makeRequest('DELETE', $url)->body;
113+
$response = $this->makeRequest('DELETE', $url)->body;
114+
return $this->object_to_array($response);
103115
}
104116

105117
public function patch($url, $fields) {
106-
return (array) $this->makeRequest('PATCH', $url, $fields)->body->data;
118+
$response = $this->makeRequest('PATCH', $url, $fields)->body->data;
119+
return $this->object_to_array($response);
107120
}
108-
109-
public function me($filters=null) {
110-
$body = $this->makeMeRequest($filters)->body->data;
111-
return (array) $body;
121+
122+
public function me($filters = null) {
123+
$response = $this->makeMeRequest($filters)->body->data;
124+
return $this->object_to_array($response);
112125
}
113-
}
126+
}

0 commit comments

Comments
 (0)
0