Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from talisman-innovations/master
Browse files Browse the repository at this point in the history
Minor versions for create and update
  • Loading branch information
khairulashraff committed Mar 6, 2018
2 parents 9602f40 + f6620f7 commit f3fe3cf
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/Services/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Rangka\Quickbooks\Query;

class Service extends Client {

/**
* Resource endpoint of this service.
*
Expand All @@ -28,22 +29,24 @@ class Service extends Client {
protected static $responseHasRoot = true;

/**
* Load a single item
*
* @return
*/
* Load a single item
*
* @return
*/
public function load($id) {
return parent::get($this->getResourceName() . '/' . $id)->{$this->getEntityName()};
}

/**
* Create a single item
*
* @param array $data Item information
* @return
*/
public function create($data) {
$response = parent::post($this->getResourceName(), $data);
* Create a single item
*
* @param array $data Item information
* @param int $minorVersion
* @return
*/
public function create($data, $minorVersion = null) {
$query = ($minorVersion) ? '?minorversion=' . $minorVersion : '';
$response = parent::post($this->getResourceName() . $query, $data);

// Response has no root, send it back immediately.
if (!static::$responseHasRoot) {
Expand All @@ -54,13 +57,16 @@ public function create($data) {
}

/**
* Update an entity.
*
* @param array $data Item information.
* @return void
*/
public function update($data) {
$response = parent::post($this->getResourceName() . '?operation=update', $data);
* Update an entity.
*
* @param array $data Item information.
* @param int $minorVersion
* @return void
*/
public function update($data, $minorVersion = null) {
$query = ($minorVersion) ? '&minorversion=' . $minorVersion : '';
$response = parent::post($this->getResourceName() . '?operation=update' . $query, $data);

// Response has no root, send it back immediately.
if (!static::$responseHasRoot) {
Expand All @@ -69,44 +75,44 @@ public function update($data) {

return $response->{$this->getEntityName()};
}

/**
* Delete an entity.
*
* @param array $data Item information.
* @return void
*/
* Delete an entity.
*
* @param array $data Item information.
* @return void
*/
public function delete($data) {
return parent::post($this->getResourceName() . '?operation=delete', [
'Id' => $data,
'SyncToken' => 0,
])->{$this->getEntityName()};
'Id' => $data,
'SyncToken' => 0,
])->{$this->getEntityName()};
}

/**
* Query quickbooks. Use Query to construct the query itself.
*
* @param \Rangka\Quickbooks\Query $query Query object
* @return object
*/
* Query quickbooks. Use Query to construct the query itself.
*
* @param \Rangka\Quickbooks\Query $query Query object
* @return object
*/
public function query() {
return (new Query($this))->entity($this->getEntityName());
}

/**
* Get all items of this Entity.
*
* @return object
*/
* Get all items of this Entity.
*
* @return object
*/
public function all() {
return $this->query()->get();
}

/**
* Get builder instance to construct entity data.
*
* @return \Rangka\Quickbooks\Builders\Builder
*/
* Get builder instance to construct entity data.
*
* @return \Rangka\Quickbooks\Builders\Builder
*/
public function getBuilder() {
$class = '\Rangka\Quickbooks\Builders\\' . $this->getClassName();
return new $class($this);
Expand All @@ -121,7 +127,6 @@ public function getEntityName() {
if (static::$entity) {
return static::$entity;
}

return $this->getClassName();
}

Expand All @@ -130,10 +135,9 @@ public function getEntityName() {
*
* @return string
*/
public function getClassName()
{
public function getClassName() {
$fullClass = get_called_class();
$exploded = explode('\\', $fullClass);
$exploded = explode('\\', $fullClass);

return end($exploded);
}
Expand All @@ -146,4 +150,5 @@ public function getClassName()
public function getResourceName() {
return static::$resource ?: strtolower($this->getEntityName());
}

}

0 comments on commit f3fe3cf

Please sign in to comment.