Exemplo n.º 1
0
 public function register(Application $app)
 {
     $app['guzzle.base_url'] = '/';
     $app['guzzle.api_version'] = $app->share(function () use($app) {
         return version_compare(Client::VERSION, '6.0.0', '>=') ? 6 : 5;
     });
     if (!isset($app['guzzle.handler_stack'])) {
         $app['guzzle.handler_stack'] = $app->share(function () {
             return HandlerStack::create();
         });
     }
     /** @deprecated Remove when Guzzle 5 support is dropped */
     if (!isset($app['guzzle.plugins'])) {
         $app['guzzle.plugins'] = [];
     }
     // Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
     $app['guzzle.client'] = $app->share(function () use($app) {
         if ($app['guzzle.api_version'] === 5) {
             $options = ['base_url' => $app['guzzle.base_url']];
             $client = new Client($options);
             foreach ($app['guzzle.plugins'] as $plugin) {
                 $client->addSubscriber($plugin);
             }
         } else {
             $options = ['base_uri' => $app['guzzle.base_url'], 'handler' => $app['guzzle.handler_stack']];
             $client = new Client($options);
         }
         return $client;
     });
 }
Exemplo n.º 2
0
 /**
  * Upload post 
  */
 public function post()
 {
     $token = Session::get('token');
     $client = new Client(['base_url' => $this->oauthUrl, 'defaults' => ['auth' => 'oauth']]);
     $oauthConfig = array('consumer_key' => $this->oauthKey, 'consumer_secret' => $this->oauthSecret, 'token' => $token->oauth_token, 'token_secret' => $token->oauth_token_secret);
     $oauth = new Oauth1($oauthConfig);
     $client->getEmitter()->attach($oauth);
     $logger = new Logger('client');
     $logger->pushHandler(new StreamHandler('guzzle.log'));
     $logAdapter = new MonologLogAdapter($logger);
     $logPlugin = new LogPlugin($logAdapter, MessageFormatter::DEBUG_FORMAT);
     $client->addSubscriber($logPlugin);
     $content = file_get_contents(Input::file("inputFileName")->getRealPath());
     try {
         /*
         $r = $client->put($this->oauthRequestImageEndpoint.'?output=json', ['body' => $content ]);
         $imageResult = json_decode($r->getBody());
         $message = "[img]".$imageResult->url."[/img]";
         */
         $forum_id = Config::get('kasgag.forum');
         $title = Input::get("inputTitle");
         $message = '[img]http://kascdn.mooo.com/images/2014/10/12/11_201410120657540167.jpg[/img]';
         $resp = $client->post('thread', ['body' => ['forum_id' => $forum_id, 'title' => $title, 'message' => $message]]);
         // save to DB
         var_dump($resp);
         /*
         $post = json_decode($resp,true);
         $newThreadInfo = new ThreadInfo;
         $newThreadInfo->id = $post['thread_id'];
         $newThreadInfo->title = $title;
         $newThreadInfo->user_id = $token->userid;
         $newThreadInfo->user_name = $token->username;
         $newThreadInfo->page_text = $message;
         $newThreadInfo->save();
         */
     } catch (RequestException $re) {
         echo $re->getRequest() . "\n";
         if ($re->hasResponse()) {
             echo $re->getResponse() . "\n";
         }
     } catch (ClientException $ce) {
         echo $ce->getRequest() . "\n";
         if ($ce->hasResponse()) {
             echo $ce->getResponse() . "\n";
         }
     }
     //return Redirect::to("/");
 }
Exemplo n.º 3
0
 public function register(Application $app)
 {
     $app['guzzle.base_url'] = '/';
     if (!isset($app['guzzle.plugins'])) {
         $app['guzzle.plugins'] = [];
     }
     // Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
     $app['guzzle.client'] = $app->share(function () use($app) {
         $options = ['base_url' => $app['guzzle.base_url']];
         $client = new Client($options);
         foreach ($app['guzzle.plugins'] as $plugin) {
             $client->addSubscriber($plugin);
         }
         return $client;
     });
 }
Exemplo n.º 4
0
 public function register(Application $app)
 {
     $app['guzzle.base_url'] = '/';
     if (!isset($app['guzzle.plugins'])) {
         $app['guzzle.plugins'] = array();
     }
     /** @deprecated */
     if ($app['deprecated.php']) {
         return $this->compat($app);
     }
     // Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
     $app['guzzle.client'] = $app->share(function () use($app) {
         $options = array('base_url' => $app['guzzle.base_url']);
         $client = new Client($options);
         foreach ($app['guzzle.plugins'] as $plugin) {
             $client->addSubscriber($plugin);
         }
         return $client;
     });
 }