xero-php
xero-php copied to clipboard
Support for the Projects API
Appreciate this is really new, but is such support planned? Docs are here, for those who aren't aware of it. Looks like it was only formally released last month: https://developer.xero.com/documentation/projects/overview-projects
Thanks,
Greg
Yeah why not! Have you got an immediate need for it?
Yes I need it. Please help me
Please do it as soon as possible. We really thankful to you sir
@wasimakaram Sorry I don't have time to do this right at the moment. If you're pressed for time, feel free to create some models for it–I don't think it'll take much else.
@calcinai I tried a lot but I am failed. Can you please manage your time? Its your kindness
Working on it for a project I am completing now, I'll submit a PR when its done
@wilsonwc thanks!
I haven't figured out how to submit a PR (haven't bothered) but here is the really bodgy "fix" that I did to load a list of Projects:
1. modify /Remote/Request.php , change this line: $this->setHeader(self::HEADER_ACCEPT, self::CONTENT_TYPE_XML);
to these lines:
if (strpos($url->getFullURL(), 'projects.xro')) {
$this->setHeader(self::HEADER_ACCEPT, self::CONTENT_TYPE_JSON);
} else {
$this->setHeader(self::HEADER_ACCEPT, self::CONTENT_TYPE_XML);
}
2. modify /Remote/Response.php , find the line that says $this->parseJSON(); and change it to:
$this->parseJSON();
return;
3. in the same file, modify the parseJSON() function, in the case statement add these lines before the default:
case 'items':
$this->elements = $root_child;
break;
4. in the same file, change the if (is_array($root_child)) { to
if ( ($child_index != 'pagination') && (is_array($root_child)) ) {
5. modify /Remote/URL.php and in the switch ($api) { add a new case statement above the default:
case 'projects.xro':
$version = '2.0';
break;
6. create new file /Models/Projects/Project.php and add the following code:
<?php
namespace XeroPHP\Models\Projects;
use XeroPHP\Remote;
class Project extends Remote\Model
{
/**
* Get the resource uri of the class (Contacts) etc
*
* @return string
*/
public static function getResourceURI()
{
return 'Projects';
}
/**
* Get the root node name. Just the unqualified classname
*
* @return string
*/
public static function getRootNodeName()
{
return 'Project';
}
/**
* Get the guid property
*
* @return string
*/
public static function getGUIDProperty()
{
return 'ProjectID';
}
/**
* Get the stem of the API (core.xro) etc
*
* @return string|null
*/
public static function getAPIStem()
{
return 'projects.xro';
}
/**
* Get the supported methods
*/
public static function getSupportedMethods()
{
return [
Remote\Request::METHOD_POST,
Remote\Request::METHOD_PUT,
Remote\Request::METHOD_GET,
Remote\Request::METHOD_PATCH
];
}
/**
*
* Get the properties of the object. Indexed by constants
* [0] - Mandatory
* [1] - Type
* [2] - PHP type
* [3] - Is an Array
* [4] - Saves directly
*
* @return array
*/
public static function getProperties()
{
return [
'projectId' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'contactId' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'name' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'deadlineUtc' => [false, self::PROPERTY_TYPE_STRING, null, false, false]
];
}
public static function isPageable()
{
return true;
}
/**
* @return string
*/
public function getProjectID()
{
return $this->_data['projectId'];
}
/**
* @param string $value
* @return Project
*/
public function setProjectID($value)
{
$this->propertyUpdated('projectId', $value);
$this->_data['projectId'] = $value;
return $this;
}
/**
* @return string
*/
public function getContactID()
{
return $this->_data['contactId'];
}
/**
* @param string $value
* @return Contact
*/
public function setContactID($value)
{
$this->propertyUpdated('contactId', $value);
$this->_data['contactId'] = $value;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->_data['name'];
}
/**
* @param string $value
* @return Account
*/
public function setName($value)
{
$this->propertyUpdated('name', $value);
$this->_data['name'] = $value;
return $this;
}
}
Once you've set that all up, you can use it in your own code by doing something like this:
$allProjects = $xero->load('Projects\\Project')->execute();
The above is not complete, but it's a start. Basically projects only work with JSON, so you have to mess with a few things so that it doesn't do everything with XML.
Enjoy.
@calcinai @wasimakaram @gregharvey hope the above helps
@wilsonwc Did you have any success with this? Might get one of my team to sort and do a PR, but no point doing it if you've got it sorted already and are happy to share.
Yes, I've made some progress, but have more classes to be added. Happy to share what I've got.
Ross Wilson Wilson Web Consulting LLC
On Tue, Nov 12, 2019 at 1:45 PM Ian [email protected] wrote:
@wilsonwc https://github.com/wilsonwc Did you have any success with this? Might get one of my team to sort and do a PR, but no point doing it if you've got it sorted already and are happy to share.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/calcinai/xero-php/issues/537?email_source=notifications&email_token=AAFWXUGNTGQSA5JEKOS4JYTQTMIXJA5CNFSM4HBPS3NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED33XAQ#issuecomment-553106306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFWXUDSXEKUT2VEQVJMTALQTMIXJANCNFSM4HBPS3NA .
Thanks everyone, let me know if there's anything I can do to help.
I'm looking to get the oauth2 version of this library running over the Christmas period, but that should have no direct impact on this.
Created the pull request for above.
https://github.com/calcinai/xero-php/pull/774
Has anyone added more functionality? specifically Tasks
I have set the projects tasks URI
/**
* Get the resource uri of the class (Contacts) etc
*
* @return string
*/
public static function getResourceURI()
{
return 'Projects/{project_id}/tasks';
}
How would I inject the project_id into the address
Also, How would I pass the Rate in. I cant seem to get it to work as it needs an array
@matthewhutchings there's not actually any url transformation at this point, so we may need to work this in. Wouldn't Projects
be in the api stem for projects?
If tasks is a sub-object of a project, those models will need to be created in a hierarchical way so it can be parsed properly.