Skip to content

Commit a20bd9c

Browse files
authored
Merge pull request #18 from Oneflow/development
Release 1.0.3
2 parents e6368a6 + 2da4deb commit a20bd9c

File tree

10 files changed

+146
-280
lines changed

10 files changed

+146
-280
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oneflow/php-sdk",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "PHP SDK for OneFlow",
55
"minimum-stability": "stable",
66
"license": "OneFlow Master",

src/OneflowSDK.php

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function setAuthHeader($header){
6565
* accountsGetMy function.
6666
*
6767
* @access public
68-
* @return void
68+
* @return mixed
6969
*/
7070
public function accountsGetMy(){
7171
return json_decode($this->get('/account'));
@@ -75,7 +75,7 @@ public function accountsGetMy(){
7575
* accountsGetAll function.
7676
*
7777
* @access public
78-
* @return void
78+
* @return mixed
7979
*/
8080
public function accountsGetAll(){
8181
return json_decode($this->get('/account/all'));
@@ -86,7 +86,7 @@ public function accountsGetAll(){
8686
*
8787
* @access public
8888
* @param mixed $id
89-
* @return void
89+
* @return mixed
9090
*/
9191
public function accountsGetById($id){
9292
return json_decode($this->get('/account/' . $id));
@@ -96,9 +96,9 @@ public function accountsGetById($id){
9696
* accountsCreate function.
9797
*
9898
* @access public
99-
* @return void
99+
* @return mixed
100100
*/
101-
public function accountsCreate(){
101+
public function accountsCreate($data){
102102
return json_decode($this->post('/account', $data));
103103
}
104104

@@ -109,7 +109,7 @@ public function accountsCreate(){
109109
*
110110
* @access private
111111
* @param mixed $orderResponse
112-
* @return void
112+
* @return mixed
113113
*/
114114
private function processOrderArray($orderResponse){
115115
$orders = Array();
@@ -131,7 +131,7 @@ private function processOrderArray($orderResponse){
131131
*
132132
* @access public
133133
* @param mixed $id
134-
* @return void
134+
* @return OneFlowOrder
135135
*/
136136
public function ordersGetById($id){
137137
$order = json_decode($this->get('/order/' . $id));
@@ -143,37 +143,29 @@ public function ordersGetById($id){
143143
*
144144
* @access public
145145
* @param mixed $order
146-
* @return void
146+
* @return mixed
147147
*/
148148
public function orderValidate($order) {
149-
150149
echo "Validation : Passed\n";
151150
return $this->post('/order/validate', $order->toJSON());
152-
153151
}
154152

155153
/**
156154
* ordersCreate function.
157155
*
158156
* @access public
159157
* @param mixed $order
160-
* @return void
158+
* @return mixed
161159
*/
162160
public function ordersCreate($order) {
163-
164161
//check that order is valid before submission
165-
166162
if (count($order->isValid())>0) {
167-
168163
echo "Validation : Failed\n";
169164
return $order->validateOrder();
170-
171165
} else {
172-
173166
echo "Validation : Passed\n";
174167
return $this->post('/order', $order->toJSON());
175168
}
176-
177169
}
178170

179171
/**
@@ -182,7 +174,7 @@ public function ordersCreate($order) {
182174
* @access public
183175
* @param mixed $uploadUrl
184176
* @param mixed $localPath
185-
* @return void
177+
* @return mixed
186178
*/
187179
public function postFile($uploadUrl, $localPath){
188180
if (file_exists($localPath)) {
@@ -197,7 +189,7 @@ public function postFile($uploadUrl, $localPath){
197189
*
198190
* @access public
199191
* @param mixed $id
200-
* @return void
192+
* @return mixed
201193
*/
202194
public function orderCancel($id){
203195
if (strlen($id)>0) return $this->put("/order/$id/cancel");
@@ -210,7 +202,7 @@ public function orderCancel($id){
210202
* @access public
211203
* @param mixed $id
212204
* @param mixed $orderData
213-
* @return void
205+
* @return mixed
214206
*/
215207
public function ordersUpdateById($id, $orderData){
216208
if (strlen($id)>0) return $this->put("/order/$id", json_encode($orderData));
@@ -227,10 +219,10 @@ public function ordersUpdateById($id, $orderData){
227219
* @param mixed $path
228220
* @param mixed $jsonData (default: null)
229221
* @param mixed $optional_headers (default: null)
230-
* @return void
222+
* @throws Exception
223+
* @return mixed
231224
*/
232-
protected function request($method, $path, $jsonData=null, $optional_headers = null) {
233-
225+
protected function request($method, $path, $jsonData=null, $optional_headers = null) {
234226
ini_set("track_errors","on");
235227

236228
$timestamp = time();
@@ -255,18 +247,15 @@ protected function request($method, $path, $jsonData=null, $optional_headers = n
255247
}
256248

257249
$params['http']['header'][] = "x-oneflow-date: $timestamp";
258-
$params['http']['header'][] = $this->authHeader.": ".$this->token($method, $fullPath, $timestamp, $jsonData);
250+
$params['http']['header'][] = $this->authHeader.": ".$this->token($method, $fullPath, $timestamp);
259251

260252
foreach ($optional_headers as $name => $value) {
261253
$params['http']['header'][] = "$name: $value";
262254
}
263255

264-
// echo "Connecting To : $url\n";
265-
266256
$context = stream_context_create($params);
267257
$fp = fopen($url, 'rb', false, $context);
268258
if (!$fp) {
269-
// print_r($http_response_header);
270259
throw new Exception("Problem creating stream from $url, \n\t".implode("\n\t", error_get_last()));
271260
}
272261

@@ -282,17 +271,15 @@ protected function request($method, $path, $jsonData=null, $optional_headers = n
282271
* @access private
283272
* @param mixed $path
284273
* @param string $format (default: 'application/json')
285-
* @return void
274+
* @return mixed
286275
*/
287276
protected function get($path, $format = 'application/json'){
288-
289277
try {
290-
291278
$response = $this->request("GET", $path, "", array(
292279
'Accept' => $format,
293280
));
294-
295281
} catch (Exception $e) {
282+
$response = null;
296283
echo "get exception\n";
297284
echo $e->getMessage()."\n";
298285
}
@@ -307,19 +294,17 @@ protected function get($path, $format = 'application/json'){
307294
* @param mixed $path
308295
* @param mixed $jsonData
309296
* @param string $format (default: 'application/json')
310-
* @return void
297+
* @return mixed
311298
*/
312299
protected function post($path, $jsonData, $format = 'application/json') {
313-
314300
try {
315-
316301
$response = $this->request("POST", $path, $jsonData, array(
317302
'Content-Type' => $format,
318303
'Accept' => $format,
319304
));
320-
321305
} catch (Exception $e) {
322-
echo $e->getMessage()."\n";
306+
$response = null;
307+
echo $e->getMessage()."\n";
323308
}
324309

325310
return $response;
@@ -332,19 +317,17 @@ protected function post($path, $jsonData, $format = 'application/json') {
332317
* @param mixed $path
333318
* @param mixed $jsonData
334319
* @param string $format (default: 'application/json')
335-
* @return void
320+
* @return mixed
336321
*/
337322
protected function put($path, $jsonData, $format = 'application/json'){
338-
339323
try {
340-
341324
$response = $this->request("PUT", $path, $jsonData, array(
342325
'Content-Type' => $format,
343326
'Accept' => $format,
344327
));
345-
346328
} catch (Exception $e) {
347-
echo $e->getMessage()."\n";
329+
$response = null;
330+
echo $e->getMessage()."\n";
348331
}
349332

350333
return $response;
@@ -356,17 +339,16 @@ protected function put($path, $jsonData, $format = 'application/json'){
356339
* @access private
357340
* @param mixed $path
358341
* @param string $format (default: 'application/json')
359-
* @return void
342+
* @return mixed
360343
*/
361344
protected function del($path, $format = 'application/json'){
362-
363345
try {
364346
$response = $this->request("DELETE", $path, "", array(
365347
'Accept' => $format,
366348
));
367-
368349
} catch (Exception $e) {
369-
echo $e->getMessage()."\n";
350+
$response = null;
351+
echo $e->getMessage()."\n";
370352
}
371353

372354
return $response;
@@ -378,7 +360,8 @@ protected function del($path, $format = 'application/json'){
378360
* @access public
379361
* @param mixed $uploadUrl
380362
* @param mixed $localPath
381-
* @return void
363+
* @throws Exception when a problem occurs
364+
* @return mixed
382365
*/
383366
protected function post_file_s3($uploadUrl, $localPath) {
384367

@@ -409,7 +392,7 @@ protected function post_file_s3($uploadUrl, $localPath) {
409392
if (!$fp) throw new Exception("PROBLEM:\n".implode("\n\t", error_get_last())."\n\n\n\n");
410393

411394
$response = stream_get_contents($fp);
412-
if ($response === false) throw new Exception("Problem reading data from $url, $php_errormsg");
395+
if ($response === false) throw new Exception("Problem reading data from $uploadUrl, $php_errormsg");
413396

414397
return $response;
415398
}
@@ -421,7 +404,7 @@ protected function post_file_s3($uploadUrl, $localPath) {
421404
* @param mixed $method
422405
* @param mixed $path
423406
* @param mixed $timestamp
424-
* @return void
407+
* @return string
425408
*/
426409
private function token($method, $path, $timestamp){
427410
$stringToSign = strtoupper($method) . ' ' . $path . ' ' . $timestamp;

0 commit comments

Comments
 (0)