Services_Twitter_Uploader
[ class tree: Services_Twitter_Uploader ] [ index: Services_Twitter_Uploader ] [ all elements ]

Source for file YfrogUploader.php

Documentation is available at YfrogUploader.php

  1. <?php
  2. /**
  3.  * An abstract interface for OAuthUploader Services
  4.  *
  5.  * PHP version 5.2.0+
  6.  *
  7.  * Copyright 2010 withgod
  8.  *
  9.  * Licensed under the Apache License, Version 2.0 (the "License");
  10.  * you may not use this file except in compliance with the License.
  11.  * You may obtain a copy of the License at
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  *
  19.  * @category Services
  20.  * @package  Services_Twitter_Uploader
  21.  * @author   withgod <noname@withgod.jp>
  22.  * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License
  23.  * @version  Release: 0.1.0
  24.  * @link     https://github.com/withgod/Services_Twitter_Uploader
  25.  */
  26.  
  27. require_once 'HTTP/Request2.php';
  28. require_once 'Services/Twitter/Uploader.php';
  29.  
  30. /**
  31.  * implementation OAuthUploader Services
  32.  *
  33.  * @category Services
  34.  * @package  Services_Twitter_Uploader
  35.  * @author   withgod <noname@withgod.jp>
  36.  * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License
  37.  * @version  Release: 0.1.0
  38.  * @link     https://github.com/withgod/Services_Twitter_Uploader
  39.  * @link     http://code.google.com/p/imageshackapi/
  40.  * @link     http://code.google.com/p/imageshackapi/wiki/TwitterAuthentication
  41.  * @see      HTTP_Request2
  42.  */
  43. {
  44.  
  45.     /**
  46.      * upload endpoint
  47.      * @var string 
  48.      */
  49.     protected $uploadUrl = "https://yfrog.com/api/upload";
  50.  
  51.     /**
  52.      * preUpload implementation
  53.      *
  54.      * @return void 
  55.      */
  56.     protected function preUpload()
  57.     {
  58.         $this->lastRequest->setConfig('ssl_verify_peer'false);
  59.         try {
  60.             $this->lastRequest->addUpload('media'$this->postFile);
  61.         catch (HTTP_Request2_Exception $e{
  62.             throw new Services_Twitter_Uploader_Exception('cannot open file ' $this->postFile);
  63.         }
  64.         $this->lastRequest->addPostParameter(
  65.             'verify_url',
  66.             $this->genVerifyUrl(self::TWITTER_VERIFY_CREDENTIALS_XML)
  67.         );
  68.         $this->lastRequest->addPostParameter('auth''oauth');
  69.         $verify file_get_contents(
  70.             $this->genVerifyUrl(self::TWITTER_VERIFY_CREDENTIALS_XML)
  71.         );
  72.         $this->lastRequest->addPostParameter(
  73.             'username',
  74.             (string)simplexml_load_string($verify)->screen_name
  75.         );
  76.     }
  77.  
  78.     /**
  79.      * postUpload implementation
  80.      *
  81.      * @return string|nullimage url
  82.      */
  83.     protected function postUpload()
  84.     {
  85.         $body $this->postUploadCheck($this->response200);
  86.         $resp simplexml_load_string($body);
  87.  
  88.         if ($resp['stat'== 'ok'{
  89.             return (string)$resp->mediaurl[0];
  90.         }
  91.         throw new Services_Twitter_Uploader_Exception(
  92.             'invalid response code [' $resp->err['msg'']'
  93.         );
  94.     }
  95. }

Documentation generated on Wed, 19 Oct 2011 16:30:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.