From 47de44caba1ed3dbac212c914eeabe502f5a9aca Mon Sep 17 00:00:00 2001 From: Emil Huseynaliev Date: Fri, 5 Jun 2015 14:26:45 -0400 Subject: [PATCH] Initial code commit Updates readme --- .gitignore | 2 + README.md | 94 +++- composer.json | 27 ++ composer.lock | 976 +++++++++++++++++++++++++++++++++++++++ src/AttachmentUtils.php | 37 ++ src/Client.php | 299 ++++++++++++ src/EmojiUtils.php | 449 ++++++++++++++++++ tests/EmojiUtilsTest.php | 57 +++ 8 files changed, 1939 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 src/AttachmentUtils.php create mode 100644 src/Client.php create mode 100644 src/EmojiUtils.php create mode 100644 tests/EmojiUtilsTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..180ac16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +nbproject/ +vendor/ diff --git a/README.md b/README.md index 78e1cc5..fbc9f9a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,92 @@ -# groupme-api-client -A PHP wrapper for the GroupMe API +# GroupMe API Client +This library is an unofficial PHP wrapper for the [GroupMe v3 API](https://dev.groupme.com/). + +### Installation +Install using Composer: +`"emilh91/groupme-api-client": "dev-master"` + +### Boilerplate +Your GroupMe API key can be found on the page mentioned above once you are logged in. +```php +require 'vendor/autoload.php'; +$c = new GroupMeApiClient\Client('API-KEY'); +``` + +### Client methods +All the methods in the following sub-sections should be invoked on the newly created client object. + +##### Bot methods +```php +public function getMyBots() +public function createBot($bot_name, $group_id, $avatar_url='', $callback_url='') +public function sendBotMessage($bot_id, $text, array $attachments=array()) +public function destroyBot($bot_id) +``` + +##### Direct Message methods +```php +public function getDirectMessageChats($page=1, $per_page=10) +public function getLatestDirectMessages($other_user_id, $limit=20) +public function getDirectMessagesBefore($other_user_id, $message_id) +public function getDirectMessagesSince($other_user_id, $message_id) +public function sendDirectMessage($other_user_id, $text, $source_guid=null, array $attachments=array()) +public function likeDirectMessage($other_user_id, $message_id) +public function unlikeDirectMessage($other_user_id, $message_id) +``` + +##### Group methods +```php +public function getAllGroups($page=1, $per_page=10) +public function getFormerGroups() +public function createGroup($name, $description='', $image_url='', $share=false) +public function getGroupDetails($group_id) +public function updateGroupDetails($group_id, array $payload) +public function destroyGroup($group_id) +public function joinGroup($group_id, $share_token) +public function rejoinGroup($group_id) +public function getLeaderboard($group_id, $period='day') +public function getLeaderboardForDay($group_id) +public function getLeaderboardForWeek($group_id) +public function getLeaderboardForMonth($group_id) +public function getMyLikes($group_id) +public function getMyHits($group_id) +public function addMembersToGroup($group_id, array $members) +public function updateMyGroupMembership($group_id, $nickname) +public function getGroupMembers($group_id, $results_id) +public function removeGroupMember($group_id, $user_id) +public function getLatestGroupMessages($group_id, $limit=20) +public function getGroupMessagesBefore($group_id, $message_id, $limit=20) +public function getGroupMessagesAfter($group_id, $message_id, $limit=20) +public function getGroupMessagesSince($group_id, $message_id, $limit=20) +public function sendGroupMessage($group_id, $text, $source_guid=null, array $attachments=array()) +``` + +##### User methods +```php +public function getMyDetails() +public function updateMyDetails(array $payload) +public function enableSmsMode($duration, $registration_id) +public function disableSmsMode() +``` + +### Attachments +When sending messages (bot, direct, or group), you can specify an array of attachments. A factory class exists to easily create attachments: `GroupMeApiClient\AttachmentUtils`. +```php +public static function makeLocationAttachment($lat, $lng, $name='') +public static function makeImageAttachment($image_url) +public static function makeSplitAttachment() +public static function makeEmojiAttachment(array $charmap) +``` + +### Emojis +Aah, the pinnacle of modern communication... To send emojis in GroupMe, you need to specify a charmap (character map) when creating the attachment. For this purpose, another factory class exists: `GroupMeApiClient\EmojiUtils`. + +```php +$raw_text = 'Hello :cool_guy_face::cigar_face:'; +$emojification = GroupMeApiClient\EmojiUtils::extractEmojiNamesFromText($raw_text); // returns an array +$emoji_attachment = GroupMeApiClient\AttachmentUtils::makeEmojiAttachment($emojification['charmap']); +$c->sendDirectMessage('OTHER-USER-ID', $emojification['text'], null, array($emoji_attachment)); +``` + +### Image Service +This functionality is still buggy. Check back again later. Sorry :( \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f511adf --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "emilh91/groupme-api-client", + "type": "library", + "description": "GroupMe API Client", + "keywords": ["groupme", "api", "client", "wrapper"], + "homepage": "https://github.com/emilh91/groupme-api-client", + "license": "MIT", + "authors": [ + { + "name": "Emil Huseynaliev", + "email": "admin@emilh.net", + "homepage": "https://emilh.net", + "role": "Developer" + } + ], + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "4.6.10" + }, + "autoload": { + "psr-4": { + "GroupMeApiClient\\": "src" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..e30d908 --- /dev/null +++ b/composer.lock @@ -0,0 +1,976 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "f3072e78b4c914e69ae279ce57ce5fb7", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "28a6b34e91d789b2608072ab3c82eaae7cdb973c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/28a6b34e91d789b2608072ab3c82eaae7cdb973c", + "reference": "28a6b34e91d789b2608072ab3c82eaae7cdb973c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-06-03 07:01:01" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "eab81d02569310739373308137284e0158424330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", + "reference": "eab81d02569310739373308137284e0158424330", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-04-08 04:46:07" + }, + { + "name": "phpunit/phpunit", + "version": "4.6.10", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "7b5fe98b28302a8b25693b2298bca74463336975" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7b5fe98b28302a8b25693b2298bca74463336975", + "reference": "7b5fe98b28302a8b25693b2298bca74463336975", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.0,>=2.0.11", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.6.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-06-03 05:03:30" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/253c005852591fd547fc18cd5b7b43a1ec82d8f7", + "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-05-29 05:19:18" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "symfony/yaml", + "version": "v2.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/4a29a5248aed4fb45f626a7bbbd330291492f5c3", + "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-05-02 15:21:08" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.0" + }, + "platform-dev": [] +} diff --git a/src/AttachmentUtils.php b/src/AttachmentUtils.php new file mode 100644 index 0000000..43fee6c --- /dev/null +++ b/src/AttachmentUtils.php @@ -0,0 +1,37 @@ + 'location', + 'lat' => "$lat", + 'lng' => "$lng", + 'name' => "$name", + ); + } + + public static function makeImageAttachment($image_url) { + return array( + 'type' => 'image', + 'url' => $image_url, + ); + } + + public static function makeSplitAttachment() { + return array( + 'type' => 'split', + 'token' => 'SPLIT_TOKEN', + ); + } + + public static function makeEmojiAttachment(array $charmap) { + return array( + 'type' => 'emoji', + 'placeholder' => EmojiUtils::PLACEHOLDER, + 'charmap' => $charmap, + ); + } +} diff --git a/src/Client.php b/src/Client.php new file mode 100644 index 0000000..cbd983c --- /dev/null +++ b/src/Client.php @@ -0,0 +1,299 @@ +token = $token; + } + + // Image Service methods + public function uploadImage($image_url) { + $payload = array('file' => $image_url); + return $this->request('POST', '/pictures', array(), $payload, true); + } + + // Bot methods + public function getMyBots() { + return $this->get('/bots'); + } + + public function createBot($bot_name, $group_id, $avatar_url='', $callback_url='') { + $bot_info = array( + 'name' => $bot_name, + 'group_id' => $group_id, + 'avatar_url' => $avatar_url, + 'callback_url' => $callback_url + ); + $payload = array('bot' => $bot_info); + return $this->post('/bots', $payload); + } + + public function sendBotMessage($bot_id, $text, array $attachments=array()) { + $payload = array( + 'bot_id' => $bot_id, + 'text' => $text, + 'attachments' => $attachments + ); + return $this->post('/bots/post', $payload); + } + + public function destroyBot($bot_id) { + $payload = array('bot_id' => $bot_id); + return $this->post('/bots/destroy', $payload); + } + + // Direct Message methods + public function getOtherUserIdFromConversationId($conversation_id) { + $my_details = $this->getMyDetails(); + $my_user_id = $my_details['response']['id']; + $user_ids = explode('+', $conversation_id); + return $my_user_id==$user_ids[0] ? $user_ids[1] : $user_ids[0]; + } + + public function getConversationIdFromOtherUserId($other_user_id) { + $my_details = $this->getMyDetails(); + $my_user_id = intval($my_details['response']['id']); + $o_user_id = intval($other_user_id); + return min($my_user_id,$o_user_id) . '+' . max($my_user_id,$o_user_id); + } + + public function getDirectMessageChats($page=1, $per_page=10) { + $query = array( + 'page' => $page, + 'per_page' => $per_page + ); + return $this->get('/chats', $query); + } + + public function getLatestDirectMessages($other_user_id, $limit=20) { + $query = array( + 'other_user_id' => $other_user_id, + 'limit' => $limit + ); + return $this->get('/direct_messages', $query); + } + + public function getDirectMessagesBefore($other_user_id, $message_id) { + $query = array( + 'other_user_id' => $other_user_id, + 'before_id' => $message_id + ); + return $this->get('/direct_messages', $query); + } + + public function getDirectMessagesSince($other_user_id, $message_id) { + $query = array( + 'other_user_id' => $other_user_id, + 'since_id' => $message_id + ); + return $this->get('/direct_messages', $query); + } + + public function sendDirectMessage($other_user_id, $text, $source_guid=null, array $attachments=array()) { + $message_info = array( + 'recipient_id' => $other_user_id, + 'text' => $text, + 'source_guid' => $source_guid ?: "D$other_user_id-". date('YmdHis-') . uniqid(), + 'attachments' => $attachments + ); + $payload = array('direct_message' => $message_info); + return $this->post('/direct_messages', $payload); + } + + public function likeDirectMessage($other_user_id, $message_id) { + $conversation_id = $this->getConversationIdFromOtherUserId($other_user_id); + return $this->post("/messages/$conversation_id/$message_id/like"); + } + + public function unlikeDirectMessage($other_user_id, $message_id) { + $conversation_id = $this->getConversationIdFromOtherUserId($other_user_id); + return $this->post("/messages/$conversation_id/$message_id/unlike"); + } + + // Group methods + public function getAllGroups($page=1, $per_page=10) { + $query = array( + 'page' => $page, + 'per_page' => $per_page + ); + return $this->get('/groups', $query); + } + + public function getFormerGroups() { + return $this->get('/groups/former'); + } + + public function createGroup($name, $description='', $image_url='', $share=false) { + $payload = array( + 'name' =>$name, + 'description' => $description, + 'image_url' => $image_url, + 'share' => boolval($share) + ); + return $this->post('/groups', $payload); + } + + public function getGroupDetails($group_id) { + return $this->request("/groups/$group_id"); + } + + public function updateGroupDetails($group_id, array $payload) { + return $this->post("/groups/$group_id/update", $payload); + } + + public function destroyGroup($group_id) { + return $this->post("/groups/$group_id/destroy"); + } + + public function joinGroup($group_id, $share_token) { + return $this->post("/groups/$group_id/join/$share_token"); + } + + public function rejoinGroup($group_id) { + $payload = array('group_id' => $group_id); + return $this->post('/groups/join', $payload); + } + + public function getLeaderboard($group_id, $period='day') { + $query = array('period' => $period); + return $this->get("/groups/$group_id/likes", $query); + } + + public function getLeaderboardForDay($group_id) { + return $this->getLeaderboard($group_id, 'day'); + } + + public function getLeaderboardForWeek($group_id) { + return $this->getLeaderboard($group_id, 'week'); + } + + public function getLeaderboardForMonth($group_id) { + return $this->getLeaderboard($group_id, 'month'); + } + + public function getMyLikes($group_id) { + return $this->get("/groups/$group_id/likes/mine"); + } + + public function getMyHits($group_id) { + return $this->get("/groups/$group_id/likes/for_me"); + } + + public function addMembersToGroup($group_id, array $members) { + $payload = array('members' => $members); + return $this->post("/groups/$group_id/members/add", $payload); + } + + public function updateMyGroupMembership($group_id, $nickname) { + $membership_info = array('nickname' => $nickname); + $payload = array('membership' => $membership_info); + return $this->post("/groups/$group_id/memberships/update", $payload); + } + + public function getGroupMembers($group_id, $results_id) { + return $this->get("/groups/$group_id/members/results/$results_id"); + } + + public function removeGroupMember($group_id, $user_id) { + return $this->post("/groups/$group_id/members/$user_id/remove"); + } + + public function getLatestGroupMessages($group_id, $limit=20) { + $query = array('limit' => $limit); + return $this->get("/groups/$group_id/messages", $query); + } + + public function getGroupMessagesBefore($group_id, $message_id, $limit=20) { + $query = array( + 'before_id' => $message_id, + 'limit' => $limit + ); + return $this->get("/groups/$group_id/messages", $query); + } + + public function getGroupMessagesAfter($group_id, $message_id, $limit=20) { + $query = array( + 'after_id' => $message_id, + 'limit' => $limit + ); + return $this->get("/groups/$group_id/messages", $query); + } + + public function getGroupMessagesSince($group_id, $message_id, $limit=20) { + $query = array( + 'since_id' => $message_id, + 'limit' => $limit + ); + return $this->get("/groups/$group_id/messages", $query); + } + + public function sendGroupMessage($group_id, $text, $source_guid=null, array $attachments=array()) { + $message_info = array( + 'text' => $text, + 'source_guid' => $source_guid ?: "G$group_id-" . date('YmdHis-') . uniqid(), + 'attachments' => $attachments + ); + $payload = array('message' => $message_info); + return $this->post("/groups/$group_id/messages", $payload); + } + + // User methods + public function getMyDetails() { + return $this->get('/users/me'); + } + + public function updateMyDetails(array $payload) { + return $this->post('/users/update', $payload); + } + + public function enableSmsMode($duration, $registration_id) { + $payload = array( + 'duration' => $duration, + 'registration_id' => $registration_id + ); + return $this->post('/users/sms_mode', $payload); + } + + public function disableSmsMode() { + return $this->post('/users/sms_mode/delete'); + } + + // Core methods + private function get($endpoint, array $query=array()) { + return $this->request('GET', $endpoint, $query); + } + + private function post($endpoint, array $payload=array()) { + return $this->request('POST', $endpoint, array(), $payload); + } + + private function request($method, $endpoint, array $query=array(), array $payload=array(), $img_svc_url=false) { + if ($img_svc_url) { + $base_url = 'https://image.groupme.com'; + $query['access_token'] = $this->token; + } + else { + $base_url = 'https://api.groupme.com/v3'; + $query['token'] = $this->token; + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $base_url . $endpoint . '?' . http_build_query($query)); + curl_setopt($ch, CURLOPT_TIMEOUT, 4); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_USERAGENT, 'GroupMe API Client'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + + if ($method == 'POST') { + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); + } + + $result = curl_exec($ch); + curl_close($ch); + return json_decode($result, true); + } +} diff --git a/src/EmojiUtils.php b/src/EmojiUtils.php new file mode 100644 index 0000000..47d6fac --- /dev/null +++ b/src/EmojiUtils.php @@ -0,0 +1,449 @@ + $seq) { + if ($seq == $sequence) { + return $name; + } + } + } + + public static function getEmojiNameByPackAndIndex($pack, $index) { + $sequence = array($pack, $index); + return self::getEmojiNameBySequence($sequence); + } + + public static function getCharmapFromEmojiNames(array $names) { + $callback = 'self::getEmojiSequenceByName'; + return array_map($callback, $names); + } + + public static function extractEmojiNamesFromText($text) { + $charmap = array(); + + if (preg_match_all('~(:[A-Za-z0-9_\-!]+:)~', $text, $matches)) { + foreach ($matches[1] as $m) { + $seq = self::getEmojiSequenceByName($m); + if (!$seq) continue; + + $charmap[] = $seq; + $text = preg_replace("~$m~", self::PLACEHOLDER, $text, 1); + } + } + + return array( + 'text' => $text, + 'charmap' => $charmap, + ); + } + + public static function injectEmojiNamesIntoText($text, $charmap) { + $placeholder=self::PLACEHOLDER; + //$text = str_replace(chr(194).chr(160), ' ', $text); + + foreach ($charmap as $seq) { + $name = self::getEmojiNameBySequence($seq); + $text = preg_replace("~$placeholder~", $name, $text, 1); + } + + return $text; + } + + private static $emojis = array( + ':smiley_face:' => array(1, 0), + ':happy_face:' => array(1, 1), + ':pleased_face:' => array(1, 2), + ':content_face:' => array(1, 3), + ':winky_face:' => array(1, 4), + ':thrilled_face:' => array(1, 5), + ':swoon_face:' => array(1, 6), + ':clown_face:' => array(1, 7), + ':goofy_face:' => array(1, 8), + ':silly_face:' => array(1, 9), + ':neil_face:' => array(1, 10), + ':glasses_face:' => array(1, 11), + ':cool_guy_face:' => array(1, 12), + ':cigar_face:' => array(1, 13), + ':blank_face:' => array(1, 14), + ':bummed_face:' => array(1, 15), + ':sad_face:' => array(1, 16), + ':tearful_face:' => array(1, 17), + ':crying_face:' => array(1, 18), + ':nervous_face:' => array(1, 19), + ':frustrated_face:' => array(1, 20), + ':mad_face:' => array(1, 21), + ':conniving_face:' => array(1, 22), + ':grossed_out_face:' => array(1, 23), + ':sick_face:' => array(1, 24), + ':puking_face:' => array(1, 25), + ':dead_face:' => array(1, 26), + ':yawn_face:' => array(1, 27), + ':surprised_face:' => array(1, 28), + ':shocked_face:' => array(1, 29), + ':stoney_face:' => array(1, 30), + ':tweak_face:' => array(1, 31), + ':kissy_face:' => array(1, 32), + ':surprised_glasses_face:' => array(1, 33), + ':hand_over_mouth_face:' => array(1, 34), + ':hands_over_eyes_face:' => array(1, 35), + ':confused_face:' => array(1, 36), + ':zipper_mouth_face:' => array(1, 37), + ':sleeping_face:' => array(1, 38), + ':caffeinated_face:' => array(1, 39), + ':emo_face:' => array(1, 40), + ':gasp_face:' => array(1, 41), + ':goatee_face:' => array(1, 42), + ':steve:' => array(1, 43), + ':jared:' => array(1, 44), + ':iced_coffee:' => array(1, 45), + ':latte:' => array(1, 46), + ':icecream_cookie:' => array(1, 47), + ':hotsauce:' => array(1, 48), + ':tacotaco:' => array(1, 49), + ':pizza:' => array(1, 50), + ':popping_bottle:' => array(1, 51), + ':brown_bottle:' => array(1, 52), + ':lighter:' => array(1, 53), + ':red_solo_cup:' => array(1, 54), + ':pingpong:' => array(1, 55), + ':pinball_flipper:' => array(1, 56), + ':pink_electric_guitar:' => array(1, 57), + ':wet_wipes:' => array(1, 58), + ':dead_fish:' => array(1, 59), + ':petey:' => array(1, 60), + ':pivotal:' => array(1, 61), + ':dino:' => array(1, 62), + ':heart:' => array(1, 63), + ':badge_icon:' => array(1, 64), + ':grilled_cheese:' => array(1, 65), + ':poundie:' => array(1, 66), + ':frowndie:' => array(1, 67), + ':headphones_poundie:' => array(1, 68), + ':blonde_poundie:' => array(1, 69), + ':nerdie_poundie:' => array(1, 70), + ':evil_poundie:' => array(1, 71), + ':angel_poundie:' => array(1, 72), + ':kitty_poundie:' => array(1, 73), + ':pink_bow_poundie:' => array(1, 74), + ':3d_poundie:' => array(1, 75), + ':sunglasses_poundie:' => array(1, 76), + ':beanie_poundie:' => array(1, 77), + ':bowtie_poundie:' => array(1, 78), + ':kissie_poundie:' => array(1, 79), + ':bandit_poundie:' => array(1, 80), + ':disguise_poundie:' => array(1, 81), + ':beard_poundie:' => array(1, 82), + ':tongue_out_poundie:' => array(1, 83), + ':backwards_hat_smiley_face:' => array(2, 0), + ':snorkel_face:' => array(2, 1), + ':sporty_sun_glasses_face:' => array(2, 2), + ':life_vest_face:' => array(2, 3), + ':watermelon_mouth_face:' => array(2, 4), + ':taking_a_picture_face:' => array(2, 5), + ':shutter_shades_face:' => array(2, 6), + ':face_with_speedo:' => array(2, 7), + ':thong_butt:' => array(2, 8), + ':dreadlocks:' => array(2, 9), + ':sunscreen:' => array(2, 10), + ':tanning:' => array(2, 11), + ':paradise:' => array(2, 12), + ':sunset:' => array(2, 13), + ':fireworks:' => array(2, 14), + ':beachball:' => array(2, 15), + ':flippers:' => array(2, 16), + ':sun:' => array(2, 17), + ':sun_with_sunglasses:' => array(2, 18), + ':kite:' => array(2, 19), + ':surfing_doggie:' => array(2, 20), + ':life_saver:' => array(2, 21), + ':sail_boat:' => array(2, 22), + ':hawaiian_shirt:' => array(2, 23), + ':board_shorts:' => array(2, 24), + ':bikini:' => array(2, 25), + ':flip_flops:' => array(2, 26), + ':sun_tan_lotion:' => array(2, 27), + ':aviator_glasses:' => array(2, 28), + ':sun_hat:' => array(2, 29), + ':sand_castle:' => array(2, 30), + ':sand_bucket:' => array(2, 31), + ':sea_shell:' => array(2, 32), + ':water_gun:' => array(2, 33), + ':air_conditioner:' => array(2, 34), + ':fan:' => array(2, 35), + ':fire_hyrdrant:' => array(2, 36), + ':ice_bag:' => array(2, 37), + ':popsicle:' => array(2, 38), + ':baseball:' => array(2, 39), + ':pit-stained_shirt:' => array(2, 40), + ':jorts:' => array(2, 41), + ':bee:' => array(2, 42), + ':spilled_ice_cream:' => array(2, 43), + ':deal_with_it_dog:' => array(2, 44), + ':car_trip:' => array(2, 45), + ':camp_fire:' => array(2, 46), + ':marshmallow:' => array(2, 47), + ':graham_cracker:' => array(2, 48), + ':chocolate_bar:' => array(2, 49), + ':mosquito:' => array(2, 50), + ':grill:' => array(2, 51), + ':grilled_steak:' => array(2, 52), + ':grilled_chicken:' => array(2, 53), + ':hotdog:' => array(2, 54), + ':hamburger:' => array(2, 55), + ':can:' => array(2, 56), + ':fish_taco:' => array(2, 57), + ':bacon:' => array(2, 58), + ':lettuce:' => array(2, 59), + ':tomato:' => array(2, 60), + ':pickle:' => array(2, 61), + ':avocado:' => array(2, 62), + ':peach:' => array(2, 63), + ':blueberry:' => array(2, 64), + ':raspberry:' => array(2, 65), + ':strawberry:' => array(2, 66), + ':banana:' => array(2, 67), + ':watermelon:' => array(2, 68), + ':blender:' => array(2, 69), + ':margarita:' => array(2, 70), + ':pina_colada:' => array(2, 71), + ':drink_umbrella:' => array(2, 72), + ':slice_of_lime:' => array(2, 73), + ':coconut_drink:' => array(2, 74), + ':lemonade:' => array(2, 75), + ':ice_cream_cone:' => array(2, 76), + ':ice_cream_sandwich:' => array(2, 77), + ':shark:' => array(2, 78), + ':gold_fish:' => array(2, 79), + ':squid:' => array(2, 80), + ':starfish:' => array(2, 81), + ':crab:' => array(2, 82), + ':lobster:' => array(2, 83), + ':sting_ray:' => array(2, 84), + ':stack_of_books_face:' => array(3, 0), + ':taped_glasses_face:' => array(3, 1), + ':writing_face:' => array(3, 2), + ':open_laptop:' => array(3, 3), + ':science_experiment:' => array(3, 4), + ':painter:' => array(3, 5), + ':backpack_front:' => array(3, 6), + ':backpack_back:' => array(3, 7), + ':singer:' => array(3, 8), + ':wrestler:' => array(3, 9), + ':football_player:' => array(3, 10), + ':#1_fan:' => array(3, 11), + ':marching_band_leader:' => array(3, 12), + ':cheerleader:' => array(3, 13), + ':sleep_deprived_face:' => array(3, 14), + ':stressed_out_face:' => array(3, 15), + ':graduate:' => array(3, 16), + ':prom_king:' => array(3, 17), + ':prom_queen:' => array(3, 18), + ':toga:' => array(3, 19), + ':upside-down_face:' => array(3, 20), + ':lamp_shade_head:' => array(3, 21), + ':school_bus:' => array(3, 22), + ':A+:' => array(3, 23), + ':Fail:' => array(3, 24), + ':spiral_notebook:' => array(3, 25), + ':#2_pencil:' => array(3, 26), + ':paper_airplane:' => array(3, 27), + ':calculator:' => array(3, 28), + ':globe:' => array(3, 29), + ':chalk_board:' => array(3, 30), + ':bell:' => array(3, 31), + ':diploma:' => array(3, 32), + ':teachers_pet:' => array(3, 33), + ':sack_lunch:' => array(3, 34), + ':school_lunch:' => array(3, 35), + ':varsity_jacket:' => array(3, 36), + ':fencing:' => array(3, 37), + ':lacrosse:' => array(3, 38), + ':field_hockey:' => array(3, 39), + ':cleat:' => array(3, 40), + ':soccer_ball:' => array(3, 41), + ':basketball:' => array(3, 42), + ':baseball_hit:' => array(3, 43), + ':football:' => array(3, 44), + ':hockey:' => array(3, 45), + ':frisbee:' => array(3, 46), + ':stadium:' => array(3, 47), + ':drama_club:' => array(3, 48), + ':bicycle:' => array(3, 49), + ':pool_table:' => array(3, 50), + ':bunk_bed:' => array(3, 51), + ':laundry:' => array(3, 52), + ':alarm_clock:' => array(3, 53), + ':lava_lamp:' => array(3, 54), + ':guitar:' => array(3, 55), + ':video_game_controller:' => array(3, 56), + ':BRB:' => array(3, 57), + ':shower_shoes:' => array(3, 58), + ':shower_caddy:' => array(3, 59), + ':prescription:' => array(3, 60), + ':freshman_15:' => array(3, 61), + ':condom:' => array(3, 62), + ':sweatpants:' => array(3, 63), + ':sweatpants_behind:' => array(3, 64), + ':hippy_sandals:' => array(3, 65), + ':pot_of_coffee:' => array(3, 66), + ':ramen:' => array(3, 67), + ':mac_and_cheese:' => array(3, 68), + ':takeout:' => array(3, 69), + ':pizza_box:' => array(3, 70), + ':chips:' => array(3, 71), + ':energy_drink:' => array(3, 72), + ':real_ID:' => array(3, 73), + ':cups:' => array(3, 74), + ':pony:' => array(3, 75), + ':shot_glass:' => array(3, 76), + ':alpha:' => array(3, 77), + ':beta:' => array(3, 78), + ':gamma:' => array(3, 79), + ':delta:' => array(3, 80), + ':epsilon:' => array(3, 81), + ':zeta:' => array(3, 82), + ':eta:' => array(3, 83), + ':theta:' => array(3, 84), + ':iota:' => array(3, 85), + ':kappa:' => array(3, 86), + ':lambda:' => array(3, 87), + ':mu:' => array(3, 88), + ':nu:' => array(3, 89), + ':xi:' => array(3, 90), + ':omicron:' => array(3, 91), + ':pi:' => array(3, 92), + ':rho:' => array(3, 93), + ':sigma:' => array(3, 94), + ':tau:' => array(3, 95), + ':upsilon:' => array(3, 96), + ':phi:' => array(3, 97), + ':chi:' => array(3, 98), + ':psi:' => array(3, 99), + ':omega:' => array(3, 100), + ':pirate:' => array(4, 0), + ':witch:' => array(4, 1), + ':ghost:' => array(4, 2), + ':vampire:' => array(4, 3), + ':scary_nurse:' => array(4, 4), + ':red_riding_hood:' => array(4, 5), + ':cowboy:' => array(4, 6), + ':jason_mask:' => array(4, 7), + ':mummy:' => array(4, 8), + ':frankenstein:' => array(4, 9), + ':bride_of_frankenstein:' => array(4, 10), + ':zombie:' => array(4, 11), + ':ax_head:' => array(4, 12), + ':policeman:' => array(4, 13), + ':lion:' => array(4, 14), + ':werewolf:' => array(4, 15), + ':scream_mask:' => array(4, 16), + ':fairy_princess:' => array(4, 17), + ':hot_dog_dog:' => array(4, 18), + ':jack_o_lantern:' => array(4, 19), + ':spider_web:' => array(4, 20), + ':skull:' => array(4, 21), + ':grim_reaper:' => array(4, 22), + ':boo!:' => array(4, 23), + ':coffin:' => array(4, 24), + ':bloody_hand:' => array(4, 25), + ':spider:' => array(4, 26), + ':bat:' => array(4, 27), + ':cauldron:' => array(4, 28), + ':trick_or_treat!:' => array(4, 29), + ':candy_corn:' => array(4, 30), + ':smashed_pumpkin:' => array(4, 31), + ':eggs:' => array(4, 32), + ':tp_tree:' => array(4, 33), + ':black_cat:' => array(4, 34), + ':flying_witch:' => array(4, 35), + ':rip:' => array(4, 36), + ':pilgrim:' => array(5, 0), + ':native_american:' => array(5, 1), + ':leaf_pile:' => array(5, 2), + ':chef:' => array(5, 3), + ':about_to_eat:' => array(5, 4), + ':so_full:' => array(5, 5), + ':food_coma:' => array(5, 6), + ':black_friday_shopper:' => array(5, 7), + ':watching_the_game:' => array(5, 8), + ':cornucopia:' => array(5, 9), + ':maize:' => array(5, 10), + ':hand_turkey:' => array(5, 11), + ':living_turkey:' => array(5, 12), + ':baster:' => array(5, 13), + ':deal_with_it_turkey:' => array(5, 14), + ':gravy:' => array(5, 15), + ':mashed_potatoes:' => array(5, 16), + ':stuffing:' => array(5, 17), + ':cranberry_sauce:' => array(5, 18), + ':sweet_potatoes_and_marshmallows:' => array(5, 19), + ':green_beans:' => array(5, 20), + ':rolls:' => array(5, 21), + ':dog_begging:' => array(5, 22), + ':full_plate:' => array(5, 23), + ':empty_plate:' => array(5, 24), + ':wish_bone:' => array(5, 25), + ':pumpkin_pie:' => array(5, 26), + ':hot_apple_cider:' => array(5, 27), + ':wine:' => array(5, 28), + ':leftover_sandwich:' => array(5, 29), + ':dreidel:' => array(5, 30), + ':menorah:' => array(5, 31), + ':gelt:' => array(5, 32), + ':jelly_donut:' => array(5, 33), + ':santa:' => array(10, 0), + ':mrs_claus:' => array(10, 1), + ':elf:' => array(10, 2), + ':caroler:' => array(10, 3), + ':mistletoe_kiss:' => array(10, 4), + ':keviiiiin:' => array(10, 5), + ':bundled_up:' => array(10, 6), + ':snowing:' => array(10, 7), + ':snowflake_on_tongue:' => array(10, 8), + ':hit_with_snowball:' => array(10, 9), + ':skier:' => array(10, 10), + ':sick:' => array(10, 11), + ':christmas_tree_car:' => array(10, 12), + ':christmas_tree:' => array(10, 13), + ':sad_christmas_tree:' => array(10, 14), + ':present:' => array(10, 15), + ':santa_hat:' => array(10, 16), + ':christmas_lights:' => array(10, 17), + ':wreath:' => array(10, 18), + ':ornament:' => array(10, 19), + ':mistletoe:' => array(10, 20), + ':stocking:' => array(10, 21), + ':fireplace:' => array(10, 22), + ':gingerbread_man:' => array(10, 23), + ':candy_cane:' => array(10, 24), + ':milk_and_cookies:' => array(10, 25), + ':hot_chocolate:' => array(10, 26), + ':ugly_sweater:' => array(10, 27), + ':party_dress:' => array(10, 28), + ':sleigh:' => array(10, 29), + ':snow_globe:' => array(10, 30), + ':rudolph:' => array(10, 31), + ':penguin:' => array(10, 32), + ':dog_with_antlers:' => array(10, 33), + ':snowman:' => array(10, 34), + ':ice_skate:' => array(10, 35), + ':snowflake:' => array(10, 36), + ':2014_glasses:' => array(10, 37), + ':noisemaker:' => array(10, 38), + ':nye_kiss:' => array(10, 39), + ':cheers:' => array(10, 40), + ':midnight:' => array(10, 41), + ); +} diff --git a/tests/EmojiUtilsTest.php b/tests/EmojiUtilsTest.php new file mode 100644 index 0000000..c2922ad --- /dev/null +++ b/tests/EmojiUtilsTest.php @@ -0,0 +1,57 @@ +assertEquals($expected, $actual); + } + + public function test_ShouldReturnEmojiNameBySequence() { + $expected = ':cigar_face:'; + $actual = EmojiUtils::getEmojiNameBySequence(array(1, 13)); + $this->assertEquals($expected, $actual); + } + + public function test_ShouldReturnEmojiNameByPackAndIndex() { + $expected = ':tweak_face:'; + $actual = EmojiUtils::getEmojiNameByPackAndIndex(1, 31); + $this->assertEquals($expected, $actual); + } + + public function test_ShouldReplaceEmojiNamesWithPlaceholders() { + $ph = EmojiUtils::PLACEHOLDER; + $text = 'Hello :smiley_face::smiley_face::pleased_face:'; + + $expected = "Hello $ph$ph$ph"; + $result = EmojiUtils::extractEmojiNamesFromText($text); + $this->assertEquals($expected, $result['text']); + } + + public function test_ShouldReplacePlaceholdersWithEmojiNames() { + $ph = EmojiUtils::PLACEHOLDER; + $text = "Hello $ph$ph$ph"; + $charmap = array(array(1,0), array(1,0), array(1,2)); + + $expected = "Hello :smiley_face::smiley_face::pleased_face:"; + $actual = EmojiUtils::injectEmojiNamesIntoText($text, $charmap); + $this->assertEquals($expected, $actual); + } + + public function test_ShouldReturnCharmap() { + $text = 'Hello :smiley_face::smiley_face::pleased_face:'; + + $expected = array(array(1,0), array(1,0), array(1,2)); + $result = EmojiUtils::extractEmojiNamesFromText($text); + $this->assertEquals($expected, $result['charmap']); + } + + public function test_ShouldNotMatchAnyEmojis() { + $text = 'Hello :nonexistent_face:'; + + $expected = "Hello :nonexistent_face:"; + $result = EmojiUtils::extractEmojiNamesFromText($text); + $this->assertEquals($expected, $result['text']); + } +}