Permalink
Browse files

update annotated code, add package installer configs

  • Loading branch information...
jabranr committed Jul 7, 2014
1 parent 9da3828 commit f9fa9f051e760b26413c6e457c9a907f65762e67
Showing with 157 additions and 11 deletions.
  1. +2 −1 .gitignore
  2. +14 −1 CHANGELOG.md
  3. +20 −2 README.md
  4. +6 −0 Tests/FetchwitterTest.php
  5. +22 −0 bower.json
  6. +19 −0 composer.json
  7. +17 −4 package.json
  8. +57 −3 src/Fetchwitter.php
View
@@ -1,3 +1,4 @@
.DS_Store
examples
vendor
vendor
branding
View
@@ -1,8 +1,21 @@
## Fetchwitter Change Log
PHP library to use with Twitter API v1.1
PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization
Version: 1.0.5
+ Available using [Composer](http://getcomposer.org)
+ More annotated code
===
Version: 1.0.4
+ Unit Test added with Travis CI
===
Version: 1.0.3
+ Added comments to class.
View
@@ -1,10 +1,28 @@
## Fetchwitter [![Build Status](https://travis-ci.org/jabranr/Fetchwitter.svg?branch=master)](https://travis-ci.org/jabranr/Fetchwitter)
PHP library to use with Twitter API v1.1
PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization
<blockquote>This is an updated and enhanced version of <a href="https://github.com/jabranr/twitter-api-v1.1" target="_blank">existing PHP wrapper</a> to fetch Tweets using <a href="https://dev.twitter.com/docs/api/1.1" target="_blank">Twitter API v1.1</a> (unlike its depreciated API v1) that requires authentication for any kind of requests made to its endpoints.</blockquote>
<blockquote>The authentication flow only uses the App-Only Authentication.</blockquote>
<blockquote>The authentication flow uses Twiiter’s App-Only Authentication.</blockquote>
## Install
Fetchwitter can be installed using one of following methods:
#### [Download the latest release](https://github.com/jabranr/Fetchwitter/releases)
#### Use `Bower`
``` shell
$ bower install fetchwitter
```
#### Use `Composer`
``` shell
$ composer install fetchwitter
```
## Basic Example
@@ -6,6 +6,12 @@ class FetchwitterTest extends PHPUnit_Framework_TestCase {
public $fetchwitter, $config;
public function setUp() {
/**
* Do NOT use these credentials in your projects as they have
* limited functionality for testing purpose only.
*/
$this->config = array(
'api_key' => 'hqXaOd33grIEIOizaUvpcQ',
'api_secret' => 'Kxs68MJGHvtTe9CArjLntsc9iVDEygIfqTJlrcqMhLM'
View
@@ -0,0 +1,22 @@
{
"name": "fetchwitter",
"version": "1.0.5",
"homepage": "https://github.com/jabranr/Fetchwitter",
"authors": [
"Jabran Rafique <hello@jabran.me>"
],
"main": "src/",
"keywords": [
"php",
"twitter-api",
"api"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
View
@@ -0,0 +1,19 @@
{
"name": "fetchwitter/Fetchwitter",
"type": "framework",
"version": "1.0.5",
"description": "PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization",
"keywords": ["twitter","twitter-api", "oauth", "fetch-tweets", "php"],
"homepage": "http://git.io/fetchwitter",
"license": "MIT",
"authors": [
{
"name": "Jabran Rafique",
"email": "hello@jabran.me",
"homepage": "http://jabran.me"
}
],
"require": {
"php": ">=5.3.0"
}
}
View
@@ -1,6 +1,19 @@
{
"name": "Fetchwitter",
"author": "Jabran Rafique",
"version": "1.0.4",
"license": "MIT License"
"name": "Fetchwitter",
"type": "framework",
"version": "1.0.5",
"description": "PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization",
"keywords": ["twitter","twitter-api", "oauth", "fetch-tweets", "php"],
"homepage": "http://git.io/fetchwitter",
"license": "MIT",
"authors": [
{
"name": "Jabran Rafique",
"email": "hello@jabran.me",
"homepage": "http://jabran.me"
}
],
"require": {
"php": ">=5.3.0"
}
}
View
@@ -2,12 +2,34 @@
/*!
* Fetchwitter Class
* Fetchwitter enables to search for tweets/hashtags & get a user timeline feed.
*
* PHP framework to fetch tweets from Twitter API v1.1 using OAuth authentication/authorization.
* Fetchwitter provides easy to use methods for tweets/hashtags search & user timeline feed.
*
* @author: hello@jabran.me
* @version: 1.0.4
* @version: 1.0.5
* @license: MIT License
*
* License: MIT License
*
* Copyright (c) 2014 Jabran Rafique
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
* OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* Fetchwitter class
*/
class Fetchwitter {
@@ -68,7 +90,7 @@ public function set_access_token( $access_token ) {
/**
* Method to get current set access token
* @return: String access_token
* @return: String
*/
public function get_access_token() {
@@ -238,14 +260,32 @@ private function _get_access_token() {
return false;
}
/**
* Private method to use PHP CURL Extension.
* Throws exceptions if CURL not found.
* @return: String | Mix
*/
private function _do_curl( $options = array() ) {
if ( ! in_array('curl', get_loaded_extensions()) )
throw new Exception('CURL extension is required.');
$ch = curl_init();
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
/**
* Private method to format links in a string
* @param: String $text
* @return: String
*/
private function _do_links( $text ) {
$urlRegEx = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/i";
if ( preg_match($urlRegEx, $text, $url) ) {
@@ -256,6 +296,13 @@ private function _do_links( $text ) {
return $text;
}
/**
* Private method to format @mentions in a string
* @param: String $text
* @return: String
*/
private function _do_mentions( $text ) {
$mentionRegEx = "/@([A-Z0-9_])+/i";
if ( preg_match($mentionRegEx, $text, $mention) ) {
@@ -266,6 +313,13 @@ private function _do_mentions( $text ) {
return $text;
}
/**
* Private method to format #hashtags in a string
* @param: String $text
* @return: String
*/
private function _do_hashtags( $text ) {
$hashtagRegEx = "/#([A-Z0-9_])+/i";
if ( preg_match($hashtagRegEx, $text, $hashtags) ) {

0 comments on commit f9fa9f0

Please sign in to comment.