kgengler / laravel-feed-client by kgengler

An Atom and RSS feed client for the Laravel Framework
18
1
1
Package Data
Maintainer Username: kgengler
Maintainer Contact: kyle.gengler@gmail.com (Kyle Gengler)
Package Create Date: 2016-12-04
Package Last Update: 2017-03-28
Language: PHP
License: MIT
Last Refreshed: 2024-04-30 03:04:16
Package Statistics
Total Downloads: 18
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 1
Total Open Issues: 1

Feed Client Laravel Service Provider

Packagist

This branch is for Laravel 4.x

An Atom and RSS feed client for the Laravel Framework

Installation

Add the following line to the require section of composer.json:

{
    "require": {
        "kgengler/feed-client": "4.*"
    }
}

Run composer update.

Configuration

Publish the package configuration using Artisan.

php artisan config:publish kgengler/feed-client

Find the providers key in your app/config/app.php and register the Feed Client Service Provider.

'providers' => array(
    // ...
    'Kgengler\FeedClient\FeedClientServiceProvider',
)

Find the aliases key in your app/config/app.php and add the Feed Client facade alias.

'aliases' => array(
    // ...
    'FeedClient' => 'Kgengler\FeedClient\FeedClientFacade'
)

Open the configuration file in app/config/packages/kgengler/feed-client/config.php, and add the feed you need to access

<?php
// app/config/packages/kgengler/feed-client/config.php

return array(
    // The `laravel` key here is used to fetch the feed later. You can specify multiple
    // feeds, just use another key.
    'laravel' => array(
        
        // Feed type, either `atom` or `rss`
        // Required
        // Default: none
        'type'          => 'atom',
        
        // Url of the feed
        // Required
        // Default: none
        'url'           => 'https://github.com/laravel/laravel/commits/master.atom',
        
        // username required to access feed
        // Optional
        // Default: null
        'user'          => null,
        
        // password required to access feed
        // Optional
        // Default: null
        'password'      => null,
        
        // whether or not to cache the feed locally. I would recommend leaving this
        // on, unless you plan on caching it yourself. It will use whatever cache
        // driver you have specified for your application.
        // Optional
        // Default: true
        'cached'        => true,
        
        // time in minutes to cache feed
        // Optional
        // Default: 60
        'cacheTimeout'  => 60
    )
);

Usage

Fetch the client from the Laravel IOC Container and get the feed with the key you provided in the configuration file:

$feed_client = App::make('feed-client');
$feed = $feed_client->get('laravel');

// or with the Facade
$feed = FeedClient::get('laravel');

Access methods to get the information from the feed:

$feed->getTitle(); // Feed Title
$feed->getDescription(); // Feed Description
$feed->getLink(); // Link to feed

$feed_items = $feed->getItems(); // Items in feed

// Feed items are given as a collection of FeedItem objects
foreach($feed_items as $item) {
    $item->getTitle(); // Item Title
    $item->getTime(); // Publication Time as DateTime object
    $item->getLink(); // Get link for Item
    $item->getDescription(); // Item Description
}