Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Merge d89672a into 36f2044
Browse files Browse the repository at this point in the history
  • Loading branch information
Younès committed Aug 19, 2015
2 parents 36f2044 + d89672a commit fe58f59
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 381 deletions.
53 changes: 25 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ A simple PHP library for determining the popularity of a given URL by querying s
It presently supports:
- Twitter (counts mentions and retweets)
- Facebook (counts likes, comments and shares)
- Google+ (+1s)
- Pinterest (shares)
- Reddit (counts submitted stories and upvotes)
- StumbleUpon views
Expand All @@ -19,6 +18,7 @@ most popular articles for optimizing placement, or featuring social network
counters on your pages without relying on bloated external JavaScript includes.

## Installation

To add this package as a dependency for your project, simply add
`evansims/socialworth` to your project's composer.json file.
Here is an example of a minimal composer.json file:
Expand All @@ -38,45 +38,43 @@ before invoking Socialworth:
## Usage
To query all supported services for a URL:

<?php
use Evansims\Socialworth;

$socialworth = new Socialworth('https://github.com/');
var_dump($socialworth->all());
?>
```php
use Evansims\Socialworth\Socialworth;

$socialworth = new Socialworth('https://github.com/');
var_dump($socialworth->all());
```
Alternatively you can query just one service:

<?php
use Evansims\Socialworth;

var_dump(Socialworth::twitter('https://github.com/'));
?>
```php
var_dump(Socialworth::twitter('https://github.com/'));
```

Or leave out specific services from your query:

<?php
use Evansims\Socialworth;
```php
$socialworth = new Socialworth(['linkedin', 'twitter']) // won't do facebook etc.

$socialworth = new Socialworth('https://github.com/');
$socialworth->linkedin = false;

var_dump($socialworth->all());
?>
var_dump($socialworth->all());
```

The `all()` method will return an object that you can use to grab individual
service results or find the combined popularity from the services:

<?php
use Evansims\Socialworth;
```php
$socialworth = new Socialworth('https://github.com/');
$response = $socialworth->all();

var_dump($response->total); // Total likes, shares, upvotes, etc.
var_dump($response->reddit); // Just shares and upvotes from reddit.
var_dump($response->twitter); // Just mentions, retweets and shares on Twitter.
```

$socialworth = new Socialworth('https://github.com/');
$response = $socialworth->all();
The `setClient` allows to set a custom Guzzle Client so you can attach subscribers or mock request

var_dump($response->total); // Total likes, shares, upvotes, etc.
var_dump($response->reddit); // Just shares and upvotes from reddit.
var_dump($response->twitter); // Just mentions, retweets and shares on Twitter.
?>
```php
$socialworth->setClient(new \GuzzleHttp\Client());
```

## Demo Script
A demo script is provided that allows you to query the library from your
Expand All @@ -102,7 +100,6 @@ Whether from the CLI or the browser, you will receive a JSON object back.
"facebook": 15284,
"pinterest": 157,
"reddit": 5,
"googleplus": 6049,
"stumbleupon": 297,
"linkedin": 0
}
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
}
],
"autoload": {
"psr-0": {
"Evansims\\": "src/"
"psr-4": {
"Evansims\\Socialworth\\": "src/"
}
},
"require": {
"php": ">=5.3.0",
"lib-curl": "*"
"php": ">=5.4.0",
"lib-curl": "*",
"guzzlehttp/guzzle": "^5.3"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
Expand Down
2 changes: 1 addition & 1 deletion demo.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require 'tests/bootstrap.php';

use Evansims\Socialworth;
use Evansims\Socialworth\Socialworth;

// Command Line
if (PHP_SAPI == 'cli' && isset($argv) && count($argv > 1)) {
Expand Down

0 comments on commit fe58f59

Please sign in to comment.