2017 © Pedro Peláez
 

library nylas-php

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

image

activix/nylas-php

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

  • Wednesday, July 26, 2017
  • by PhilippeTellier
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,604 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 3 Versions
  • 19 % Grown

The README.md

Nylas PHP

Forked from nylas/nylas-php. Adapted for Activix., (*1)

PHP bindings for the Nylas REST API https://www.nylas.com., (*2)

Installation

You can install the library by running:, (*3)

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:, (*4)

  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., (*5)

In practice, the Nylas REST API client simplifies this down to two steps., (*6)

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();

The Versions

26/07 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

by Philippe Tellier
by Kartik Talwar

26/07 2017

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

 

by Philippe Tellier
by Kartik Talwar

19/01 2017

0.26

0.26.0.0

PHP wrapper for the Nylas API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Kartik Talwar