承接 lobrs/calendly-sdk-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lobrs/calendly-sdk-php

最新稳定版本:0.2.13

Composer 安装命令:

composer require lobrs/calendly-sdk-php

包简介

Calendly API SDK PHP

README 文档

README

PHP implementation of Calendly API (v2).

Installation

composer require lobrs/calendly-sdk-php

Usage

\LoBrs\Calendly\Calendly::setToken($token);
$currentUser = \LoBrs\Calendly\Calendly::me();

Get user from UUID

$user = \LoBrs\Calendly\Models\User::get($uuid);

Get model list

Returns an array of objects from the model class.

// List scheduled events from a user
$scheduled_events = \Calendly\Models\Event::getList([
    "user" => $user->uri
]);
// List busy times from a user
$busy_times = \Calendly\Models\UserBusyTime::getList([
    "user"          => $user->uri,
    "start_time"    => date(DateTime::ATOM, strtotime("+1 minute")),
    "end_time"      => date(DateTime::ATOM, strtotime("+7 days")),
]);

You can also use paginate($options) method, returning a PaginatedList.

$result = \Calendly\Models\Event::paginate([
    "user" => $user->uri
]);

echo $result->countResults() . " results \n";
echo $result->getNextPageURL();

// Request next page with the same options.
$next_page_results = $result->next();

Refer to the Calendly API documentation to find requests options.

Currently supported models

Models Get uuid Paginate Create Delete
Event
EventType
EventTypeAvailableTime
Guest
Invitee
Organization
OrganizationInvitation
OrganizationMembership
Profile
RoutingForm
RoutingFormSubmission
SchedulingLink
User
UserAvailabilitySchedule
UserBusyTime
WebhookSubscription

Direct API request usage

You can directly call the API using Calendly::request($uri, "GET", $params), which returns the body of the response.

Webhooks

You can use WebhookSubscription Model directly to manage your Webhooks methods getList, get, create and delete.

Webhook subscription

We provide the subscribe helper method to add a new webhook.

The 3rd parameter can be a $uuid referencing a user or organization uuid or an array of options.

\LoBrs\Calendly\Webhooks\Webhook::subscribe("https://example.com/my-webhook", [
    'invitee.created'
], [
    'user' => 'user_abc123',
    'organization' => 'organization_abc123',
    'scope' => 'organization',
], 'my-webhook-secret-key');

To improve security, you can sign your webhooks by providing the webhook secret key parameter.

Webhook payload example

$payload = @file_get_contents('php://input');
$header = $_SERVER['HTTP_CALENDLY_WEBHOOK_SIGNATURE'];
try {
    $webhook = Webhook::readEvent($payload, $header, 'my-webhook-secret-key');
} catch (WebhookExpiredResponseException|WebhookSignatureException $e) {}

OAuth

This package comes with an OAuth2 CLient, using ThePhpLeague OAuth2 Client

Usage flow

$provider = new CalendlyOAuthProvider([
    "clientId"     => env('CALENDLY_CLIENT'),
    "clientSecret" => env('CALENDLY_OAUTH_SECRET'),
    'redirectUri'  => env('CALENDLY_REDIRECT_URI'),
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();

    header('Location: ' . $authUrl);
    exit;

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code'],
    ]);

    try {
        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        print_r($user->toArray());

    } catch (Exception $e) {
        exit('Failed to get user details');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}

统计信息

  • 总下载量: 23.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-18