Skip to content

Commit

Permalink
Merge pull request #50 from cachethq/rss-feed
Browse files Browse the repository at this point in the history
Adds RSS feed. Closes #26. No link or anything, but accessible at /rss
  • Loading branch information
manavo committed Nov 27, 2014
2 parents b7d4956 + 6d5ad36 commit 5dfa5d7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
'Dingo\Api\Provider\ApiServiceProvider',

'CachetHQ\Cachet\Support\ServiceProviders\RepositoryServiceProvider',

'Thujohn\Rss\RssServiceProvider',
),

/*
Expand Down Expand Up @@ -194,7 +194,8 @@
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',

'API' => 'Dingo\Api\Facades\API'
'API' => 'Dingo\Api\Facades\API',
'RSS' => 'Thujohn\Rss\RssFacade',

),

Expand Down
27 changes: 27 additions & 0 deletions app/controllers/RSSController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class RSSController extends Controller {
public function feedAction() {
$feed = RSS::feed('2.0', 'UTF-8');
$feed->channel([
'title' => Setting::get('app_name'),
'description' => 'Status Feed',
'link' => Setting::get('app_domain'),
]);

Incident::get()->map(function($incident) use ($feed) {
$feed->item([
'title' => $incident->name,
'message' => $incident->message,
'component' => $incident->parent->name,
'status' => $incident->humanStatus,
'created_at' => $incident->created_at,
'updated_at' => $incident->updated_at
]);
});

return Response::make($feed, 200, [
'Content-Type' => 'text/xml'
]);
}
}
5 changes: 4 additions & 1 deletion app/models/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI

protected $fillable = ['component', 'name', 'status', 'message'];

protected $appends = ['humanStatus'];

/**
* An incident belongs to a component.
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
Expand All @@ -29,7 +31,8 @@ public function parent() {
* @return string
*/
public function getHumanStatusAttribute() {
return Lang::get('incident.status' . $this->status);
$statuses = Lang::get('incident.status');
return $statuses[$this->status];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/routes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
// Authorization stuff.
Route::get('/auth/logout', 'AuthController@logoutAction');
});

Route::get('/rss', 'RSSController@feedAction');
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"laravel/framework": "4.2.*",
"guzzlehttp/guzzle": "~5.0",
"dingo/api": "0.7.*",
"watson/validating": "0.10.*"
"watson/validating": "0.10.*",
"thujohn/rss": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~4.3.0"
Expand Down
48 changes: 46 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5dfa5d7

Please sign in to comment.