@@ -14,20 +14,24 @@ public function initialize($provider) {
14
14
$ this ->provider = $ provider ;
15
15
}
16
16
17
+ private function object_to_array ($ obj ) {
18
+ return json_decode (json_encode ($ obj ), true );
19
+ }
20
+
17
21
private function makeRequest ($ method , $ url , $ body_fields = null ) {
18
22
$ response = null ;
19
23
if (!isset ($ this ->injector ->session ['oauthio ' ]['auth ' ][$ this ->provider ])) {
20
24
throw new NotAuthenticatedException ('The user is not authenticated for that provider ' );
21
25
} else {
22
26
$ prov_data = $ this ->injector ->session ['oauthio ' ]['auth ' ][$ this ->provider ];
23
27
$ requester = $ this ->injector ->getRequest ();
24
-
28
+
25
29
$ tokens = array ();
26
30
27
31
$ headers = array (
28
32
'k ' => $ this ->injector ->config ['app_key ' ]
29
33
);
30
-
34
+
31
35
if (isset ($ prov_data ['access_token ' ])) {
32
36
$ headers ['access_token ' ] = $ prov_data ['access_token ' ];
33
37
}
@@ -36,30 +40,32 @@ private function makeRequest($method, $url, $body_fields = null) {
36
40
$ headers ['oauth_token_secret ' ] = $ prov_data ['oauth_token_secret ' ];
37
41
$ headers ['oauthv1 ' ] = '1 ' ;
38
42
}
39
-
43
+
40
44
$ response = $ requester ->make_request (array (
41
45
'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
+ ) ,
44
50
'body ' => is_array ($ body_fields ) ? $ body_fields : null
45
51
));
46
52
}
47
53
return $ response ;
48
54
}
49
-
55
+
50
56
private function makeMeRequest ($ filters ) {
51
57
if (!isset ($ this ->injector ->session ['oauthio ' ]['auth ' ][$ this ->provider ])) {
52
58
throw new \Exception ('Error ' );
53
59
} else {
54
60
$ prov_data = $ this ->injector ->session ['oauthio ' ]['auth ' ][$ this ->provider ];
55
61
$ requester = $ this ->injector ->getRequest ();
56
-
62
+
57
63
$ tokens = array ();
58
64
59
65
$ headers = array (
60
66
'k ' => $ this ->injector ->config ['app_key ' ]
61
67
);
62
-
68
+
63
69
if (isset ($ prov_data ['access_token ' ])) {
64
70
$ headers ['access_token ' ] = $ prov_data ['access_token ' ];
65
71
}
@@ -68,46 +74,53 @@ private function makeMeRequest($filters) {
68
74
$ headers ['oauth_token_secret ' ] = $ prov_data ['oauth_token_secret ' ];
69
75
$ headers ['oauthv1 ' ] = '1 ' ;
70
76
}
71
-
72
-
77
+
73
78
if (is_array ($ filters )) {
74
79
$ filters = array (
75
80
'filter ' => join (', ' , $ filters )
76
81
);
77
82
}
78
-
83
+
79
84
$ response = $ requester ->make_request (array (
80
85
'method ' => 'GE
8000
T ' ,
81
86
'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
+ ) ,
83
90
'qs ' => is_array ($ filters ) ? $ filters : null
84
91
));
85
92
}
86
93
return $ response ;
87
94
}
88
95
89
96
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 ;
91
100
}
92
101
93
102
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 );
95
105
}
96
106
97
107
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 );
99
110
}
100
111
101
112
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 );
103
115
}
104
116
105
117
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 );
107
120
}
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 ) ;
112
125
}
113
- }
126
+ }
0 commit comments