Skip to content

Latest commit

 

History

History
316 lines (238 loc) · 9.47 KB

README.md

File metadata and controls

316 lines (238 loc) · 9.47 KB

Basecamp SDK for PHP

Build Status

The Basecamp SDK for PHP enables PHP developers to easily integrate 37signals Basecamp all new API into their applications.

NOTE: This library is under heavy development and a lot of calls haven't been implemented yet. We're looking forward to any of your PR's.

Installation

We recommend Composer for managing dependencies. Installing is as easy as:

$ php composer.phar require netvlies/basecamp-php

Usage

To use the library the only requirement is you have a account. Upon creating the client you have to pass your credentials or an OAuth token. Furthermore you need your userId to construct the URI's.

Authorization with username and password

<?php

$client = \Basecamp\BasecampClient::factory(array(
    'auth' => 'http',
    'username' => 'you@email.com',
    'password' => 'secret',
    'user_id' => 99999999,
    'app_name' => 'My Wicked Application',
    'app_contact' => 'http://mywickedapplication.com'
));

Authorization with OAuth token

This library doesn't handle the OAuth authorization process for you. There are already a lot of libraries out there which handle this process perfectly for you. When you recieved your token you'll have to pass it on to the client:

<?php

$client = \Basecamp\BasecampClient::factory(array(
    'auth'     => 'oauth',
    'token'    => 'Wtj4htewhtuewhuoitewh',
    'user_id'   => 99999999,
    'app_name' => 'My Wicked Application',
    'app_contact' => 'http://mywickedapplication.com'
));

Identification

It is required to identify you application. This can be accomplished by using app_name and app_contact.

About this API client

This client is build upon the shoulders of the impressive Guzzle library. If you're willing to contribute to this client, make sure to check out the docs.

Caching

It is required to implement caching in your application. Lucky for you, using Guzzle this is peanuts! Please refer to the official docs for more information.

Here's a quick example using the Doctrine cache:

<?php

use Basecamp\BasecampClient;
use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;
use Guzzle\Plugin\Cache\CachePlugin;

$cachePlugin = new CachePlugin(array(
    'adapter' => new DoctrineCacheAdapter(new FilesystemCache(__DIR__.'/../../../../app/cache/basecamp'))
));

$this->client = BasecampClient::factory(array(
    // config options
));
$this->client->addSubscriber($cachePlugin);

API calls

All services are documented below. View full service description in src/Basecamp/Resources/service.php

Get archived Projects

Basecamp API: Projects

$response = $client->getArchivedProjects(); 

Get active Projects

Basecamp API: Projects

$response = $client->getProjects(); 

Get a Project

Basecamp API: Projects

$response = $client->getProject( array( 
	'id' => 1234567,  // Required. Project ID 
) ); 

Get all Documents

Basecamp API: Documents

$response = $client->getDocumentsByProject( array( 
	'projectId' => 1234567,  // Required. Project ID 
) ); 

Get a Document

Basecamp API: Documents

$response = $client->getDocument( array( 
	'projectId' => 1234567,  // Required. Project ID 
	'documentId' => 1234567,  // Required. Document ID 
) ); 

Get Topics

Basecamp API: Topics

$response = $client->getTopicsByProject( array( 
	'projectId' => 1234567,  // Required. Project ID 
) ); 

Get Todo Lists

Basecamp API: Todo lists

$response = $client->getTodolistsByProject( array( 
	'projectId' => 1234567,  // Required. Project ID 
) ); 

Get Todo Lists assigned to a Person

Basecamp API: Todo lists

$response = $client->getAssignedTodolistsByPerson( array( 
	'personId' => 1234567,  // Required. Person id
	'page' => 1234567,  // Optional
	'due_since' => '2012-03-24T11:00:00-06:00',  // Optional
) ); 

Get completed Todo Lists

Basecamp API: Todo lists

$response = $client->getCompletedTodolistsByProject( array( 
	'projectId' => 1234567,  // Required. Project id 
) ); 

Create Todo List

Basecamp API: Todo lists

$response = $client->createTodolistByProject( array( 
	'projectId' => 1234567,  // Required. Project id 
	'name' => 'Example name',  // Required.  
	'description' => 'Example description',  // Required.  
) ); 

Create Todo

Basecamp API: Todos

$response = $client->createTodoByTodolist( array( 
	'projectId' => 1234567,  // Required. Project id 
	'todolistId' => 1234567,  // Required. Todo list id 
	'content' => 'Example content',  // Required.  
	'assignee' => array( 'id' => 1234567, 'type' => 'Person' ),  // Optional.  
) ); 

Create Comment on Todo

Basecamp API: Comments

$response = $client->createCommentByTodo( array( 
	'projectId' => 1234567,  // Required. Project id 
	'todoId' => 1234567,  // Required. Todo id 
	'content' => 'Example content',  // Required.  
	'attachments' => array( array( 'token' => $upload_token, 'name' => 'file.jpg' ) ),  // Optional.  
) ); 

Get Attachments

Basecamp API: Attachments

$response = $client->getAttachmentsByProject( array( 
	'projectId' => 1234567,  // Required. Project id 
) ); 

Create Attachment

Basecamp API: Attachments

$response = $client->createAttachment( array( 
	'mimeType' => 'image/jpeg',  // Required. The content type of the data 
	'data' => file_get_contents( 'image.jpg' ),  // Required. The attachment's binary data 
) ); 

Get Todo List

Basecamp API: Todo lists

$response = $client->getTodolist( array( 
	'projectId' => 1234567,  // Required. Project id 
	'todolistId' => 1234567,  // Required. Todolist id 
) ); 

Get Todo

Basecamp API: Todos

$response = $client->getTodo( array( 
	'projectId' => 1234567,  // Required. Project id 
	'todoId' => 1234567,  // Required. Todo id 
) ); 

Update Todo

Basecamp API: Todos

$response = $client->updateTodo( array( 
	'projectId' => 1234567,  // Required. Project id 
	'todoId' => 1234567,  // Required. Todo id 
	'content' => 'Example content',  // Optional.  
	'due_at' => 'example',  // Optional.  
	'assignee' => array( 'id' => 1234567, 'type' => 'Person' ),  // Optional.  
	'completed' => 'example',  // Optional.  
) ); 

Get current User

Basecamp API: People

$response = $client->getCurrentUser(); 

Get global Events

Basecamp API: Events

$response = $client->getGlobalEvents( array( 
	'since' => '2012-03-24T11:00:00-06:00',  // Optional. All events since given datetime (format: 2012-03-24T11:00:00-06:00) 
	'page' => 1234567,  // Optional. The page to retrieve. API returns 50 events per page. 
) ); 

Get Project Events

Basecamp API: Events

$response = $client->getProjectEvents( array( 
	'projectId' => 1234567,  // Required. Project id 
	'since' => '2012-03-24T11:00:00-06:00',  // Optional. All events since given datetime (format: 2012-03-24T11:00:00-06:00) 
) ); 

Get Accesses to Project

Basecamp API: Accesses

$response = $client->getAccessesByProject( array( 
	'projectId' => 1234567,  // Required. Project id 
) ); 

Get Accesses to Calendar

Basecamp API: Accesses

$response = $client->getAccessesByCalendar( array( 
	'calendarId' => 1234567,  // Required. Calendar id 
) ); 

Get all People

Basecamp API: People

$response = $client->getPeople();