Merge pull request #13 from jbrooksuk/webhooks

Webhooks
This commit is contained in:
James Brooks
2014-11-22 14:02:17 +00:00
5 changed files with 99 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateWebHooksTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('web_hooks', function(Blueprint $table)
{
$table->increments('id');
$table->string('name')->nullable(FALSE);
$table->string('endpoint')->nullable(FALSE);
$table->tinyInteger('hook_type')->default(0); // When should this web hook be called?
$table->tinyInteger('request_type')->default(0); // ENUM: GET, POST, PUT, DELETE etc
$table->boolean('active')->default(0);
$table->timestamps();
$table->softDeletes();
// Indexes
$table->index('active');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('web_hooks');
}
}

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateWebHookResponsesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('web_hook_response', function(Blueprint $table)
{
$table->increments('id');
$table->integer('hook_id')->unsigned();
$table->tinyInteger('response_code')->nullable(FALSE); // This should return something like 200, 301 etc.
$table->string('response_type'); // application/json etc.
$table->text('sent_headers');
$table->longText('sent_body'); // What we sent the web hook
$table->text('recv_headers');
$table->longText('recv_body'); // Potentially a big response will be returned
$table->float('time_taken')->default(0); // How long did the request take, in seconds.
$table->timestamps();
$table->index('hook_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('web_hook_response');
}
}

7
app/models/WebHook.php Normal file
View File

@@ -0,0 +1,7 @@
<?php
class WebHook extends Eloquent {
public function response() {
return $this->hasMany('WebHookContent', 'hook_id', 'id');
}
}

View File

@@ -0,0 +1,7 @@
<?php
class WebHookContent extends Eloquent {
public function hook() {
return $this->belongsTo('WebHook', 'id', 'hook_id');
}
}

View File

@@ -5,7 +5,8 @@
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
"laravel/framework": "4.2.*",
"guzzlehttp/guzzle": "4.*"
},
"autoload": {
"classmap": [