Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project list implementation #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Api/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace zaporylie\Tripletex\Api;

use zaporylie\Tripletex\Model\Project\RequestProjectList;
use zaporylie\Tripletex\Resource\Project\ProjectList;

class Project extends ApiBase
{

/**
* @param array $options
*
* @return \zaporylie\Tripletex\Model\Project\ResponseProjectList
*/
public function getList($options = [])
{
$request = new RequestProjectList();
// @todo: Pass options.
$resource = new ProjectList($this->app);
return $resource->call($request);
}
}
48 changes: 48 additions & 0 deletions src/Model/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,52 @@ class Project implements ModelInterface
* @Serializer\Type("zaporylie\Tripletex\Model\Project\ProjectCategory")
*/
protected $projectCategory; // (ProjectCategory, optional)

/**
* @var bool
*
* @Serializer\Type("boolean")
*/
protected $isClosed;

/**
* @var bool
*
* @Serializer\Type("boolean")
*/
protected $isOffer;

/**
* @return ProjectCategory
*/
public function getCategory()
{
return $this->projectCategory;
}

/**
* Gets number value.
*
* @return string
*/
public function getNumber()
{
return $this->number;
}

/**
* @return bool
*/
public function isClosed()
{
return $this->isClosed;
}

/**
* @return bool
*/
public function isOffer()
{
return $this->isOffer;
}
}
190 changes: 190 additions & 0 deletions src/Model/Project/RequestProjectList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?php

namespace zaporylie\Tripletex\Model\Project;

use JMS\Serializer\Annotation as Serializer;
use zaporylie\Tripletex\Model\ModelInterface;

class RequestProjectList implements ModelInterface
{

/**
* @var string
*
* @Serializer\Type("string")
*/
protected $number;

/**
* @var string
*
* @Serializer\Type("string")
*/
protected $name;

/**
* @var string
*
* @Serializer\Type("string")
*/
protected $from;

/**
* @var int
*
* @Serializer\Type("integer")
*/
protected $count;

/**
* @var string
*
* @Serializer\Type("string")
*/
protected $sorting;

/**
* @var string
*
* @Serializer\Type("string")
*/
protected $fields;

/**
* Gets count value.
*
* @return int
*/
public function getCount()
{
return $this->count;
}

/**
* Sets count variable.
*
* @param int $count
*
* @return $this
*/
public function setCount($count)
{
$this->count = $count;
return $this;
}

/**
* Gets from value.
*
* @return string
*/
public function getFrom()
{
return $this->from;
}

/**
* Sets from variable.
*
* @param string $from
*
* @return $this
*/
public function setFrom($from)
{
$this->from = $from;
return $this;
}

/**
* Gets number value.
*
* @return string
*/
public function getNumber()
{
return $this->number;
}

/**
* Sets number variable.
*
* @param string $number
*
* @return $this
*/
public function setNumber($number)
{
$this->number = $number;
return $this;
}

/**
* Gets name value.
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Sets name variable.
*
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

/**
* Gets fields value.
*
* @return string
*/
public function getFields()
{
return $this->fields;
}

/**
* Sets fields variable.
*
* @param string $fields
*
* @return $this
*/
public function setFields($fields)
{
$this->fields = $fields;
return $this;
}

/**
* Gets sorting value.
*
* @return string
*/
public function getSorting()
{
return $this->sorting;
}

/**
* Sets sorting variable.
*
* @param string $sorting
*
* @return $this
*/
public function setSorting($sorting)
{
$this->sorting = $sorting;
return $this;
}
}
41 changes: 41 additions & 0 deletions src/Model/Project/ResponseProjectList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace zaporylie\Tripletex\Model\Project;

use JMS\Serializer\Annotation as Serializer;
use zaporylie\Tripletex\Model\ListBase;
use zaporylie\Tripletex\Model\ModelInterface;

class ResponseProjectList extends ListBase implements ModelInterface
{

/**
* @var \zaporylie\Tripletex\Model\Project\Project[]
*
* @\JMS\Serializer\Annotation\Type("array<zaporylie\Tripletex\Model\Project\Project>")
*/
protected $values;

/**
* Gets values value.
*
* @return \zaporylie\Tripletex\Model\Project\Project[]
*/
public function getValues()
{
return $this->values;
}

/**
* Sets values variable.
*
* @param \zaporylie\Tripletex\Model\Project\Project[] $values
*
* @return $this
*/
public function setValues(array $values)
{
$this->values = $values;
return $this;
}
}
59 changes: 59 additions & 0 deletions src/Resource/Project/ProjectList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace zaporylie\Tripletex\Resource\Project;

use zaporylie\Tripletex\Client\RequestMethod;
use zaporylie\Tripletex\Model\Product\RequestProductList;
use zaporylie\Tripletex\Model\Project\RequestProjectList;
use zaporylie\Tripletex\Resource\ResourceBase;
use zaporylie\Tripletex\Resource\ResourceInterface;

class ProjectList extends ResourceBase implements ResourceInterface
{

/**
* @var \zaporylie\Tripletex\Client\RequestMethod
*/
protected $method = RequestMethod::GET;

/**
* @var string
*/
protected $path = '/project';

/**
* @param \zaporylie\Tripletex\Model\Product\RequestProductList $requestObject
*
* @return \zaporylie\Tripletex\Model\Product\ResponseProductList
*/
public function call(RequestProjectList $requestObject)
{
/** @var \Psr\Http\Message\RequestInterface $request */
$request = $this->app->getClient()->messageFactoryDiscovery()->createRequest(
$this->getMethod(),
$this->getPath().'?'.http_build_query([
'number' => $requestObject->getNumber(),
'name' => $requestObject->getName(),
'from' => $requestObject->getFrom(),
'count' => $requestObject->getCount(),
'sorting' => $requestObject->getSorting(),
'fields' => $requestObject->getFields(),
])
);
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $this->doRequest($request);

// Get response.
$body = $response->getBody()->getContents();

/** @var \zaporylie\Tripletex\Model\Project\ResponseProjectList $responseObject */
// Deserialize response.
$responseObject = $this->app->getSerializer()->deserialize(
$body,
'zaporylie\Tripletex\Model\Project\ResponseProjectList',
'json'
);

return $responseObject;
}
}
9 changes: 9 additions & 0 deletions src/Tripletex.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use zaporylie\Tripletex\Api\Customer;
use zaporylie\Tripletex\Api\Ledger;
use zaporylie\Tripletex\Client\TripletexClient;
use zaporylie\Tripletex\Model\Project\Project;

class Tripletex
{
Expand Down Expand Up @@ -80,6 +81,14 @@ public function product()
return new Product($this);
}

/**
* @return \zaporylie\Tripletex\Api\Project
*/
public function project()
{
return new Api\Project($this);
}

/**
* @return \zaporylie\Tripletex\Api\Order
*/
Expand Down
Loading