Skip to content

Commit

Permalink
Revert "Merge pull request #1665 from ushahidi/1550-platform-api-rece…
Browse files Browse the repository at this point in the history
…ive"

This reverts commit 50b6759, reversing
changes made to 708b522.
  • Loading branch information
tuxpiper committed Mar 27, 2018
1 parent 1dbafad commit a1cd291
Show file tree
Hide file tree
Showing 49 changed files with 155 additions and 1,141 deletions.
18 changes: 0 additions & 18 deletions application/classes/Controller/Api/Apikeys.php

This file was deleted.

67 changes: 0 additions & 67 deletions application/classes/Controller/Api/Webhooks/Posts.php

This file was deleted.

47 changes: 14 additions & 33 deletions application/classes/Ushahidi/Console/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,46 +105,27 @@ 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);
$json = json_encode($post->asArray());

// Get webhook data
$webhooks = $this->webhookRepository->getAllByEventType($webhook_request->event_type);
$webhook = $this->webhookRepository->getByEventType($webhook_request->event_type);

foreach ($webhooks as $webhook) {
$this->signer = new Signer($webhook->shared_secret);

if ($post->form_id == $webhook['form_id']) {
$this->signer = new Signer($webhook['shared_secret']);
$signature = $this->signer->sign($webhook->url, $json);

$data = $post->asArray();

// Attach Webhook Uuid so that service can subsequently identify itself
// when sending data to the Platform
$data['webhook_uuid'] = $webhook['webhook_uuid'];

// If set append the source and destination fields to the request
// These fields identify the UUIDs of the Post fields which the remot service should
// treat as the source of data and the destination for any data to be posted back to the Platform
$data['source_field_key'] = $webhook['source_field_key'] ?: null;
$data['destination_field_key'] = $webhook['destination_field_key'] ?: null;

$json = json_encode($data);
$signature = $this->signer->sign($webhook['url'], $json);

// This is an asynchronous request, we don't expect a result
// this can be extended to allow for handling of the returned promise
//TODO: HANDLE HTTP ERRORS
$promise = $this->client->request('POST', $webhook['url'], [
'headers' => [
'X-Ushahidi-Signature' => $signature,
'Accept' => 'application/json'
],
'json' => $data
]);

}
}
// 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->request('POST', $webhook->url, [
'headers' => [
'X-Platform-Signature' => $signature,
'Accept' => 'application/json'
],
'json' => $post->asArray()
]);
}
}
10 changes: 1 addition & 9 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public static function init()
];
$di->params['Ushahidi\Factory\ValidatorFactory']['map']['posts'] = [
'create' => $di->lazyNew('Ushahidi_Validator_Post_Create'),
'webhook-update' => $di->lazyNew('Ushahidi_Validator_Post_Update'),
'update' => $di->lazyNew('Ushahidi_Validator_Post_Update'),
'import' => $di->lazyNew('Ushahidi_Validator_Post_Import'),
];
Expand Down Expand Up @@ -288,10 +287,6 @@ public static function init()
'create' => $di->lazyNew('Ushahidi_Validator_Notification_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_Notification_Update'),
];
$di->params['Ushahidi\Factory\ValidatorFactory']['map']['apikeys'] = [
'create' => $di->lazyNew('Ushahidi_Validator_ApiKey_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_ApiKey_Update'),
];
$di->params['Ushahidi\Factory\ValidatorFactory']['map']['webhooks'] = [
'create' => $di->lazyNew('Ushahidi_Validator_Webhook_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_Webhook_Update'),
Expand Down Expand Up @@ -344,8 +339,7 @@ public static function init()
'savedsearches_posts' => $di->lazyNew('Ushahidi_Formatter_Post'),
'users' => $di->lazyNew('Ushahidi_Formatter_User'),
'notifications' => $di->lazyNew('Ushahidi_Formatter_Notification'),
'webhooks' => $di->lazyNew('Ushahidi_Formatter_Webhook'),
'apikeys' => $di->lazyNew('Ushahidi_Formatter_Apikey'),
'webhooks' => $di->lazyNew('Ushahidi_Formatter_Webhook'),
'contacts' => $di->lazyNew('Ushahidi_Formatter_Contact'),
'csv' => $di->lazyNew('Ushahidi_Formatter_CSV'),
'roles' => $di->lazyNew('Ushahidi_Formatter_Role'),
Expand Down Expand Up @@ -374,7 +368,6 @@ public static function init()
'set_post',
'notification',
'webhook',
'apikey',
'contact',
'role',
'permission',
Expand Down Expand Up @@ -443,7 +436,6 @@ public static function init()
$di->set('repository.role', $di->lazyNew('Ushahidi_Repository_Role'));
$di->set('repository.notification', $di->lazyNew('Ushahidi_Repository_Notification'));
$di->set('repository.webhook', $di->lazyNew('Ushahidi_Repository_Webhook'));
$di->set('repository.apikey', $di->lazyNew('Ushahidi_Repository_ApiKey'));
$di->set('repository.csv', $di->lazyNew('Ushahidi_Repository_CSV'));
$di->set('repository.notification.queue', $di->lazyNew('Ushahidi_Repository_Notification_Queue'));
$di->set('repository.webhook.job', $di->lazyNew('Ushahidi_Repository_Webhook_Job'));
Expand Down
4 changes: 2 additions & 2 deletions application/classes/Ushahidi/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function send($to, $message, $title = "")
* @param string data_provider_message_id Message ID
* @return void
*/
public function receive($type, $from, $message, $to = NULL, $title = NULL, $date = NULL, $data_provider_message_id = NULL, Array $additional_data = NULL)
public function receive($type, $from, $message, $to = NULL, $title = NULL, $data_provider_message_id = NULL, Array $additional_data = NULL)
{
$data_provider = $this->provider_name();
$contact_type = $this->contact_type;

$usecase = service('factory.usecase')->get('messages', 'receive');
try
{
$usecase->setPayload(compact(['type', 'from', 'message', 'to', 'title', 'date', 'data_provider_message_id', 'data_provider', 'contact_type', 'additional_data']))
$usecase->setPayload(compact(['type', 'from', 'message', 'to', 'title', 'data_provider_message_id', 'data_provider', 'contact_type', 'additional_data']))
->interact();
}
catch (Ushahidi\Core\Exception\NotFoundException $e)
Expand Down
17 changes: 0 additions & 17 deletions application/classes/Ushahidi/Formatter/Apikey.php

This file was deleted.

88 changes: 0 additions & 88 deletions application/classes/Ushahidi/Repository/ApiKey.php

This file was deleted.

Loading

0 comments on commit a1cd291

Please sign in to comment.