summaryrefslogtreecommitdiff
path: root/providers/Untappd.php
diff options
context:
space:
mode:
Diffstat (limited to 'providers/Untappd.php')
-rw-r--r--providers/Untappd.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/providers/Untappd.php b/providers/Untappd.php
new file mode 100644
index 0000000..95c7ab7
--- /dev/null
+++ b/providers/Untappd.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Providers;
+
+require_once('HtmlFeed.php');
+require_once('Item.php');
+
+class Untappd extends \Providers\HtmlFeed {
+
+ protected $_cacheTimeout = '5 minutes';
+
+ protected function _getCachePath() {
+ return '../cache/untappd.%s';
+ }
+
+ protected function _getFeedUrl($feed) {
+ return sprintf('https://untappd.com/%s/beer?sort=created_at_desc', $feed);
+ }
+
+ protected function _parseFeedContent($tree) {
+ $items = [];
+ $parents = [];
+ foreach ($tree->find('div.beer-item') as $div) {
+ $details = $div->find('div.beer-details, div.details');
+ if ($details) {
+ $texts = [
+ $details->find('p.name')->text(),
+ $details->find('p.style')->text(),
+ $details->find('p.desc')->eq(1)->text(),
+ $details->find('p.abv')->text(),
+ $details->find('p.ibu')->text()
+ ];
+ $items[] = [
+ 'id' => $div->attr()['data-bid'],
+ 'link' => $div->find('a.label')->attr()['href'],
+ 'name' => $texts[0],
+ 'texts' => $texts,
+ 'time' => trim($details->find('p.date')->text())
+ ];
+ }
+ }
+ return array_values($items);
+ }
+
+ protected function _mapItems($content) {
+ return array_map(
+ function ($obj) {
+ $item = new Item();
+ $item->ID = $obj['id'];
+ $item->Link = sprintf('https://untappd.com/%s', $obj['link']);
+ $item->Title = sprintf('New beer by %s: %s', $this->_feed, $obj['name']);
+ $item->Text = implode('<br />', $obj['texts']);
+ $item->Time = strtotime(str_replace('Added ', '', $obj['time']) . ' 00:00:00');
+ return $item;
+ },
+ $content
+ );
+ }
+
+ public function title() {
+ return sprintf("%s's untappd beer list", $this->_feed);
+ }
+
+}
+
+?>