@@ -106,31 +106,30 @@ public function handleApiError($rbody, $rcode, $resp)
106
106
throw new Shippo_ApiError ($ msg , $ rcode , $ rbody , $ resp );
107
107
}
108
108
}
109
-
110
- private function _requestRaw ( $ method , $ url , $ params )
109
+
110
+ public function getRequestHeaders ( )
111
111
{
112
- $ myApiKey = $ this ->_apiKey ;
113
- if (!$ myApiKey )
114
- $ myApiKey = Shippo::$ apiKey ;
115
-
116
- if (!$ myApiKey ) {
117
- $ msg = 'No credentials provided. ' ;
118
- throw new Shippo_AuthenticationError ($ msg );
119
- }
120
-
121
- $ absUrl = $ this ->apiUrl ($ url );
122
- $ params = self ::_encodeObjects ($ params );
123
- $ langVersion = phpversion ();
124
- $ uname = php_uname ();
112
+ $ apiKey = $ this ->_getApiKey ();
113
+
125
114
$ headers = array (
126
115
'Content-Type: application/json ' ,
127
- 'Authorization: ' . $ this ->_getAuthorizationType ($ myApiKey ) . ' ' . $ myApiKey ,
116
+ 'Authorization: ' . $ this ->_getAuthorizationType ($ apiKey ) . ' ' . $ apiKey ,
128
117
'Accept: application/json ' ,
129
118
'User-Agent: Shippo/v1 PHPBindings/ ' . Shippo::VERSION
130
119
);
131
120
if (Shippo::getApiVersion ()){
132
121
$ headers [] = 'Shippo-API-Version: ' . Shippo::getApiVersion ();
133
122
}
123
+
124
+ return $ headers ;
125
+ }
126
+
127
+ private function _requestRaw ($ method , $ url , $ params )
128
+ {
129
+ $ absUrl = $ this ->apiUrl ($ url );
130
+ $ params = self ::_encodeObjects ($ params );
131
+ $ myApiKey = $ this ->_getApiKey ();
132
+ $ headers = $ this ->getRequestHeaders ();
134
133
135
134
list ($ rbody , $ rcode ) = $ this ->httpClient ()->request ($ method , $ absUrl , $ headers , $ params );
136
135
return array (
@@ -156,6 +155,19 @@ private function _interpretResponse($rbody, $rcode)
156
155
return $ resp ;
157
156
}
158
157
158
+ private function _getApiKey ()
159
+ {
160
+ $ apiKey = $ this ->_apiKey ;
161
+ if (!$ apiKey )
162
+ $ apiKey = Shippo::$ apiKey ;
163
+
164
+ if (!$ apiKey ) {
165
+ throw new Shippo_AuthenticationError ('No credentials provided. ' );
166
+ }
167
+
168
+ return $ apiKey ;
169
+ }
170
+
159
171
private function _getAuthorizationType ($ apiKey = '' )
160
172
{
161
173
return strpos ($ apiKey , 'oauth. ' ) === 0 ? 'Bearer ' : 'ShippoToken ' ;
0 commit comments