コード例 #1
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;
     });
 }
コード例 #2
0
ファイル: example.php プロジェクト: jimlind/pie7o
<?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;
}
コード例 #3
0
ファイル: TweeterFactoryTest.php プロジェクト: jimlind/pie7o
 /**
  * Not really anything testable here. It's mostly configuration.
  */
 public function testBuildTweeter()
 {
     $settings = ['accessToken' => uniqid(), 'accessTokenSecret' => uniqid(), 'consumerKey' => uniqid(), 'consumerSecret' => uniqid()];
     $fixture = TweeterFactory::buildTweeter($settings);
     $this->assertInstanceOf('JimLind\\Pie7o\\Tweeter', $fixture);
 }