activix/nylas-php

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP wrapper for the Nylas API (Adapted for Activix).

Maintainers

Details

github.com/activix/nylas-php

Source

Installs: 87 817

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 26

2.0.7 2023-06-13 15:00 UTC

This package is auto-updated.

Last update: 2023-10-13 15:50:23 UTC


README

Forked from nylas/nylas-php. Adapted for Activix.

PHP bindings for the Nylas REST API https://www.nylas.com.

Installation

You can install the library by running:

cd nylas-php
composer install

Usage

The Nylas REST API uses server-side (three-legged) OAuth, and this library provides convenience methods to simplify the OAuth process. Here's how it works:

  1. You redirect the user to our login page, along with your App Id and Secret
  2. Your user logs in
  3. She is redirected to a callback URL of your own, along with an access code
  4. You use this access code to get an authorization token to the API

For more information about authenticating with Nylas, visit the Developer Documentation.

In practice, the Nylas REST API client simplifies this down to two steps.

Fetching Account Information

$client = new Nylas(CLIENT, SECRET, TOKEN);
$account = $client->account();

echo $account->email_address;
echo $account->provider;

Fetching Threads

$client = new Nylas(CLIENT, SECRET, TOKEN);

// Fetch the first thread
$firstThread = $client->threads()->first();
echo $firstThread->id;

// Fetch first 2 latest threads
$twoThreads = $client->threads()->all(2);

foreach ($twoThreads as $thread) {
    echo $thread->id;
}

// List all threads with 'ben@nylas.com'
$searchCriteria = ['any_email' => 'ben@nylas.com'];
$getThreads = $client->threads()->where($searchCriteria)->items();

foreach ($getThreads as $thread) {
    echo $thread->id;
}

Working with Threads

// List thread participants
foreach ($thread->participants as $participant) {
    echo $participant->email;
    echo $participant->name;
}

// Mark as Read
$thread->markAsRead();

// Mark as Seen
$thread->markAsSeen();

// Archive
$thread->archive();

// Unarchive
$thread->unarchive();

// Trash
$thread->trash();

// Star
$thread->star();

// Unstar
$thread->unstar();

// Add or remove arbitrary tags
$toAdd = ['cfa1233ef123acd12'];
$toRemove = ['inbox'];
$thread->addTags($toAdd);
$thread->removeTags($toRemove);

// Listing messages
foreach ($thread->messages()->items() as $message) {
    echo $message->subject;
    echo $message->body;
}

Working with Files

$client = new Nylas(CLIENT, SECRET, TOKEN);

$filePath = '/var/my/folder/test_file.pdf';
$uploadResp = $client->files()->create($filePath);
echo $uploadResp->id;

Working with Drafts

$client = new Nylas(CLIENT, SECRET, TOKEN);

$personObj = new \Nylas\Models\Person('Kartik Talwar', 'kartik@nylas.com');

$messageObj = [
    'to' => [$personObj],
    'subject' => 'Hello, PHP!',
    'body' => 'Test <br> message'
];

$draft = $client->drafts()->create($messageObj);
$sendMessage = $draft->send();
echo $sendMessage->id;

Working with Events

$client = new Nylas(CLIENT, SECRET, TOKEN);
$calendars = $client->calendars()->all();
$calendar = null;

foreach ($calendars as $i) {
    if (!$i->read_only) {
        $calendar = $i;
    }
}

$personObj = new \Nylas\Models\Person('Kartik Talwar', 'kartik@nylas.com');

$calendarObj = [
    'title' => 'Important Meeting',
    'location' => 'Nylas HQ',
    'participants' => [$personObj],
    'calendar_id' => $calendar->id,
    'when' => [
        'start_time' => time(),
        'end_time' => time() + (30 * 60),
    ],
];

// Create event
$event = $client->events()->create($calendarObj);
echo $event->id;

// Update
$event = $event->update(['location' => 'Meeting room #1']);

// Delete event
$event->delete();

// Delete event (alternate)
$remove = $client->events()->find($event->id)->delete();