Permalink
Browse files

Update EpiTwitter.php

  • Loading branch information...
dlnetworks committed Feb 28, 2014
1 parent 4ee0153 commit 0db3c0dbe0483545b0adfc0cb2c2ed43c525ea32
Showing with 31 additions and 16 deletions.
  1. +31 −16 EpiTwitter.php
View
@@ -1,21 +1,32 @@
<?php
/*
* Class to integrate with Twitter's API.
* Authenticated calls are done using OAuth and require access tokens for a user.
* API calls which do not require authentication do not require tokens (i.e. search/trends)
*
* Full documentation available on github
* http://wiki.github.com/jmathai/twitter-async
*
* @author Jaisen Mathai <jaisen@jmathai.com>
*/
class EpiTwitter extends EpiOAuth
{
const EPITWITTER_SIGNATURE_METHOD = 'HMAC-SHA1';
const EPITWITTER_AUTH_OAUTH = 'oauth';
const EPITWITTER_AUTH_BASIC = 'basic';
protected $requestTokenUrl= 'https://twitter.com/oauth/request_token';
protected $accessTokenUrl = 'https://twitter.com/oauth/access_token';
protected $authorizeUrl = 'https://twitter.com/oauth/authorize';
protected $authenticateUrl= 'https://twitter.com/oauth/authenticate';
protected $apiUrl = 'https://twitter.com';
protected $apiVersionedUrl= 'https://api.twitter.com';
protected $searchUrl = 'https://search.twitter.com';
protected $requestTokenUrl= 'https://api.twitter.com/oauth/request_token';
protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
protected $authorizeUrl = 'https://api.twitter.com/oauth/authorize';
protected $authenticateUrl= 'https://api.twitter.com/oauth/authenticate';
protected $apiUrl = 'https://api.twitter.com';
protected $userAgent = 'EpiTwitter (http://github.com/jmathai/twitter-async/tree/)';
protected $apiVersion = '1.1';
protected $isAsynchronous = false;
/**
* The Twitter API version 1.0 search URL.
* @var string
*/
protected $searchUrl = 'http://search.twitter.com';
/* OAuth methods */
public function delete($endpoint, $params = null)
@@ -49,6 +60,11 @@ public function post_basic($endpoint, $params = null, $username = null, $passwor
return $this->request_basic('POST', $endpoint, $params, $username, $password);
}
public function useApiUrl($url = '')
{
$this->apiUrl = rtrim( $url, '/' );
}
public function useApiVersion($version = null)
{
$this->apiVersion = $version;
@@ -95,12 +111,12 @@ public function __call($name, $params = null/*, $username, $password*/)
private function getApiUrl($endpoint)
{
if(preg_match('@^/(trends|search)[./]?(?=(json|daily|current|weekly))@', $endpoint))
return "{$this->searchUrl}{$endpoint}";
elseif(!empty($this->apiVersion))
return "{$this->apiVersionedUrl}/{$this->apiVersion}{$endpoint}";
else
return "{$this->apiUrl}{$endpoint}";
if ($this->apiVersion === '1' && preg_match('@^/search[./]?(?=(json|daily|current|weekly))@', $endpoint))
{
return $this->searchUrl.$endpoint;
}
return $this->apiUrl.'/'.$this->apiVersion.$endpoint;
}
private function request($method, $endpoint, $params = null)
@@ -239,7 +255,6 @@ class EpiTwitterException extends Exception
public static function raise($response, $debug)
{
$message = $response->data;
switch($response->code)
{
case 400:

0 comments on commit 0db3c0d

Please sign in to comment.