Code Monkey home page Code Monkey logo

mogreet-php's Introduction

Introduction

This is a PHP wrapper for the Mogreet API. Tests and a solution to install the wrapper using a package manager are coming soon.

Installation

For now, you can use mogreet-php only by checking out this repo. Others methods will be added later.

First clone the git repo:

git clone https://github.com/jperichon/mogreet-php.git

Then include the Client:

require_once('/path/to/mogreet-php/Mogreet.php');

Usage examples

Create a client

require_once('/path/to/mogreet-php/Mogreet.php');

$clientId = 'xxxxx' // Your Client ID from https://developer.mogreet.com/dashboard
$token = 'xxxxx' // Your token from https://developer.mogreet.com/dashboard
$client = new Mogreet($clientId, $token);

Ping

$response = $client->system->ping();
print $response->message;

Send an SMS to one recipient

$response = $client->transaction->send(array(
    'campaign_id' => 'xxxxx', // Your SMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'This is super easy!'
));
print $response->messageId;

Send an MMS to one recipient

$response = $client->transaction->send(array(
    'campaign_id' => 'xxxxx', // Your MMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'This is super easy!',
    'content_url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
print $response->messageId;

Upload a media file

$response = $client->media->upload(array(
    'type' => 'image',
    'name' => 'mogreet logo',
    'file' => '/path/to/image/mogreet.png',
    // to ingest a file already online, use: 'url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
print $response->media->smartUrl;
print '<br/>';
print $response->media->contentId;

List all medias

$response = $client->media->listAll();
foreach($response->mediaList as $media) {
    print $media->contentId . ' => ' . $media->name . ' ' . $media->smartUrl . '<br />';
}

Notes

With the Response object, you can print the plain JSON response of the API call (print $response), or access directly a field (e.g: $response->message).

Due to the keyword restriction on 'list' and the existing function 'empty()' in PHP, I changed the mappings of the following API calls:

  • $client->*->listAll() maps to the method list
  • $client->list->pruneAll() maps to 'list.empty'

The full documentation for the Mogreet API is available here

Prerequisites

  • PHP >= 5.4
  • The PHP JSON extension

mogreet-php's People

Contributors

jperichon avatar

Stargazers

Aimee avatar Brian Barthold avatar Paul Forsyth avatar

Watchers

 avatar Alin Mazilu avatar James Cloos avatar

Forkers

mopo922 impeto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.