Browse Source

Add the getItemsByStatus API call

master
George Baev 5 years ago
parent
commit
c4af4f47d9
No known key found for this signature in database
GPG Key ID: F5EA3C59671A4018
  1. 59
      docs/json-rpc-api.markdown
  2. 6
      jsonrpc.php
  3. 44
      tests/functional/ApiTest.php

59
docs/json-rpc-api.markdown

@ -410,7 +410,7 @@ Response example:
### getItems
- Purpose: **Get list o items**
- Purpose: **Get list of items**
- Parameters:
- **since_id** (integer, optional) Returns only feeds from this item id
- **item_ids** ([]integer, optional) Returns only items in this list
@ -433,6 +433,61 @@ Request example:
Response example:
```json
{
"jsonrpc": "2.0",
"result": [
{
"id": "3",
"checksum": "7f4b791f",
"title": "Miniflux 1.1.8 released",
"updated": "1442016000",
"url": "https:\/\/miniflux.net\/news\/version-1.1.8",
"enclosure_url": "",
"enclosure_type": "",
"bookmark": "0",
"feed_id": "1",
"status": "unread",
"content": "<ul>\n<li>Add feed groups (tags)<\/li>\n<li>Add custom rules directory support<\/li>\n<li>Add no referrer policy in meta tags and content security directives<\/li>\n<li>Update of PicoFeed with new scraper rules<\/li>\n<li>Enable Strict-Transport-Security header for HTTPS<\/li>\n<li>Change CSP directives to allow data url (Fix issue with Firefox 40)<\/li>\n<li>Toggle text direction for full content preview as well<\/li>\n<li>Add Russian translation<\/li>\n<li>Updated Czech translation<\/li>\n<li>Mark items on page 2+ read as well<\/li>\n<li>Allow to override the maximum feed size limit<\/li>\n<li>Added a config option to select how many concurrent refreshes are done on the subscription page<\/li>\n<li>Catch exceptions for image proxy<\/li>\n<li>Improve CSS for preview full content<\/li>\n<li>Minor feed edit dialog improvements<\/li>\n<li>Expose all feed errors to the frontend when adding a subscription<\/li>\n<li>Keep selected options on feed adding error<\/li>\n<li>Fix bug when the summery helper doesn&#039;t contains whitespace<\/li>\n<li>Fix Fever API bug: enable send bookmark to third-party services<\/li>\n<\/ul>\n<p><strong>Thanks to all contributors!<\/strong><\/p>\n<p><a href=\"https:\/\/miniflux.net\/miniflux-1.1.8.zip\" rel=\"noreferrer\" target=\"_blank\">Download archive<\/a><\/p>",
"language": "",
"rtl": "0",
"author": "Fr\u00e9d\u00e9ric Guillot",
"site_url": "https:\/\/miniflux.net\/",
"feed_title": "Miniflux"
},
[..]
],
"id":84429548
}
```
### getItemsByStatus
- Purpose: **Get list of items by status**
- Parameters:
- **status** (string)
- **feed_ids** ([]integer, optional) Returns only items from this list of feeds
- **offset** (integer, optional) Number of offset items (used for pagination)
- **limit** (integer, optional, default=50) Change number of items returned
- **order_column** (string, optional, default='updated') Order table column
- **order_direction** (string, optional, default='desc') Order direction
- Result on success: **list of item objects**
- Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "getItems",
"id": 84429548,
"params": {
"status": "unread"
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
@ -732,4 +787,4 @@ Response example:
],
"id": 1029539064
}
```
```

6
jsonrpc.php

@ -134,6 +134,12 @@ $procedureHandler->withCallback('getItems', function ($since_id = null, array $i
return Model\Item\get_items($user_id, $since_id, $item_ids, $limit);
});
// Get items by status
$procedureHandler->withCallback('getItemsByStatus', function ($status, array $feed_ids = array(), $offset = null, $limit = 50, $order_column = 'updated', $order_direction = 'desc') {
$user_id = SessionStorage::getInstance()->getUserId();
return Model\Item\get_items_by_status($user_id, $status, $feed_ids, $offset, $limit, $order_column, $order_direction);
});
// Get one item
$procedureHandler->withCallback('getItem', function ($item_id) {
$user_id = SessionStorage::getInstance()->getUserId();

44
tests/functional/ApiTest.php

@ -101,6 +101,50 @@ class ApiTest extends BaseApiTest
$this->assertNotEmpty($items[0]['url']);
}
public function testGetItemsByStatusUnread()
{
$items = $this->getApiClient()->getItemsByStatus(array('status' => 'unread'));
$this->assertNotEmpty($items);
$this->assertEquals(1, $items[0]['id']);
$this->assertEquals(1, $items[0]['feed_id']);
$this->assertNotEmpty($items[0]['title']);
$this->assertNotEmpty($items[0]['author']);
$this->assertNotEmpty($items[0]['content']);
$this->assertNotEmpty($items[0]['url']);
$this->assertEquals('unread', $items[0]['status']);
}
public function testGetItemsByStatusRead()
{
$items = $this->getApiClient()->getItemsByStatus(array('status' => 'read'));
$this->assertEmpty($items);
}
public function testGetItemsByFeedIds()
{
$items = $this->getApiClient()->getItemsByStatus(array(
'status' => 'unread',
'feed_ids' => array(1)
));
$this->assertNotEmpty($items);
$this->assertEquals(1, $items[0]['id']);
$this->assertEquals(1, $items[0]['feed_id']);
$this->assertNotEmpty($items[0]['title']);
$this->assertNotEmpty($items[0]['author']);
$this->assertNotEmpty($items[0]['content']);
$this->assertNotEmpty($items[0]['url']);
$this->assertEquals('unread', $items[0]['status']);
}
public function testGetItemsByFeedIdsNonExist()
{
$items = $this->getApiClient()->getItemsByStatus(array(
'status' => 'unread',
'feed_ids' => array(2)
));
$this->assertEmpty($items);
}
public function testGetItemsSinceId()
{
$items = $this->getApiClient()->getItems(array('since_id' => 2));

Loading…
Cancel
Save