Browse Source

add bookmark-of property for hackernews posts

pull/93/merge
Aaron Parecki 6 months ago
parent
commit
9c0a8ba48b
3 changed files with 32 additions and 1 deletions
  1. +5
    -1
      lib/XRay/Formats/Hackernews.php
  2. +16
    -0
      tests/HackernewsTest.php
  3. +11
    -0
      tests/data/hacker-news.firebaseio.com/v0_item_27402392.json

+ 5
- 1
lib/XRay/Formats/Hackernews.php View File

@ -61,9 +61,13 @@ class Hackernews extends Format {
'photo' => null,
'url' => 'https://news.ycombinator.com/user?id='.$data['by']
],
'published' => $date->format('c')
'published' => $date->format('c'),
);
if(isset($data['url'])) {
$entry['bookmark-of'] = [$data['url']];
}
if(isset($data['title'])) {
$entry['name'] = $data['title'];
}

+ 16
- 0
tests/HackernewsTest.php View File

@ -21,6 +21,22 @@ class HackernewsTest extends PHPUnit\Framework\TestCase
return $this->client->parse($request, $response);
}
public function testBookmark()
{
$url = 'https://news.ycombinator.com/item?id=27402392';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('hackernews', $data['source-format']);
$this->assertEquals(['https://kevincox.ca/2021/06/04/http-range-caching/'], $data['data']['bookmark-of']);
$this->assertEquals('The Impossibility of Perfectly Caching HTTP Range Requests', $data['data']['name']);
}
public function testSubmission()
{
$url = 'https://news.ycombinator.com/item?id=14516538';

+ 11
- 0
tests/data/hacker-news.firebaseio.com/v0_item_27402392.json View File

@ -0,0 +1,11 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 09 Jun 2017 14:30:19 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 1701
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
{"by":"giuliomagnifico","descendants":0,"id":27402392,"score":2,"time":1622869705,"title":"The Impossibility of Perfectly Caching HTTP Range Requests","type":"story","url":"https://kevincox.ca/2021/06/04/http-range-caching/"}

Loading…
Cancel
Save