netvlies / basecamp-php
Basecamp API 使得开发者能够轻松与 37signals Basecamp 平台进行通信
dev-master / 1.0.x-dev
2016-10-12 11:31 UTC
Requires
- guzzle/guzzle: ~3.3
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-14 15:00:47 UTC
README
PHP 的 Basecamp SDK 允许 PHP 开发者轻松将 37signals Basecamp 的新 API 集成到他们的应用程序中。
注意:此库正在积极开发中,许多调用尚未实现。我们期待您提交的任何 PR。
安装
我们建议使用 Composer 来管理依赖项。安装就像这样简单
$ php composer.phar require netvlies/basecamp-php
使用
要使用此库,唯一的要求是您有一个账户。创建客户端时,您必须传递您的凭据或 OAuth 令牌。此外,您还需要您的 userId 来构造 URI。
使用用户名和密码进行授权
<?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' ));
使用 OAuth 令牌进行授权
此库不会为您处理 OAuth 授权过程。已经有许多库可以完美地为您处理此过程。收到令牌后,您必须将其传递给客户端
<?php $client = \Basecamp\BasecampClient::factory(array( 'auth' => 'oauth', 'token' => 'Wtj4htewhtuewhuoitewh', 'user_id' => 99999999, 'app_name' => 'My Wicked Application', 'app_contact' => 'http://mywickedapplication.com' ));
识别
需要识别您的应用程序。这可以通过使用 app_name
和 app_contact
完成。
关于此 API 客户端
此客户端建立在令人印象深刻的 Guzzle 库 之上。如果您愿意为此客户端做出贡献,请确保查看文档。
缓存
需要在您的应用程序中实现缓存。幸运的是,使用 Guzzle 这非常简单!请参阅 官方文档 获取更多信息。
这里是一个使用 Doctrine 缓存的快速示例
<?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 调用
以下列出了所有服务。在 src/Basecamp/Resources/service.php 中查看完整的服务描述。
获取存档项目
$response = $client->getArchivedProjects();
获取活动项目
$response = $client->getProjects();
获取一个项目
$response = $client->getProject( array( 'id' => 1234567, // Required. Project ID ) );
获取所有文档
$response = $client->getDocumentsByProject( array( 'projectId' => 1234567, // Required. Project ID ) );
获取一个文档
$response = $client->getDocument( array( 'projectId' => 1234567, // Required. Project ID 'documentId' => 1234567, // Required. Document ID ) );
获取主题
$response = $client->getTopicsByProject( array( 'projectId' => 1234567, // Required. Project ID ) );
获取待办事项列表
$response = $client->getTodolistsByProject( array( 'projectId' => 1234567, // Required. Project ID ) );
获取分配给某人的待办事项列表
$response = $client->getAssignedTodolistsByPerson( array( 'personId' => 1234567, // Required. Person id 'page' => 1234567, // Optional. The page to retrieve. API returns 50 todos per page. 'due_since' => 'example', // Optional. Will return all the to-do lists with to-dos assigned to the specified person due after the date specified. (format: 2012-03-24T11:00:00-06:00) ) );
获取完成的待办事项列表
$response = $client->getCompletedTodolistsByProject( array( 'projectId' => 1234567, // Required. Project id ) );
获取完成的待办事项
$response = $client->getCompletedTodosByProject( array( 'projectId' => 1234567, // Required. Project id ) );
创建新的项目
$response = $client->createProject( array( 'name' => 'Example name', // Required. 'description' => 'Example description', // Required. ) );
创建新的文档
$response = $client->createDocument( array( 'projectId' => 1234567, // Required. Project ID 'title' => 'example', // Required. 'content' => 'Example content', // Required. ) );
创建待办事项列表
$response = $client->createTodolistByProject( array( 'projectId' => 1234567, // Required. Project id 'name' => 'Example name', // Required. 'description' => 'Example description', // Required. ) );
创建待办事项
$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. ) );
在待办事项上创建评论
$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. ) );
获取附件
$response = $client->getAttachmentsByProject( array( 'projectId' => 1234567, // Required. Project id ) );
创建附件
$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 ) );
获取待办事项列表
$response = $client->getTodolist( array( 'projectId' => 1234567, // Required. Project id 'todolistId' => 1234567, // Required. Todolist id ) );
获取待办事项
$response = $client->getTodo( array( 'projectId' => 1234567, // Required. Project id 'todoId' => 1234567, // Required. Todo id ) );
更新待办事项
$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. ) );
获取当前用户
$response = $client->getCurrentUser();
获取特定用户
$response = $client->getSpecificUser( array( 'personId' => 1234567, // Required. Person id ) );
获取全局事件
$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. ) );
获取项目事件
$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) ) );
获取项目访问权限
$response = $client->getAccessesByProject( array( 'projectId' => 1234567, // Required. Project id ) );
获取日历访问权限
$response = $client->getAccessesByCalendar( array( 'calendarId' => 1234567, // Required. Calendar id ) );
获取所有人员
$response = $client->getPeople();
获取所有组
$response = $client->getGroups();
授予访问权限
$response = $client->grantAccess( array( 'projectId' => 1234567, // Required. Project id 'ids' => '', // Required. Existing user ids 'email_addresses' => 'example', // Optional. Grant access to new users ) );
获取所有日历
$response = $client->getCalendars();
获取单个日历
$response = $client->getCalendar( array( 'calendarId' => 1234567, // Required. Calendar id ) );
创建新的日历
$response = $client->createCalendar( array( 'name' => 'Example name', // Required. ) );
更新日历
$response = $client->updateCalendar( array( 'calendarId' => 1234567, // Required. Calendar id 'name' => 'Example name', // Required. ) );
删除日历
$response = $client->deleteCalendar( array( 'calendarId' => 1234567, // Required. Calendar id ) );
获取所有事件
$response = $client->getAllCalendarEvents( array( 'start_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) 'end_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) ) );
获取即将到来的日历事件
$response = $client->getCalendarEvents( array( 'calendarId' => 1234567, // Required. Calendar id 'start_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) 'end_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) ) );
获取过去的日历事件
$response = $client->getCalendarEventsPast( array( 'calendarId' => 1234567, // Required. Calendar id ) );
获取单个日历事件
$response = $client->getCalendarEvent( array( 'calendarId' => 1234567, // Required. Calendar id 'eventId' => 1234567, // Required. Event id ) );
创建日历事件
$response = $client->createCalendarEvent( array( 'calendarId' => 1234567, // Required. Calendar id 'summary' => 'example', // Required. Event Summary / title 'description' => 'Example description', // Optional. Event Description 'starts_at' => 'example', // Required. Date (and time if not an all day event) that the event starts at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'ends_at' => 'example', // Optional. Date (and time if not an all day event) that the event ends at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'remind_at' => 'example', // Optional. Datetime to remind subscribers about the event via email (format: 2015-09-15T11:50:00-05:00) 'subscribers' => '', // Optional. Array of user id's to subscribe to the event. 'recurring' => '', // Optional. Array of recurring parrameters - starts_at, frequency, count, until, excluding 'all_day' => '', // Optional. Is the event a full day event? ) );
更新日历事件
$response = $client->updateCalendarEvent( array( 'calendarId' => 1234567, // Required. Calendar id 'eventId' => 1234567, // Required. Event id 'summary' => 'example', // Optional. Event Summary / title 'description' => 'Example description', // Optional. Event Description 'starts_at' => 'example', // Optional. Date (and time if not an all day event) that the event starts at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'ends_at' => 'example', // Optional. Date (and time if not an all day event) that the event ends at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'remind_at' => 'example', // Optional. Datetime to remind subscribers about the event via email (format: 2015-09-15T11:50:00-05:00) 'subscribers' => '', // Optional. Array of user id's to subscribe to the event. 'recurring' => '', // Optional. Array of recurring parrameters - starts_at, frequency, count, until, excluding 'all_day' => '', // Optional. Is the event a full day event? ) );
删除日历事件
$response = $client->deleteCalendarEvent( array( 'calendarId' => 1234567, // Required. Calendar id 'eventId' => 1234567, // Required. Event id ) );
获取即将到来的项目日历事件
$response = $client->getProjectCalendarEvents( array( 'projectId' => 1234567, // Required. Project ID 'start_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) 'end_date' => 'example', // Optional. Will return 6 weeks worth of events after the start date if the end date is not supplied (format: 2015-09-15) ) );
获取过去的项目日历事件
$response = $client->getProjectCalendarEventsPast( array( 'projectId' => 1234567, // Required. Project ID ) );
获取单个项目日历事件
$response = $client->getProjectCalendarEvent( array( 'projectId' => 1234567, // Required. Project id 'eventId' => 1234567, // Required. Event id ) );
创建项目日历事件
$response = $client->createProjectCalendarEvent( array( 'projectId' => 1234567, // Required. Project id 'summary' => 'example', // Required. Event Summary / title 'description' => 'Example description', // Optional. Event Description 'starts_at' => 'example', // Required. Date (and time if not an all day event) that the event starts at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'ends_at' => 'example', // Optional. Date (and time if not an all day event) that the event ends at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'remind_at' => 'example', // Optional. Datetime to remind subscribers about the event via email (format: 2015-09-15T11:50:00-05:00) 'subscribers' => '', // Optional. Array of user id's to subscribe to the event. 'recurring' => '', // Optional. Array of recurring parrameters - starts_at, frequency, count, until, excluding 'all_day' => '', // Optional. Is the event a full day event? ) );
更新项目日历事件
$response = $client->updateProjectCalendarEvent( array( 'projectId' => 1234567, // Required. Project id 'eventId' => 1234567, // Required. Event id 'summary' => 'example', // Optional. Event Summary / title 'description' => 'Example description', // Optional. Event Description 'starts_at' => 'example', // Optional. Date (and time if not an all day event) that the event starts at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'ends_at' => 'example', // Optional. Date (and time if not an all day event) that the event ends at (format: 2015-09-15 or 2015-09-15T11:50:00-05:00) 'remind_at' => 'example', // Optional. Datetime to remind subscribers about the event via email (format: 2015-09-15T11:50:00-05:00) 'subscribers' => '', // Optional. Array of user id's to subscribe to the event. 'recurring' => '', // Optional. Array of recurring parrameters - starts_at, frequency, count, until, excluding 'all_day' => '', // Optional. Is the event a full day event? ) );
删除项目日历事件
$response = $client->deleteProjectCalendarEvent( array( 'projectId' => 1234567, // Required. Project id 'eventId' => 1234567, // Required. Event id ) );
单元测试覆盖率
以下服务操作尚未(尚未)由单元测试覆盖
- updateTodo
- grantAccess
- updateCalendar
- deleteCalendar
- updateCalendarEvent
- deleteCalendarEvent
- updateProjectCalendarEvent
- deleteProjectCalendarEvent