Skip to content

Commit

Permalink
json_decode() if html is no required
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Sep 4, 2020
1 parent 427d75e commit 0889e72
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,111 @@
namespace Rackbeat\Models;


use Illuminate\Support\Arr;
use Rackbeat\Utils\Model;

class Product extends Model
{
public $number;
protected $entity = 'products';
protected $primaryKey = 'number';
public $number;
protected $entity = 'products';
protected $primaryKey = 'number';

public function inventoryMatrix( $location_id = null, array $filter = null )
{
return $this->request->handleWithExceptions( function () use ( $location_id, $filter ) {
public function inventoryMatrix( $location_id = null, array $filter = null ) {
return $this->request->handleWithExceptions( function () use ( $location_id, $filter ) {

$query = '';
$query = '';

// We need to use location filter if user has provided any
if ( !is_null( $location_id ) ) {
// We need to use location filter if user has provided any
if ( !is_null( $location_id ) ) {

$query .= '?location_id=' . $location_id;
}
$query .= '?location_id=' . $location_id;
}

if ( !is_null( $filter ) ) {
if ( !is_null( $filter ) ) {

foreach ( $filter as $parameter => $value ) {
foreach ( $filter as $parameter => $value ) {

if ( $query === '' ) {
if ( $query === '' ) {

$query .= '?' . $parameter . '=' . $value;
$query .= '?' . $parameter . '=' . $value;

} else {
} else {

$query .= '&' . $parameter . '=' . $value;
}
}
}
$query .= '&' . $parameter . '=' . $value;
}
}
}

$response = $this->request->client->get("{$this->entity}/{$this->url_friendly_id}/variation-matrix" .
$query);
$response = $this->request->client->get( "{$this->entity}/{$this->url_friendly_id}/variation-matrix" .
$query );


return json_decode((string)$response->getBody());
} );
$isHtml = filter_var( Arr::get( $filter, 'html', false ), FILTER_VALIDATE_BOOLEAN );
$response = (string) $response->getBody();

}
return $isHtml ? $response : json_decode( $response );
} );

public function variations( $variation_id = 1001 )
{
return $this->request->handleWithExceptions( function () use ( $variation_id ) {
}

$response = $this->request->client->get("variations/{$this->url_friendly_id}/variation-matrix");
public function variations( $variation_id = 1001 ) {
return $this->request->handleWithExceptions( function () use ( $variation_id ) {

$response = $this->request->client->get("variations/{$this->url_friendly_id}/variation-matrix");

return json_decode((string)$response->getBody());
} );
}

public function location($number = null)
{
return $this->request->handleWithExceptions(function () use ($number) {
return (string) $response->getBody();
} );
}

$response = $this->request->client->get("{$this->entity}/{$this->url_friendly_id}/locations" . (($number !== null) ? '/' . $number : ''));
public function location($number = null) {
return $this->request->handleWithExceptions(function () use ($number) {

$response = $this->request->client->get("{$this->entity}/{$this->url_friendly_id}/locations" . (($number !== null) ? '/' . $number : ''));

$response = json_decode((string)$response->getBody());

if (isset($response->product_locations)) {
$response = json_decode((string)$response->getBody());

return collect($response->product_locations);
} else if (isset($response->product_location)) {
if (isset($response->product_locations)) {

return $response->product_location;
} else {
return collect($response->product_locations);
} else if (isset($response->product_location)) {

return $response;
}
return $response->product_location;
} else {

return $response;
}

} );
}

/**
* Show reporting ledger for desired product https://app.rackbeat.com/reporting/ledger/{product_number}
* API docs: https://rackbeat.docs.apiary.io/#reference/inventory-reports/show
*/
public function ledger()
{
return $this->request->handleWithExceptions( function () {
} );
}

$response =
$this->request->client->get("reports/ledger/{$this->{ $this->primaryKey } }");
/**
* Show reporting ledger for desired product https://app.rackbeat.com/reporting/ledger/{product_number}
* API docs: https://rackbeat.docs.apiary.io/#reference/inventory-reports/show
*/
public function ledger() {
return $this->request->handleWithExceptions( function () {

$response =
$this->request->client->get("reports/ledger/{$this->{ $this->primaryKey } }");

return collect(json_decode((string)$response->getBody())->ledger_items);

} );
}
return collect(json_decode((string)$response->getBody())->ledger_items);

public function fields()
{
} );
}

return $this->request->handleWithExceptions( function () {
public function fields() {

$response = $this->request->client->get("{$this->entity}/{$this->url_friendly_id}/fields");
return $this->request->handleWithExceptions( function () {

$response = $this->request->client->get("{$this->entity}/{$this->url_friendly_id}/fields");

return collect(json_decode((string)$response->getBody())->field_values);

} );
}
return collect(json_decode((string)$response->getBody())->field_values);

} );
}
}

0 comments on commit 0889e72

Please sign in to comment.