{"id":16557594,"url":"https://github.com/mpratt/the-simple-lifestream","last_synced_at":"2025-03-21T10:32:29.106Z","repository":{"id":57020593,"uuid":"2695050","full_name":"mpratt/The-Simple-LifeStream","owner":"mpratt","description":"A very simple and flexible library written in PHP for your life-streaming purposes. It supports a bunch of third party services like Youtube, StackOverflow, Reddit and Github.","archived":false,"fork":false,"pushed_at":"2015-05-30T05:04:20.000Z","size":1083,"stargazers_count":44,"open_issues_count":0,"forks_count":10,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-18T00:43:16.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.michael-pratt.com/blog/4/Lifestreaming-hecho-f-cil-/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpratt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-02T13:23:10.000Z","updated_at":"2024-04-21T13:07:24.000Z","dependencies_parsed_at":"2022-08-23T13:50:37.189Z","dependency_job_id":null,"html_url":"https://github.com/mpratt/The-Simple-LifeStream","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpratt%2FThe-Simple-LifeStream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpratt%2FThe-Simple-LifeStream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpratt%2FThe-Simple-LifeStream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpratt%2FThe-Simple-LifeStream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpratt","download_url":"https://codeload.github.com/mpratt/The-Simple-LifeStream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244778041,"owners_count":20508842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T20:07:55.444Z","updated_at":"2025-03-21T10:32:28.553Z","avatar_url":"https://github.com/mpratt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"The Simple Life(stream)\n=======================\n[![Build Status](https://secure.travis-ci.org/mpratt/The-Simple-LifeStream.png?branch=master)](http://travis-ci.org/mpratt/The-Simple-LifeStream) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/mpratt/The-Simple-LifeStream/badges/quality-score.png?s=5ce8505d3304732575b54e37df6057333645040c)](https://scrutinizer-ci.com/g/mpratt/The-Simple-LifeStream/) [![Code Coverage](https://scrutinizer-ci.com/g/mpratt/The-Simple-LifeStream/badges/coverage.png?s=d3f6c51de6584f1ae196cb609bfaacd54c2e34be)](https://scrutinizer-ci.com/g/mpratt/The-Simple-LifeStream/) [![Latest Stable Version](https://poser.pugx.org/mpratt/simple-lifestream/version.png)](https://packagist.org/packages/mpratt/simple-lifestream) [![Total Downloads](https://poser.pugx.org/mpratt/simple-lifestream/downloads.png)](https://packagist.org/packages/mpratt/simple-lifestream)\n\nA very simple and flexible library for your life-streaming purposes. It supports a bunch of third party providers\nand makes it easy for you to display all that information in one single place.\n\nThe sweet thing about this library is that it only returns an array with all the important data (date, html, etc).\nThis empowers you to play with that information and display it however you like. A couple of formatters are also available\nand you can use them to ouput data in any way you like, see the examples below for more information.\n\nIn order to have a decent performance and avoid making too many requests to other sites the library uses internally a\nCache System based on files (file cache). The duration of each cache is 10 minutes by default, however you can modify\nthat behaviour easily.\n\nThe name of this library is inspired by that old cheap reality show with Paris Hilton and Nicole Ritchie.\n\nSupported Sites\n===============\n\n- DaliyMotion\n- Delicious\n- Deviantart\n- Dribble\n- FacebookPages\n- Atom/RSS Feeds\n- Github\n- GimmeBar\n- Reddit\n- StackExchange/StackOverflow\n- Twitter (Important! You have to [register an app](http://dev.twitter.com/apps) first)\n- Instagram (Important! You must [register an app](http://instagram.com/developer/) first.)\n- Pinboard (Important! You need to have an API Token. You can find yours on the [settings page](https://pinboard.in/settings/password))\n- Youtube\n\nFor a more detailed information about each provider read the [STREAMS.md](https://github.com/mpratt/The-Simple-LifeStream/blob/master/STREAMS.md) file.\n\nRemember that the Atom/RSS provider can be very useful, giving you the hability to fetch actions from sites that provide RSS/Atom feeds for user actions,\nlike for example Vimeo, Flickr, LastFM, Wordpress blogs, Blogger blogs and the list goes on.\n\nSo in Theory, there are many more sites that can be used to enhance your lifestream.\n\nRequirements\n============\n\n- PHP \u003e= 5.3\n- Curl or `allow_url_fopen` must be enabled\n\nInstallation\n============\n\n### Install with Composer\n\nIf you're using [Composer](https://github.com/composer/composer) to manage your\ndependencies, you can use this library by creating a composer.json and adding this:\n\n    {\n        \"require\": {\n            \"mpratt/simple-lifestream\": \"~4.0\"\n        }\n    }\n\nSave it and run `composer.phar install`\n\n### Standalone Installation (without Composer)\n\nDownload the latest release or clone this repository, place the `Lib/SimpleLifestream` directory on your project. Afterwards, you only need to include\nthe `Autoload.php` file.\n\n```php\n    require '/path/to/SimpleLifestream/Autoload.php';\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n```\n\nOr if you already have a PSR-0 complaint autoloader, you just need to register the library\n\n```php\n    $loader-\u003eregisterNamespace('SimpleLifestream', 'path/to/SimpleLifestream');\n```\n\nBasic Usage\n===========\n\nCreate an array with valid stream providers and pass it to the `SimpleLifestream` object.\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('Reddit', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Github', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Youtube', 'ERB'),\n        new \\SimpleLifestream\\Stream('StackOverflow', '430087'),\n        new \\SimpleLifestream\\Stream('FacebookPages', '27469195051'),\n        new \\SimpleLifestream\\Stream('Feed', 'http://www.michael-pratt/blog/rss/'),\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n    $lifestream-\u003eloadStreams($streams);\n\n    $data = $lifestream-\u003egetLifestream();\n    foreach ($data as $d) {\n        echo $d['html'];\n    }\n```\n\nThe `getLifestream(int 0)` method accepts a number, which can be used to limit the latest information you want to get.\n\n```php\n    $data = $lifestream-\u003egetLifestream(10);\n    echo count($data); // 10\n```\n\n### Configuration Directives\n\nThe `SimpleLifestream` constructor, accepts an array with configuration directives\nthat you can use to modify some parts of the library.\n\n```php\n    $config = array(\n        'date_format' =\u003e 'Y-m-d H:i', // Date format returned on by the streams\n        'link_format' =\u003e '\u003ca href=\"{url}\"\u003e{text}\u003c/a\u003e', // Link template used by the streams\n        'language' =\u003e 'English', // The Output language\n        'cache_ttl' =\u003e (60*10), // Optional: Duration of the cache in seconds\n        'cache_dir' =\u003e '/path/bla/bla', // Optional: A place where the cache should be stored\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream($config);\n```\n\nThis library has support for English and Spanish languages. If you want the\noutput to be in spanish, you just need to write:\n\n```php\n    $config = array(\n        'language' =\u003e 'Spanish',\n    );\n\n    $streams = array(\n        new \\SimpleLifestream\\Stream('Reddit', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Github', 'mpratt'),\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream($config);\n    $data = $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n\n    foreach ($data as $d) {\n        echo $d['html'];\n    }\n```\n\nStream Configuration\n====================\n\nThe `\\SimpleLifestream\\Stream` object requires two parameters. The first one is a string containing the name of the Provider.\nWhen an Invalid Provider is given, an `InvalidArgumentException` is thrown.\n\nThe second argument can be a string with the relevant resource/url/username or an array with important configuration options.\nThe regular way of registring a stream is:\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('Github', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Youtube', 'ERB'),\n    );\n```\n\nOr use an associative array with the `resource` key:\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('Github', array('resource' =\u003e 'mpratt')),\n        new \\SimpleLifestream\\Stream('Youtube', array('resource' =\u003e 'ERB')),\n    );\n```\n\nThe `resource` key is used internally and is interpreted as the relevant username/url/userid needed for\nthe provider.\n\nThat being said, some streams require additional information in order to work, lets take a look to the `Twitter` provider.\nRemember that if you wish to use the Twitter Provider, first you have to  [register an app](http://dev.twitter.com/apps).\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('twitter', array(\n            'consumer_key'    =\u003e 'your consumer key',\n            'consumer_secret' =\u003e 'your consumer secret',\n            'access_token' =\u003e 'you access token',\n            'access_token_secret' =\u003e 'your access token secret',\n            'resource' =\u003e 'your twitter username',\n        ))\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n    $output = $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n    print_r($output);\n```\n\nYou can use this technique on a few providers to modify their behaviour in some ways. Another example could be The `StackExchange` Provider.\nThe provider gives you access to all the sites inside the **StackExchange** web ring, not just StackOverflow. Let's say for example we want\nto get the data from a user in `http://programmers.stackexchange.com`.\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('StackExchange', array(\n            'site' =\u003e 'programmers',\n            'resource' =\u003e '430087',\n        ))\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n    $output = $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n    print_r($output);\n```\n\nFor More Information about streams and their individual configuration options read the [STREAMS.md](https://github.com/mpratt/The-Simple-LifeStream/blob/master/STREAMS.md) file.\n\nAdvanced Usage\n==============\n\n### Error Checking\n\nThere are 3 methods for error checking `bool hasErrors()`, `array getErrors()` and `string getLastError()`\n\n```php\n    $data = $lifestream-\u003egetLifestream();\n    if ($lifestream-\u003ehasErrors()) {\n        echo $lifestream-\u003egetLastError();\n    }\n\n    if ($lifestream-\u003ehasErrors()) {\n        var_dump($lifestream-\u003egetErrors());\n    }\n```\n\n### Accessing the Raw Response (Adding your own keys)\n\nAs of version 4.7.0, you can access the raw response from a provider and return custom keys for your own usage.\nYou can modify the response on a provider basis.\n\n```php\n    $streams = array(\n        new \\SimpleLifestream\\Stream('Reddit', array(\n            'resource' =\u003e 'mpratt',\n            'callback' =\u003e function ($value) {\n                return array(\n                    'modified_title' =\u003e str_replace(' ', '-', $value['data']['title'])\n                );\n            },\n        )),\n        new \\SimpleLifestream\\Stream('Github', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Youtube', 'ERB'),\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n    $output = $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n    print_r($output);\n```\n\nOr you can register the callback by using the `addCallback()` method of each stream.\n\n```php\n    $reddit = new \\SimpleLifestream\\Stream('Reddit', 'mpratt');\n    $reddit-\u003eaddCallback(function ($v) {\n        return array(\n            'modified_title' =\u003e str_replace(' ', '', $v['data']['title'])\n        );\n    });\n\n    $streams = array(\n        $reddit,\n        new \\SimpleLifestream\\Stream('Github', 'mpratt'),\n        new \\SimpleLifestream\\Stream('Youtube', 'ERB'),\n    );\n\n    $lifestream = new \\SimpleLifestream\\SimpleLifestream();\n    $output = $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n    print_r($output);\n```\n\n### Ignoring Actions/Types\n\nAs you can see, some services detect multiple actions, but in some cases you might not want to have\nall that information. You can ignore concrete actions using the `ignore()` method.\n\n```php\n    // Tell the library to Ignore all favorited actions/types\n    $lifestream-\u003eignore('favorited');\n\n    $data = $lifestream-\u003egetLifestream();\n```\n\nOr you can restrict the action to a particular stream provider\n\n```php\n    // Tell the library to Ignore all starred actions/types only from the Github Provider\n    $lifestream-\u003eignore('favorited', 'Github');\n\n    $data = $lifestream-\u003egetLifestream();\n```\n\n### Output Formatting\n\nLets talk about output formatters. There are 2 formatters (`HtmlList` and `Template`) that can help you\ndisplay the data in different ways.\n\nIn order to use them, you have to apply the decorator pattern. When doing this, the `getLifestream()` method gets\ntransformed and instead of returning an array with information, it returns a **string** with the requested data inside\na template.\n\nLet's have a look at the `HtmlList` decorator:\n\n```php\n    \u003c?php\n        $config = array();\n\n        $streams = array(\n            new \\SimpleLifestream\\Stream('Reddit', 'mpratt')\n        );\n\n        $lifestream = new \\SimpleLifestream\\SimpleLifestream($config);\n        $lifestream = new \\SimpleLifestream\\Formatters\\HtmlList($lifestream);\n        $lifestream-\u003eloadStreams($streams);\n        echo $lifestream-\u003egetLifestream(4);\n\n        /* This prints something around this lines:\n           \u003cul class=\"simplelifestream\"\u003e\n            \u003cli class=\"servicename\"\u003eY-m-d H:i - \u003ca href=\"...\"\u003etext 1\u003c/a\u003e\u003c/li\u003e\n            \u003cli class=\"servicename\"\u003eY-m-d H:i - \u003ca href=\"...\"\u003etext 2\u003c/a\u003e\u003c/li\u003e\n            \u003cli class=\"servicename\"\u003eY-m-d H:i - \u003ca href=\"...\"\u003etext 3\u003c/a\u003e\u003c/li\u003e\n            \u003cli class=\"servicename\"\u003eY-m-d H:i - \u003ca href=\"...\"\u003etext 4\u003c/a\u003e\u003c/li\u003e\n           \u003c/ul\u003e\n        */\n    ?\u003e\n```\n\nThe other decoration is named `Template` and is a little more flexible, you can use it define your own templates\nand with the help of some placeholders, you can interpolate the data fetched by the library.\n\n```php\n    \u003c?php\n        $lifestream = new \\SimpleLifestream\\Formatters\\Template(new \\SimpleLifestream\\SimpleLifestream());\n        $lifestream-\u003esetTemplate('\u003cdiv class=\"{service}\"\u003e{text} {link}\u003c/div\u003e');\n        echo $lifestream-\u003eloadStreams($streams)-\u003egetLifestream();\n\n        /* This prints something round this lines:\n            \u003cdiv class=\"servicename\"\u003ea text \u003ca href=\"..\"\u003ea link\u003c/a\u003e\u003c/div\u003e\n            \u003cdiv class=\"servicename\"\u003eanother text \u003ca href=\"..\"\u003ea link\u003c/a\u003e\u003c/div\u003e\n            \u003cdiv class=\"servicename\"\u003eand more text \u003ca href=\"..\"\u003ea link\u003c/a\u003e\u003c/div\u003e\n        */\n    ?\u003e\n```\n\nIf you want to see more examples of how to use this library take a peak inside the `Tests` directory and view the files.\nOtherwise inspect the source code of the library, I would say that it has \"decent\" english documentation and it should be easy to follow.\n\nLicense\n=======\nMIT\n\nFor the full copyright and license information, please view the LICENSE file.\n\nAuthor\n=====\n\n[Michael Pratt](http://www.michael-pratt.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpratt%2Fthe-simple-lifestream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpratt%2Fthe-simple-lifestream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpratt%2Fthe-simple-lifestream/lists"}