# Installation

Just add this to your composer.json and then run composer update.

"rossedman/teamwork": "~1.0"

# Configuration With Laravel

This wrapper comes with support for Laravel 5. This includes a service provider as well as a facade for easy access. Once this package is pulled into your project just add this to your config/app.php file.

'providers' => [
  ...
  'Rossedman\Teamwork\TeamworkServiceProvider',
],

and then add the facade to your aliases array

'aliases' => [
  ...
  'Teamwork' => 'Rossedman\Teamwork\Facades\Teamwork',
],

Add To Services

If you are using Laravel then add a teamwork array to your config/services.php file

...
'teamwork' => [
    'key'  => 'YourSecretKey',
    'url'  => 'YourTeamworkUrl'
],

Use

If you are using the Facade with Laravel youc an easily access Teamwork like this

<?php
Teamwork::people()->all();

If you want to use dependency injection to make your application easy to test the Service Provider binds Rossedman\Teamwork\Factory. Here is an example of how to use it with dependency injection

<?php
Route::get('/test', function(Rossedman\Teamwork\Factory $teamwork) {
   $activity = $teamwork->activity()->latest();
});

# Configuration Without Laravel

If you are not using Laravel you can instantiate and use Teamwork. Once you instantiate these classes you can use the class as shown in the examples.

<?php
require "vendor/autoload.php";

use GuzzleHttp\Client as Guzzle;
use Rossedman\Teamwork\Client;
use Rossedman\Teamwork\Factory as Teamwork;

$client     = new Client(new Guzzle, 'YourSecretKey', 'YourTeamworkUrl');
$teamwork   = new Teamwork($client);

# Account

<?php
// Get details of the account.
$teamwork->account()->details();

// Authenticate the account.
$teamwork->account()->authenticate();

# Activity

<?php
// Get the latest activity for all of Teamwork
$teamwork->activity()->latest(['maxItems' => 10]);

// Get only starred activity by the account your are using.
$teamwork->activity()->latest(['onlyStarred' => 1]);

// Delete a specific activity by ID
$teamwork->activity($id)->delete();

# Company

<?php
// Retrieve all companies
$teamwork->company()->all();

// Retrieve company by ID
$teamwork->company($id)->find();

// Create a company! Aha! Business!
$teamwork->company()->create([
    "name" => "Satan Inc.",
    "address_one" => "666 Deathzone Rd.",
    "zip" => "66666",
    "city" => "Lake Of Fire",
    "state" => "Hellworld",
    "countrycode" => "US"
]);

// Update a company
$teamwork->company($id)->update([
    "name" => "Clients From Hell"
]);

// Delete a company
$teamwork->company($id)->delete();

// Get people associated with company
$teamwork->company($id)->people();

# Milestones

<?php
// Get all milestones in Teamwork.
$teamwork->milestones()->all();

// Get all milestones and get progress of each milestone.
$teamwork->milestones()->all(['getProgress' => 'true']);

// Find a specific milestone by id
$teamwork->milestones($id)->find();

// Find milestone by ID with tasks, task lists and progress.
$teamwork->milestones($id)->find([
   'getProgress' => 'true',
   'showTaskLists' => 'true',
   'showTasks' => 'true'
]);

# People

<?php
// Gather all the peoples
$teamwork->people()->all();

// Paginate people
$teamwork->people()->all(['page' => "3", "pageSize" => "10"]);

// Get a person by email address
$teamwork->people()->all(['emailaddress' => '[email protected]']);

// Create a person
$teamwork->people()->create([
    "first-name" => "Warlock",
    "last-name" => "Mastermind",
    "email-address" => "[email protected]",
    "user-type" => "account",
    "user-name" => "Deathlok"
    ...
]);

// Update a person
$teamwork->people($id)->update([
    "first-name" => "Nero"
]);

// Delete a person
$teamwork->people($id)->delete();

// Find out who you are logged in as
$teamwork->people()->me();

// Get all API Keys For site admin only
$teamwork->people()->apiKeys();

# Projects

Projects have the most associated with them and are the most complicated to use. Below are all the methods associated with the Projects class.

<?php
// Get all projects in Teamwork.
$teamwork->project()->all();

// Find a specific project by ID.
$teamwork->project($projectID)->find();

// Create a project
$teamwork->project()->create([
    "name" => "My New Amazing Project",
    "description" => "This is a project that I will dedicate my whole life too",
    "companyId" => "999"
]);

// Update a project
$teamwork->project($projectID)->update([
    "name" => "Satan, The Project"
]);

// Delete a project
$teamwork->project($projectID)->delete();

// Get the latest activity
$teamwork->project($projectID)->activity();
$teamwork->project($projectID)->activity(['maxItems' => 5]);

// Get all companies involved in a project.
$teamwork->project($projectID)->companies();

// Get all people associated with a project.
$teamwork->project($projectID)->people();

// Get starred projects
$teamwork->project()->starred();

// Star or unstar a project
$teamwork->project($projectID)->star();
$teamwork->project($projectID)->unstar();

// Get all links on a project
$teamwork->project($projectID)->links();

// Get the time totals for a project.
$teamwork->project($projectID)->timeTotal();

// Retrieve latest messages and archived messages
$teamwork->project($projectID)->latestMessages();
$teamwork->project($projectID)->archivedMessages();

// Get all milestones
$teamwork->project($projectID)->milestones();

// Create a milestone associated with a project
$teamwork->project($projectId)->createMilestone([
    "title" => "Save The World",
    "description" => "You must save the world in the next few days",
    "deadline" => "20150402",
    "notify" => true,
    "reminder" => true
]);

# Task

<?php
// Get all tasks.
$teamwork->task()->all();

// You can also filter tasks by many different parameters that are
// listed here in the Teamwork developers docs. This example
// shows how to filter by tasks that are overdue and then
// order them by date.
$teamwork->task()->all(['filter' => 'overdue', 'sort' => 'duedate']);

// Retrieve a task by id
$teamwork->task($id)->find();

// Retrieve a task by id and exclude files and subtasks.
$teamwork->task($id)->find(['getFiles' => 'false', 'nestSubTasks' => 'true]);

// Complete and uncomplete a task.
$teamwork->task($id)->complete();
$teamwork->task($id)->uncomplete();

# Tasklist

<?php
// Find a specific tasklist
$teamwork->tasklist($id)->find();

// Update a tasklist
$teamwork->tasklist($id)->update([
    'name' => 'Change The Name'
]);

// Delete a tasklist
$teamwork->tasklist($id)->delete();

// Get time totals for a tasklist
$teamwork->tasklist($id)->timeTotal();

// Get tasklists associated with a project
$teamwork->project($id)->tasklists();