Move service model to handlers

This commit is contained in:
Frederic Guillot 2016-08-18 22:53:52 -04:00
parent 2b71bbf126
commit 8fa6d65614
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
6 changed files with 15 additions and 20 deletions

View File

@ -1,28 +1,26 @@
<?php <?php
namespace Model\Service; namespace Handler\Service;
use Model\Config;
use Model\Item;
use PicoFeed\Client\Client; use PicoFeed\Client\Client;
use PicoFeed\Client\ClientException; use PicoFeed\Client\ClientException;
use Model\Config;
use Model\Item;
// Sync the item to an external service function sync($item_id)
function push($item_id)
{ {
$item = Item\get($item_id); $item = Item\get($item_id);
if ((bool) Config\get('pinboard_enabled')) { if ((bool) Config\get('pinboard_enabled')) {
pinboard_add($item); pinboard_sync($item);
} }
if ((bool) Config\get('instapaper_enabled')) { if ((bool) Config\get('instapaper_enabled')) {
instapaper_add($item); instapaper_sync($item);
} }
} }
// Send item to Instapaper function instapaper_sync(array $item)
function instapaper_add(array $item)
{ {
$params = array( $params = array(
'username' => Config\get('instapaper_username'), 'username' => Config\get('instapaper_username'),
@ -42,8 +40,7 @@ function instapaper_add(array $item)
return false; return false;
} }
// Add a Pinboard bookmark function pinboard_sync(array $item)
function pinboard_add(array $item)
{ {
$params = array( $params = array(
'auth_token' => Config\get('pinboard_token'), 'auth_token' => Config\get('pinboard_token'),
@ -65,7 +62,6 @@ function pinboard_add(array $item)
return false; return false;
} }
// HTTP client
function api_call($url) function api_call($url)
{ {
try { try {

View File

@ -2,9 +2,9 @@
namespace Model\Bookmark; namespace Model\Bookmark;
use Model\Config;
use Model\Service;
use PicoDb\Database; use PicoDb\Database;
use Handler\Service;
use Model\Config;
function count_items($feed_ids = array()) function count_items($feed_ids = array())
{ {
@ -50,7 +50,7 @@ function get_all_items($offset = null, $limit = null, $feed_ids = array())
function set_flag($id, $value) function set_flag($id, $value)
{ {
if ($value == 1) { if ($value == 1) {
Service\push($id); Service\sync($id);
} }
return Database::getInstance('db') return Database::getInstance('db')

View File

@ -39,9 +39,9 @@
"app/core/session.php", "app/core/session.php",
"app/core/template.php", "app/core/template.php",
"app/handlers/scraper.php", "app/handlers/scraper.php",
"app/handlers/service.php",
"app/handlers/proxy.php", "app/handlers/proxy.php",
"app/models/config.php", "app/models/config.php",
"app/models/service.php",
"app/models/search.php", "app/models/search.php",
"app/models/user.php", "app/models/user.php",
"app/models/feed.php", "app/models/feed.php",

View File

@ -4,7 +4,6 @@ require __DIR__.'/../app/common.php';
use Model\Feed; use Model\Feed;
use Model\Group; use Model\Group;
use Model\Service;
use PicoDb\Database; use PicoDb\Database;
// Route handler // Route handler
@ -255,7 +254,7 @@ route('write_items', function () {
->eq('rowid', $_POST['id']) ->eq('rowid', $_POST['id'])
->findOneColumn('id'); ->findOneColumn('id');
Service\push($item_id); Handler\Service\sync($item_id);
} elseif ($_POST['as'] === 'unsaved') { } elseif ($_POST['as'] === 'unsaved') {
$query->update(array('bookmark' => 0)); $query->update(array('bookmark' => 0));
} elseif ($_POST['as'] === 'read') { } elseif ($_POST['as'] === 'read') {

View File

@ -20,9 +20,9 @@ return array(
'98faa6699f100c5ddb2013d85f9dfabb' => $baseDir . '/app/core/session.php', '98faa6699f100c5ddb2013d85f9dfabb' => $baseDir . '/app/core/session.php',
'93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php', '93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php',
'9de087554be89ca71a2ed558a4e35fde' => $baseDir . '/app/handlers/scraper.php', '9de087554be89ca71a2ed558a4e35fde' => $baseDir . '/app/handlers/scraper.php',
'45d63f4d04cfb927b889e126b91aa553' => $baseDir . '/app/handlers/service.php',
'081a26ac825aa2a7e4cb00c18e0510d5' => $baseDir . '/app/handlers/proxy.php', '081a26ac825aa2a7e4cb00c18e0510d5' => $baseDir . '/app/handlers/proxy.php',
'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php',
'c3080c7edf4a590ce36fc4f3561968dc' => $baseDir . '/app/models/service.php',
'b59348c9973f21f2c58eb493d9fea5be' => $baseDir . '/app/models/search.php', 'b59348c9973f21f2c58eb493d9fea5be' => $baseDir . '/app/models/search.php',
'73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php', '73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php',
'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php', 'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php',

View File

@ -21,9 +21,9 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4
'98faa6699f100c5ddb2013d85f9dfabb' => __DIR__ . '/../..' . '/app/core/session.php', '98faa6699f100c5ddb2013d85f9dfabb' => __DIR__ . '/../..' . '/app/core/session.php',
'93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php', '93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php',
'9de087554be89ca71a2ed558a4e35fde' => __DIR__ . '/../..' . '/app/handlers/scraper.php', '9de087554be89ca71a2ed558a4e35fde' => __DIR__ . '/../..' . '/app/handlers/scraper.php',
'45d63f4d04cfb927b889e126b91aa553' => __DIR__ . '/../..' . '/app/handlers/service.php',
'081a26ac825aa2a7e4cb00c18e0510d5' => __DIR__ . '/../..' . '/app/handlers/proxy.php', '081a26ac825aa2a7e4cb00c18e0510d5' => __DIR__ . '/../..' . '/app/handlers/proxy.php',
'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php',
'c3080c7edf4a590ce36fc4f3561968dc' => __DIR__ . '/../..' . '/app/models/service.php',
'b59348c9973f21f2c58eb493d9fea5be' => __DIR__ . '/../..' . '/app/models/search.php', 'b59348c9973f21f2c58eb493d9fea5be' => __DIR__ . '/../..' . '/app/models/search.php',
'73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php', '73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php',
'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php', 'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php',