Skip to content

Commit

Permalink
added api3 bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Matousek committed Aug 21, 2020
1 parent e2cec25 commit 7da6799
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/example-api3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use postabezhranic\Apisdk\Pbh; //zadání namespace Pbh

//pokud nepoužíváte composer je potřeba takto nalinkovat závislosti
require __DIR__ . '/../src/Api3Bridge.php';
require __DIR__ . '/../src/Request.php';

$pbh = new \Postabezhranic\Apisdk\Api3Bridge('username', 'apikey'); //zde zadáme uživatelské jméno a api klíč
$result = $pbh->request('delete-fulfillment-order', [
'apiKey' => '1111',
'userId' => 1,
'data' => [
'orderNumber' => '1-123456789'
],
]);

var_dump($result);
15 changes: 15 additions & 0 deletions src/Api3Bridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Postabezhranic\Apisdk;


class Api3Bridge
{
const HOST = 'https://api.postabezhranic.cz/';

public function request($endpoint, $data){
$result = Request::request(self::HOST . $endpoint, json_encode($data));

return json_decode($result);
}
}
25 changes: 25 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ public function sendRequest($url, $data = ''){

return $this->decodeXml($response);
}

/**
*
* @param string $url
* @param string $data xml
*/
public static function request($url, $data = ''){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . self::CERTIFICATE_PATH);
$response = curl_exec($ch);
$error = curl_error($ch);

if($error){
throw new RequestException($error);
}

curl_close($ch);

return $response;
}


private function decodeXml($response)
Expand Down

0 comments on commit 7da6799

Please sign in to comment.