diff --git a/lib/XRay/Formats/Hackernews.php b/lib/XRay/Formats/Hackernews.php index 6de9eb2..9a2bfe5 100644 --- a/lib/XRay/Formats/Hackernews.php +++ b/lib/XRay/Formats/Hackernews.php @@ -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']; } diff --git a/tests/HackernewsTest.php b/tests/HackernewsTest.php index 10b9e2f..22ea527 100644 --- a/tests/HackernewsTest.php +++ b/tests/HackernewsTest.php @@ -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'; diff --git a/tests/data/hacker-news.firebaseio.com/v0_item_27402392.json b/tests/data/hacker-news.firebaseio.com/v0_item_27402392.json new file mode 100644 index 0000000..6471f2a --- /dev/null +++ b/tests/data/hacker-news.firebaseio.com/v0_item_27402392.json @@ -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/"} \ No newline at end of file