Use JSON response for q=syndicate-to request
This commit is contained in:
parent
4f30955758
commit
88b30bb815
5 changed files with 26 additions and 16 deletions
|
@ -37,9 +37,7 @@ class MicropubClientController extends Controller
|
|||
public function newNotePage(Request $request)
|
||||
{
|
||||
$url = $request->session()->get('me');
|
||||
$syndication = $this->parseSyndicationTargets(
|
||||
$request->session()->get('syndication')
|
||||
);
|
||||
$syndication = $request->session()->get('syndication');
|
||||
|
||||
return view('micropubnewnotepage', [
|
||||
'url' => $url,
|
||||
|
@ -113,7 +111,7 @@ class MicropubClientController extends Controller
|
|||
return redirect('notes/new')->withErrors('Bad response when refreshing syndication targets', 'endpoint');
|
||||
}
|
||||
$body = (string) $response->getBody();
|
||||
$syndication = str_replace(['&', '[]'], [';', ''], $body);
|
||||
$syndication = $this->parseSyndicationTargets($body);
|
||||
|
||||
$request->session()->put('syndication', $syndication);
|
||||
|
||||
|
@ -321,10 +319,9 @@ class MicropubClientController extends Controller
|
|||
return;
|
||||
}
|
||||
$syndicateTo = [];
|
||||
$parts = explode(';', $syndicationTargets);
|
||||
foreach ($parts as $part) {
|
||||
$target = explode('=', $part);
|
||||
$syndicateTo[] = urldecode($target[1]);
|
||||
$data = json_decode($syndicationTargets, true);
|
||||
foreach ($syndicateTo['syndicate-to'] as $syn) {
|
||||
$syndicateTo[] = $syn['uid'];
|
||||
}
|
||||
if (count($syndicateTo) > 0) {
|
||||
return $syndicateTo;
|
||||
|
|
|
@ -108,12 +108,22 @@ class MicropubController extends Controller
|
|||
}
|
||||
//we have a valid token, is `syndicate-to` set?
|
||||
if ($request->input('q') === 'syndicate-to') {
|
||||
$content = http_build_query([
|
||||
'syndicate-to' => 'twitter.com/jonnybarnes',
|
||||
return response()->json([
|
||||
'syndicate-to' => [[
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'name' => 'jonnybarnes on Twitter',
|
||||
'service' => [
|
||||
'name' => 'Twitter',
|
||||
'url' => 'https://twitter.com',
|
||||
'photo' => 'https://upload.wikimedia.org/wikipedia/en/9/9f/Twitter_bird_logo_2012.svg',
|
||||
],
|
||||
'user' => [
|
||||
'name' => 'jonnybarnes',
|
||||
'url' => 'https://twitter.com/jonnybarnes',
|
||||
'photo' => 'https://pbs.twimg.com/profile_images/1853565405/jmb-bw.jpg',
|
||||
],
|
||||
]],
|
||||
]);
|
||||
|
||||
return (new Response($content, 200))
|
||||
->header('Content-Type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
//nope, how about a geo URL?
|
||||
if (substr($request->input('q'), 0, 4) === 'geo:') {
|
||||
|
|
|
@ -50,9 +50,9 @@ class NoteService
|
|||
if (//micropub request, syndication sent as array
|
||||
(is_array($request->input('syndicate-to'))
|
||||
&&
|
||||
(in_array('twitter.com/jonnybarnes', $request->input('syndicate-to')))
|
||||
(in_array('https://twitter.com/jonnybarnes', $request->input('syndicate-to')))
|
||||
|| //micropub request, syndication sent as string
|
||||
($request->input('syndicate-to') == 'twitter.com/jonnybarnes')
|
||||
($request->input('syndicate-to') == 'https://twitter.com/jonnybarnes')
|
||||
|| //local admin cp request
|
||||
($request->input('twitter') == true))
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## Version {next}
|
||||
- Use JSON for syndication endpoint query response
|
||||
|
||||
## Version 0.0.6.3 (2016-06-29)
|
||||
- Fix an issue with dispatching the syndication job
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class MicropubTest extends TestCase
|
|||
public function testMicropubRequestForSyndication()
|
||||
{
|
||||
$this->call('GET', $this->appurl . '/api/post', ['q' => 'syndicate-to'], [], [], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
|
||||
$this->see('twitter.com%2Fjonnybarnes');
|
||||
$this->seeJson(['uid' => 'https://twitter.com/jonnybarnes']);
|
||||
}
|
||||
|
||||
public function testMicropubRequestForNearbyPlacesThatExist()
|
||||
|
|
Loading…
Add table
Reference in a new issue