loduis / teamwork.com-project-management

PHP API for Teamwork.com
https://developer.teamwork.com/
MIT License
69 stars 59 forks source link

Documentation Examples needed for GET #17

Open jcandan opened 10 years ago

jcandan commented 10 years ago

I'm having trouble getting a list of Projects and other Teamwork objects.

    TeamWorkPm\Auth::set(API_KEY);
    $projects = TeamWorkPm\Project::getAll();

returns the following error:

Fatal error: Using $this when not in object context in /Users/jcandan/Sites/PHP/Spartan/ssportal/sites/all/libraries/teamwork/src/Project.php on line 58

After which I tried:

    TeamWorkPm\Auth::set(API_KEY);
    $project = new TeamWorkPm\Project;
    $projects = $project->getAll();

and got the following error:

Fatal error: Call to private TeamWorkPm\Rest\Model::__construct() from invalid context in /Users/jcandan/Sites/PHP/Spartan/ssportal/sites/all/modules/custom/teamworkpm/teamworkpm.projects.inc on line 15

What am I doing wrong?

loduis commented 10 years ago

This is the right way

TeamWorkPm\Auth::set(API_KEY);
$project  = TeamWorkPm\Factory::build('project')
$projects = $project->getAll();
loduis commented 10 years ago

Other way:

TeamWorkPm\Auth::set(API_KEY);
list($company, $key) = TeamWorkPm\Auth::get();
$project = TeamWorkPm\Project::getInstance($company, $key);
$projects = $project->getAll();
jcandan commented 10 years ago

Awesome, yeah I finally saw a glimpse of that in examples/save_data.php. I missed it because I saw 'build' and thought that was another CREATE example.

So, I do have one other question: How does one get a single object? Here's what I've tried:

    TeamWorkPm\Auth::set(API_KEY);
    $projects = TeamWorkPm\Factory::build('project');
    $data = $projects->getAll(array($project_id));
loduis commented 10 years ago

Hi this is the main source for Project class:

https://github.com/loduis/TeamWorkPmPhpApi/blob/master/src/Model.php https://github.com/loduis/TeamWorkPmPhpApi/blob/master/src/Project.php Here is a get method

TeamWorkPm\Auth::set(API_KEY);
$project = TeamWorkPm\Factory::build('project');
$data = $project->get($project_id);