Skip to content

Commit

Permalink
add follow-of posts
Browse files Browse the repository at this point in the history
replaces #78
  • Loading branch information
aaronpk committed Nov 9, 2018
1 parent 8043ba5 commit 87b2cf1
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ If a property supports multiple values, it will always be returned as an array.
* `like-of`
* `repost-of`
* `bookmark-of`
* `follow-of`
* `syndication`
* `photo` (of an entry, not of a card)
* `video`
Expand All @@ -410,6 +411,7 @@ The following post types are returned, which are slightly expanded from what is
* `like`
* `reply`
* `bookmark`
* `follow`
* `checkin`
* `video`
* `audio`
Expand Down
2 changes: 1 addition & 1 deletion lib/XRay/Formats/Mf2.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private static function parseAsHEntry($mf2, $item, $http, $url) {
$refs = [];

// Single plaintext and URL values
self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url','featured'], $item, $url, $data);
self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url','featured','follow-of'], $item, $url, $data);

if(isset($data['rsvp']))
$data['rsvp'] = strtolower($data['rsvp']);
Expand Down
3 changes: 3 additions & 0 deletions lib/XRay/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static function discover($post) {
if(isset($post['bookmark-of']))
return 'bookmark';

if(isset($post['follow-of']))
return 'follow';

if(isset($post['checkin']))
return 'checkin';

Expand Down
23 changes: 23 additions & 0 deletions tests/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,27 @@ public function testMultipleContentTypeHeaders() {
$this->assertEquals('mf2+html', $data['source-format']);
}

public function testFollowOf() {
$url = 'http://source.example.com/bridgy-follow';
$response = $this->parse(['url' => $url]);

$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);

$this->assertEquals('https://realize.be/', $data['data']['follow-of']);
$this->assertEquals('follow', $data['data']['post-type']);
}

public function testFollowOfHCard() {
$url = 'http://source.example.com/follow-of-h-card';
$response = $this->parse(['url' => $url]);

$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);

$this->assertEquals('https://realize.be/', $data['data']['follow-of']);
$this->assertEquals('follow', $data['data']['post-type']);
}
}
38 changes: 38 additions & 0 deletions tests/data/source.example.com/bridgy-follow
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<article class="h-entry">
<span class="p-uid">https://mastodon.social/b8177a60-8f80-47a0-b943-a9df876cf5d5</span>



<span class="p-author h-card">
<data class="p-uid" value="https://mastodon.social/users/swentel"></data>
<a class="u-url" href="https://mastodon.social/@swentel">https://mastodon.social/@swentel</a>


</span>

<span class="p-name"></span>
<div class="">


</div>





<a class="u-follow-of" href="https://realize.be/"></a>

</article>

</body>
</html>
38 changes: 38 additions & 0 deletions tests/data/source.example.com/follow-of-h-card
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<article class="h-entry">
<span class="p-uid">https://mastodon.social/b8177a60-8f80-47a0-b943-a9df876cf5d5</span>



<span class="p-author h-card">
<data class="p-uid" value="https://mastodon.social/users/swentel"></data>
<a class="u-url" href="https://mastodon.social/@swentel">https://mastodon.social/@swentel</a>


</span>

<span class="p-name"></span>
<div class="">


</div>





<a class="u-follow-of h-card" href="https://realize.be/">swentel</a>

</article>

</body>
</html>

0 comments on commit 87b2cf1

Please sign in to comment.