Example #1
0
 /**
  * Test building with a file that does exist.
  */
 public function testBuildTweetWithGoodFile()
 {
     $filePath = uniqid();
     $fileContents = uniqid();
     $root = vfsStream::setup('dir');
     vfsStream::newFile($filePath)->at($root)->setContent($fileContents);
     $tweet = TweetFactory::buildTweet('', vfsStream::url('dir/' . $filePath));
     $mediaStream = $tweet->getMedia();
     $this->assertEquals($fileContents, $mediaStream->getContents());
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app['pie7o.tweet'] = $app->protect(function ($message, $mediaPath = null) use($app) {
         $settingList = $this->buildSettingsList($app);
         $tweeter = TweeterFactory::buildTweeter($settingList);
         $tweet = TweetFactory::buildTweet($message, $mediaPath);
         $this->logger = $this->getLogger($app);
         $this->logAttempt($message, $mediaPath, $tweet);
         try {
             $tweeter->tweet($tweet);
             $this->logSuccess();
         } catch (Pie7oException $exception) {
             $this->logFailure($exception);
             return false;
         }
         return true;
     });
 }
Example #3
0
<?php

require 'vendor/autoload.php';
use JimLind\Pie7o\Pie7oException;
use JimLind\Pie7o\Factory\TweetFactory;
use JimLind\Pie7o\Factory\TweeterFactory;
/*
 * Configure all the things
 */
$tweeter = TweeterFactory::buildTweeter(['accessToken' => 'YOUR ACCESS TOKEN', 'accessTokenSecret' => 'YOUR ACCESS TOKEN SECRET', 'consumerKey' => 'YOUR CONSUMER KEY', 'consumerSecret' => 'YOUR CONSUMER SECRET']);
/*
 * Create a Tweet
 */
$tweet = TweetFactory::buildTweet('This is a cool picture of cats.', './cat.jpg');
/*
 * Tweet and catch exceptions
 */
try {
    $tweeter->tweet($tweet);
    echo 'Tweeting was successful.' . PHP_EOL;
} catch (Pie7oException $exception) {
    echo 'Tweeting failed.' . PHP_EOL;
    echo 'Exception thrown: `' . $exception->getMessage() . '`' . PHP_EOL;
}