apility/netflex-calendar-sync

此包最新版本(v1.0.0)没有可用的许可信息。

与Netflex结构同步日历

v1.0.0 2019-05-20 12:57 UTC

This package is auto-updated.

Last update: 2024-09-21 01:49:55 UTC


README

这是一个简单的库,用于从提供者到Netflex结构的单向同步。

安装

使用Composer包含仓库。

  $ composer require apility/netflex-calendar-sync

日历

Google Calendar

为了抓取日历,在Google云端平台 这里 创建一个API密钥。这是一个通用API密钥,并非特定于Google Calendar。通过同一控制台启用对Google Calendar API的访问。

打开您的日历应用, (Google Calendar) 并进入该日历的设置部分。

找到日历的ID

并使日历公开。

创建一个类似这样的日历实例;

/*
  First option is the calendar ID.
  Second option is the API key, 
  Third option is an associative array of key values found in the Google API documentation
*/
$calendar = new GoogleCalendar($openingHourEntry->calendarId, \get_setting("google_calendar_sync_api_key"), [
  'singleEvents' => true,
]);

Google API探索器/文档

日历中的条目可以作为Laravel Collection访问。

$openingHours = $calendar
  ->map(function($event) {
    return [
      "eventId" => $event->id,
      "name" => "Åpningstid",
      "start" => Carbon::parse($event->start->dateTime)->format(DateTime::ISO8601),
      "end" => Carbon::parse($event->end->dateTime)->format(DateTime::ISO8601),
      "allDay" => false,
    ];
  });

解析器

解析器是将解析后的对象立即转移到Netflex的方法。

条目同步解析器

条目解析器接受任何 Netflex\Structure 对象,并允许您将其注入任何可序列化为JSON的数据。(例如Laravel Collection)。

$resolver = new EntrySync(Models\Calendar::find(10000));
$resolver->syncData($openingHours);