PHP code example of juanparati / inmobile

1. Go to this page and download the library: Download juanparati/inmobile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juanparati / inmobile example snippets

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

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

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

InMobile::lists()->create('My new 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());

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


// 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')
);

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';
}

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

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