Skip to content

Commit

Permalink
0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Jun 4, 2017
1 parent f366eee commit 7aadfab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 88 deletions.
90 changes: 3 additions & 87 deletions T/Basic.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,13 @@
<?php
namespace Df\Oro\T;
use Zend_Http_Client as C;
// 2017-06-01
final class Basic extends TestCase {
/** 2017-06-01 */
function t01_users() {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders(['content-type' => 'application/json'] + df_oro_headers())
->setMethod(C::GET)
->setUri("https://localhost.com:848/app_dev.php/api/rest/latest/users")
;
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
echo df_dump(df_json_decode($c->request()->getBody()));
}

/** 2017-06-03 */
function t02_customers() {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders(['content-type' => 'application/json'] + df_oro_headers())
->setMethod(C::GET)
->setUri("https://localhost.com:848/app_dev.php/api/extenddfcustomers")
;
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
echo df_dump(df_json_decode($c->request()->getBody()));
}

/**
* 2017-06-04
* «How to apply a filter to a «get list» Web API request?» https://oplatform.club/t/103
*/
function t03_orders() {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders(['content-type' => 'application/json'] + df_oro_headers())
->setMethod(C::GET)
->setUri("https://localhost.com:848/app_dev.php/api/extenddforders?filter[product]=1")
;
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
echo df_json_encode_pretty(df_json_decode($c->request()->getBody()));
}

/**
* 2017-06-04
* «What is the difference between the «application/json» and «application/vnd.api+json»
* content types of a Web API response?» https://oplatform.club/t/104
*/
function t04_orders_vnd() {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders([
'accept' => 'application/vnd.api+json'
,'content-type' => 'application/vnd.api+json'
] + df_oro_headers())
->setMethod(C::GET)
->setUri("https://localhost.com:848/app_dev.php/api/extenddforders?filter[product]=1")
;
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
echo df_json_encode_pretty(df_json_decode($c->request()->getBody()));
}

/** @test
* 2017-06-04
* «How to include related entities to a response on a Web API «get list» request?»
* https://oplatform.club/t/105
*/
function t05_orders_include() {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders([
'accept' => 'application/vnd.api+json'
,'content-type' => 'application/vnd.api+json'
] + df_oro_headers())
->setMethod(C::GET)
->setUri("https://localhost.com:848/app_dev.php/api/extenddforders?filter[product]=1&include=product,website")
;
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
echo df_json_encode_pretty(df_json_decode($c->request()->getBody()));
}
function t01_orders() {echo df_json_encode_pretty(df_oro_get_list(
'orders', ['product' => 1], ['product', 'website'], true
));}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/oro"
,"version": "0.0.4"
,"version": "0.0.5"
,"description": "A custom integration between Magento 2 and Oro Platform."
,"type": "magento2-module"
,"homepage": "https://ocrm.pro"
Expand Down
37 changes: 37 additions & 0 deletions lib/main.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
<?php
use Df\Oro\Settings\General as S;
use Zend_Http_Client as C;
/**
* 2017-06-04
* @param string $entity
* «How to apply a filter to a «get list» Web API request?» https://oplatform.club/t/103
* @param array(string => mixed) $filter [optional]
* «How to include the related entities to a response on a Web API «get list» request?»
* https://oplatform.club/t/105
* @param string[] $include [optional]
* @param bool $local [optional]
* «What is the difference between the «application/json» and «application/vnd.api+json»
* content types of a Web API response?» https://oplatform.club/t/104
* @param bool $vnd [optional]
* @return array(string => mixed)
*/
function df_oro_get_list($entity, array $filter = [], array $include = [], $local = false, $vnd = true) {
/** @var C $c */
$c = (new C)
->setConfig(['timeout' => 120])
->setHeaders(df_oro_headers() + (!$vnd ? ['application/json'] : array_fill_keys(
['accept', 'content-type'], 'application/vnd.api+json'
)))
->setUri(
'https://'
. ($local ? 'localhost.com:848/app_dev.php' : 'erp.mage2.pro')
. "/api/extenddf$entity"
)
->setParameterGet(df_clean(['filter' => $filter, 'include' => df_csv($include)]))
;
if ($local) {
$c->setAdapter((new \Zend_Http_Client_Adapter_Socket)->setStreamContext([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false]
]));
}
return df_json_decode($c->request()->getBody());
}

/**
* 2017-06-02
* «How is «oro:wsse:generate-header» implemented?» https://oplatform.club/t/84
Expand Down

0 comments on commit 7aadfab

Please sign in to comment.