本文整理汇总了PHP中Rest::postJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP Rest::postJSON方法的具体用法?PHP Rest::postJSON怎么用?PHP Rest::postJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rest
的用法示例。
在下文中一共展示了Rest::postJSON方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sync
public static function sync($source, $destination, $syncTaskId = 0)
{
// Stats
$stats = array('links' => 0);
// Get source data
$links = BackupsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['link']))->toArray();
$syncedLinks = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'destination_id' => $destination['username']['id'], 'kind' => static::$kind['link']))->column('identifier');
if ($links) {
foreach ($links as $link) {
if (!in_array($link['entity_id'], $syncedLinks)) {
$link['entity'] = json_decode($link['entity'], true);
$newLink = array_diff_key($link['entity'], array_flip(static::$skip['link']));
$newLink = \Rest::postJSON(static::$endpoints['link'], $newLink, $destination);
if (isset($newLink['result']['error'])) {
d($newLink);
}
$stats['links']++;
$syncedCalendar = MigratedDataModel::create();
$syncedCalendar->source_id = $source['username']['id'];
$syncedCalendar->destination_id = $destination['username']['id'];
$syncedCalendar->kind = static::$kind['link'];
$syncedCalendar->identifier = $link['entity_id'];
$syncedCalendar->created = date(DATE_TIME);
$syncedCalendar->save();
}
}
}
return $stats;
}
示例2: _transfer
public static function _transfer($source, $destination, $syncTaskId = 0, $ignoreUpdate = false, $whitelist = array())
{
// Stats
$stats = array('calendars' => 0, 'events' => 0);
// Get source data
$calendars = CalendarsModel::withEvents($source['username']['id'], $syncTaskId);
$destinationCalendars = CalendarsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId))->toArray();
$destinationNames = static::_getColumn($destinationCalendars, 'name');
$syncedEvents = EventsModel::identifiers(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId));
if ($calendars) {
foreach ($calendars as $calendar) {
// Create calendar
$payload = array();
// Whitelisting used for share feature
$whiteListed = true;
if ($whitelist) {
if (isset($whitelist['calendars']) && $whitelist['calendars']) {
if (!in_array($calendar['calendar_id'], $whitelist['calendars'])) {
$whiteListed = false;
}
}
}
// New
if (!in_array($calendar['name'], array_keys($destinationNames)) && $whiteListed || $whiteListed && $ignoreUpdate) {
// Create Calendar
$payload['summary'] = $calendar['name'];
$newCalendar = \Rest::postJSON(static::$endpoints['calendar'], $payload, $destination);
$stats['calendars']++;
if (isset($newCalendar['result']['error'])) {
d($newCalendar);
}
// Create Calendar List
$payloadList = array();
$payloadList['id'] = $newCalendar['id'];
$payloadList['timezone'] = $calendar['timezone'];
$payloadList['colorId'] = $calendar['color_id'];
$payloadList['backgroundColor'] = $calendar['background'];
$payloadList['foregroundColor'] = $calendar['foreground'];
$payloadList['selected'] = true;
\Rest::postJSON(static::$endpoints['calendars'], $payloadList, $destination);
$syncedCalendar = MigratedDataModel::create();
$syncedCalendar->source_id = $source['username']['id'];
$syncedCalendar->destination_id = $destination['username']['id'];
$syncedCalendar->task_id = 0;
$syncedCalendar->sync_task_id = $syncTaskId;
$syncedCalendar->table = CalendarsModel::$schema['table'];
$syncedCalendar->table_id = $calendar['id'];
$syncedCalendar->kind = static::$kind['calendar'];
$syncedCalendar->identifier = $calendar['calendar_id'];
$syncedCalendar->name = $calendar['name'];
$syncedCalendar->status = MigratedDataModel::STATUS_ACTIVE;
$syncedCalendar->created = date(DATE_TIME);
$syncedCalendar->save();
// Update calendar with new id
if (!$ignoreUpdate) {
$oldCalendar = CalendarsModel::first($calendar['id']);
$oldCalendar->calendar_new_id = $newCalendar['id'];
$oldCalendar->save();
}
// Existing
} else {
$cal = CalendarsModel::first(array('user_id' => $destination['username']['id'], 'name' => $calendar['name']))->toArray();
$newCalendar['id'] = $cal['calendar_id'];
}
// Add events
if ($calendar['events']) {
foreach ($calendar['events'] as $event) {
$combination = static::identifier($event, $calendar);
// Whitelisting used for share feature
$whiteListed = true;
if ($whitelist) {
if (isset($whitelist['calendars']) && $whitelist['calendars']) {
if (!in_array($event['google_calendar_id'], $whitelist['calendars'])) {
$whiteListed = false;
}
}
}
if (!in_array($combination, $syncedEvents) && $whiteListed || $whiteListed && $ignoreUpdate) {
// Create Event
$payload = array();
$payload['summary'] = $event['name'];
$payload['description'] = $event['description'];
$payload['location'] = $event['location'];
$payload['status'] = $event['event_status'];
if ($event['color_id']) {
$payload['colorId'] = $event['color_id'];
}
$payload['creator'] = json_decode($event['creator'], true);
$payload['start'] = json_decode($event['start'], true);
$payload['end'] = json_decode($event['end'], true);
if (json_decode($event['recurrence'], true)) {
$payload['recurrence'] = json_decode($event['recurrence'], true);
}
$newEvent = \Rest::postJSON(sprintf(static::$endpoints['events'], $newCalendar['id']), $payload, $destination);
if (isset($newEvent['result']['error'])) {
d($newEvent);
}
$stats['events']++;
$syncedEvent = MigratedDataModel::create();
$syncedEvent->source_id = $source['username']['id'];
//.........这里部分代码省略.........
示例3: _transfer
public static function _transfer($source, $destination, $syncTaskId = 0, $ignoreUpdate = false, $whitelist = array())
{
// Stats
$stats = array('lists' => 0, 'tasks' => 0);
// Get source data
$tasks = array();
$lists = BackupsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['list']))->toArray();
$tasksDB = BackupsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['task']))->toArray();
if ($tasksDB) {
foreach ($tasksDB as $task) {
$tasks[$task['parent_id']][] = $task;
}
}
$syncedLists = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'destination_id' => $destination['username']['id'], 'kind' => static::$kind['list']))->column('identifier');
$syncedTasks = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'destination_id' => $destination['username']['id'], 'kind' => static::$kind['task']))->column('identifier');
$destinationLists = BackupsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['list']))->column('entity_title');
if ($lists) {
foreach ($lists as $list) {
// Whitelisting used for share feature
$whiteListed = true;
if ($whitelist) {
if (isset($whitelist['lists']) && $whitelist['lists']) {
if (!in_array($list['entity_id'], $whitelist['lists'])) {
$whiteListed = false;
}
}
}
if (!in_array($list['entity_id'], $syncedLists) && $whiteListed) {
$list['entity'] = json_decode($list['entity'], true);
$newList = array_diff_key($list['entity'], array_flip(static::$skip['list']));
if (in_array($newList['title'], $destinationLists) && !$ignoreUpdate) {
$newList['title'] = $newList['title'] . ' (2)';
} else {
$newList['title'] = $newList['title'];
}
$newList = \Rest::postJSON(static::$endpoints['lists'], $newList, $destination);
if (isset($newList['result']['error'])) {
d($newList);
}
$stats['lists']++;
// Update playlist with new id
if (!$ignoreUpdate && $newList) {
$oldPlaylist = BackupsModel::first($list['id']);
$oldPlaylist->entity_new_id = $newList['id'];
$oldPlaylist->save();
}
$syncedCalendar = MigratedDataModel::create();
$syncedCalendar->source_id = $source['username']['id'];
$syncedCalendar->destination_id = $destination['username']['id'];
$syncedCalendar->task_id = 0;
$syncedCalendar->sync_task_id = $syncTaskId;
$syncedCalendar->table = BackupsModel::$schema['table'];
$syncedCalendar->table_id = $list['id'];
$syncedCalendar->kind = static::$kind['list'];
$syncedCalendar->identifier = $list['entity_id'];
$syncedCalendar->status = MigratedDataModel::STATUS_ACTIVE;
$syncedCalendar->created = date(DATE_TIME);
$syncedCalendar->save();
// Add tasks
if (isset($tasks[$list['id']])) {
foreach ($tasks[$list['id']] as $task) {
if (!in_array($task['entity_id'], $syncedTasks)) {
$task['entity'] = json_decode($task['entity'], true);
$newTask = array_diff_key($task['entity'], array_flip(static::$skip['task']));
$newTask = \Rest::postJSON(sprintf(static::$endpoints['tasks'], $newList['id']), $newTask, $destination);
if (isset($newTask['result']['error'])) {
d($newTask);
}
$stats['tasks']++;
$syncedEvent = MigratedDataModel::create();
$syncedEvent->source_id = $source['username']['id'];
$syncedEvent->destination_id = $destination['username']['id'];
$syncedEvent->task_id = 0;
$syncedEvent->sync_task_id = $syncTaskId;
$syncedEvent->table = BackupsModel::$schema['table'];
$syncedEvent->table_id = $task['id'];
$syncedEvent->kind = static::$kind['task'];
$syncedEvent->identifier = $task['entity_id'];
$syncedEvent->status = MigratedDataModel::STATUS_ACTIVE;
$syncedEvent->created = date(DATE_TIME);
$syncedEvent->save();
}
}
}
}
}
}
return $stats;
}
示例4: _transfer
public static function _transfer($source, $destination, $syncTaskId = 0, $ignoreUpdate = false, $whitelist = array())
{
// Stats
$stats = array('playlists' => 0, 'videos' => 0, 'subscriptions' => 0);
// Get source data
$playlists = PlaylistsModel::withVideos($source['username']['id'], $syncTaskId);
$destinationPlaylists = PlaylistsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId))->toArray();
$destinationNames = static::_getColumn($destinationPlaylists, 'title');
$subscriptions = SubscriptionsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId))->toArray();
$syncedVideos = VideosModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId))->column('video_link');
$syncedSubscriptions = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'destination_id' => $destination['username']['id'], 'kind' => static::$kind['subscription'], 'status' => MigratedDataModel::STATUS_ACTIVE))->column('identifier');
$counter = 0;
$batches = array();
$batch = md5(time());
// Add data to destionation Youtube
if ($playlists) {
foreach ($playlists as $playlist) {
if (intVal($playlist['videos_count']) > 0) {
if ($counter == 998) {
$batch = md5(time());
$counter = 0;
}
// Create Playlist
$payload = array();
$payload['status']['privacyStatus'] = 'private';
// Whitelisting used for share feature
$whiteListed = true;
if ($whitelist) {
if (isset($whitelist['playlists']) && $whitelist['playlists']) {
if (!in_array($playlist['youtube_playlist_id'], $whitelist['playlists'])) {
$whiteListed = false;
}
}
}
// New
if (!in_array($playlist['title'], array_keys($destinationNames)) && $whiteListed || $ignoreUpdate) {
// Create Playlist
$payload['snippet']['title'] = $playlist['title'];
$newPlaylist = \Rest::postJSON(static::$endpoints['playlists'] . '?part=status,snippet', $payload, $destination);
$stats['playlists']++;
if (isset($newPlaylist['result']['error'])) {
d($newPlaylist);
}
$syncPlaylist = MigratedDataModel::create();
$syncPlaylist->source_id = $source['username']['id'];
$syncPlaylist->destination_id = $destination['username']['id'];
$syncPlaylist->task_id = 0;
$syncPlaylist->sync_task_id = $syncTaskId;
$syncPlaylist->table = PlaylistsModel::$schema['table'];
$syncPlaylist->table_id = $playlist['id'];
$syncPlaylist->kind = static::$kind['playlist'];
$syncPlaylist->identifier = $playlist['youtube_playlist_id'];
$syncPlaylist->name = $playlist['title'];
$syncPlaylist->created = date(DATE_TIME);
$syncPlaylist->status = MigratedDataModel::STATUS_ACTIVE;
$syncPlaylist->save();
// Update playlist with new id
if (!$ignoreUpdate) {
$oldPlaylist = PlaylistsModel::first($playlist['id']);
$oldPlaylist->new_youtube_id = $newPlaylist['id'];
$oldPlaylist->save();
}
// Existing
} else {
$play = PlaylistsModel::first(array('user_id' => $destination['username']['id'], 'title' => $playlist['title']))->toArray();
$newPlaylist['id'] = $play['youtube_playlist_id'];
}
$counter++;
// Add videos
if ($playlist['videos']) {
foreach ($playlist['videos'] as $k => $video) {
if (!in_array($video['video_link'], $syncedVideos) || $ignoreUpdate) {
if ($counter == 998) {
$batch = md5(time());
$counter = 0;
}
$counter++;
$payload = array();
$payload['snippet']['playlistId'] = $newPlaylist['id'];
$payload['snippet']['resourceId']['kind'] = static::$kind['video'];
$payload['snippet']['resourceId']['videoId'] = $video['video_link'];
$payload = json_encode($payload);
$batches[$batch][$newPlaylist['id']][] = <<<EOD
POST https://www.googleapis.com/youtube/v3/playlistItems?part=snippet
Content-Type: application/json
Authorization: Bearer {$destination['credentials']['access_token']}
{$payload}
EOD;
$stats['videos']++;
$syncPlaylist = MigratedDataModel::create();
$syncPlaylist->source_id = $source['username']['id'];
$syncPlaylist->destination_id = $destination['username']['id'];
$syncPlaylist->task_id = 0;
$syncPlaylist->sync_task_id = $syncTaskId;
$syncPlaylist->table = VideosModel::$schema['table'];
$syncPlaylist->table_id = $video['id'];
$syncPlaylist->kind = static::$kind['video'];
//.........这里部分代码省略.........