Skip to content

Commit

Permalink
Adjusting Webhook behaviour to use asynchronous requests
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed Mar 26, 2017
1 parent 512d164 commit 640f81b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions application/classes/Ushahidi/Console/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function configure()
->setName('webhook')
->setDescription('Manage webhook requests')
->addArgument('action', InputArgument::OPTIONAL, 'list, send', 'list')
//->addOption('limit', ['l'], InputOption::VALUE_OPTIONAL, 'number of webhook requests to be sent')
->addOption('limit', ['l'], InputOption::VALUE_OPTIONAL, 'number of webhook requests to be sent')
;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ protected function executeSend(InputInterface $input, OutputInterface $output)
private function generateRequest($webhook_request)
{
// Delete queued webhook request
$this->webhookJobRepository->delete($webhook_request);
//$this->webhookJobRepository->delete($webhook_request);

// Get post data
$post = $this->postRepository->get($webhook_request->post_id);
Expand All @@ -123,12 +123,15 @@ private function generateRequest($webhook_request)
$this->signer = new Signer($webhook->shared_secret);

$signature = $this->signer->sign($webhook->url, $json);
$headers = ['X-Platform-Signature' => $signature];

$request = new Request('POST', $webhook->url, $headers, $json);
// $this->client->sendAsync($request);
$this->client->send($request);
return $request;

// This is an asynchronous request, we don't expect a result
// this can be extended to allow for handling of the returned promise
$promise = $this->client->requestAsync('POST', $webhook->url, [
'headers' => [
'X-Platform-Signature' => $signature,
'Accept' => 'application/json'
],
'json' => $post->asArray()
]);
}
}

0 comments on commit 640f81b

Please sign in to comment.