juanparati/inmobile

InMobile client for Laravel

1.2 2024-10-23 14:19 UTC

This package is auto-updated.

Last update: 2024-10-24 06:19:24 UTC


README

InMobile library for Laravel.

Installation

composer require juanparati/inmobile

Configuration

Publish configuration file:

artisan vendor:publish --tag="inmobile"

Usage examples

List service

Create list

InMobile::lists()->create('My list');

Get all lists

// Return a paginated results instance.
$lists = InMobile::lists()->all();

// Will automatically transverse all the pages automatically.
// Rewind is not allowed.
foreach ($lists as $list)
    var_dump($list->toArray());

Get a list

InMobile::lists()->find($myListId);

Create a list

InMobile::lists()->create('My new list');

Get all recipients in list

$recipients = InMobile::lists()->getRecipients($myListId);

// Will automatically transverse all the pages automatically.
// Rewind is not allowed.
foreach ($recipients as $recipient)
    var_dump($recipient->toArray());

Other methods

  • update
  • delete
  • truncate

Recipient service

Create recipient

$recipient = InMobile::recipients()->create(
    $listId, 
    \Juanparati\InMobile\Models\Recipient::make('45', '12345678')
        ->addField('firstname', 'John')
        ->addField('lastname', 'Random')
        ->addField('custom1', 'foobar')
        ->setCreatedAt(now()->subMinute())
);

echo 'Recipient id: ' . $recipient->getId();

Update recipient

// Only update some fields
InMobile::recipients()->updateById(
    $listId,
    $recipientId, 
    \Juanparati\InMobile\Models\Recipient::make()
        ->addField('firstname', 'John')
        ->addField('lastname', 'Random')
        ->addField('custom1', 'foobar'),       
    false   // Indicate that only values set are updated (Default)
);

// Full update
InMobile::recipients()->updateById(
    $listId,
    $recipientId, 
    \Juanparati\InMobile\Models\Recipient::make('35', '12345678')
        ->addField('firstname', 'John')
        ->addField('lastname', 'Random')
        ->addField('custom1', 'foobar')
        ->setCreatedAt(now())
        ,       
    true   // Indicate that all fields are update, the fields missing in the recipient model are emptied
);

// or use updateByNumber instead (It's slower than updateById because it has to lookup for the recipient Id)
InMobile::recipients()->updateByNumber(
    $listId,
    $prefix,
    $number,
     \Juanparati\InMobile\Models\Recipient::make()
        ->addField('firstname', 'John')
        ->addField('lastname', 'Random')
        ->addField('custom1', 'foobar')
);

Find recipient by Id

if ($recipient = InMobile::recipients()->findById('listid', 'recipientId')) {
    echo 'Recipient ' . $recipient->getId() . ' has phone +' . $recipient->getCode() . ' ' . $recipient->getPhone(); 
    var_dump($recipient->toArray());
} else {
    echo 'Recipient not found';
}

Find recipient

// Search by phone number
$recipient = InMobile::recipients()->findByNumber('listid', '45', '12345678');

// or search by recipient id
$recipient = InMobile::recipients()->findById('listid', 'recipientId');

Other methods

  • deleteById
  • deleteByNumber
  • updateOrCreateByNumber
  • moveToList

Blacklist service

Methods

  • all
  • create
  • findById
  • findByNumber
  • deleteById
  • deleteByNumber

Email service

Methods

  • send
  • sendTemplate

Email template service

Methods

  • all
  • find

Gdpr service

  • create

Sms service

Methods

  • send
  • sendUsingTemplate
  • cancel
  • status