'],
68 | ['url', 'url'],
69 | ['method', 'in', 'range' => ['GET', 'POST', 'PUT', 'DELETE']],
70 | ];
71 | }
72 |
73 | public function httpMethodValidation()
74 | {
75 | }
76 |
77 | public function attributeLabels()
78 | {
79 | return [
80 | 'id' => 'ID',
81 | 'event' => 'Event',
82 | 'description' => 'Description',
83 | 'url' => 'Url',
84 | 'method' => 'Method',
85 | 'created_at' => 'Created At',
86 | 'updated_at' => 'Updated At',
87 | ];
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/models/WebhookLog.php:
--------------------------------------------------------------------------------
1 | 255],
45 | [['webhook_method'], 'string', 'max' => 10],
46 | ];
47 | }
48 |
49 | /**
50 | * {@inheritdoc}
51 | */
52 | public function attributeLabels()
53 | {
54 | return [
55 | 'id' => 'ID',
56 | 'log_time' => 'Log Time',
57 | 'webhook_event' => 'Webhook Event',
58 | 'webhook_method' => 'Webhook Method',
59 | 'webhook_url' => 'Webhook Url',
60 | 'request_headers' => 'Request Headers',
61 | 'request_payload' => 'Request Payload',
62 | 'response_headers' => 'Response Headers',
63 | 'response_status_code' => 'Response Status Code',
64 | ];
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/models/WebhookLogSearch.php:
--------------------------------------------------------------------------------
1 | $query,
50 | 'sort' => [
51 | 'defaultOrder' => [
52 | 'id' => SORT_DESC
53 | ],
54 | ]
55 | ]);
56 |
57 | $this->load($params);
58 |
59 | if (!$this->validate()) {
60 | // uncomment the following line if you do not want to return any records when validation fails
61 | // $query->where('0=1');
62 | return $dataProvider;
63 | }
64 |
65 | // grid filtering conditions
66 | $query->andFilterWhere([
67 | 'id' => $this->id,
68 | 'log_time' => $this->log_time,
69 | 'response_status_code' => $this->response_status_code,
70 | ]);
71 |
72 | $query->andFilterWhere(['like', 'webhook_event', $this->webhook_event])
73 | ->andFilterWhere(['like', 'webhook_method', $this->webhook_method])
74 | ->andFilterWhere(['like', 'webhook_url', $this->webhook_url])
75 | ->andFilterWhere(['like', 'request_headers', $this->request_headers])
76 | ->andFilterWhere(['like', 'request_payload', $this->request_payload])
77 | ->andFilterWhere(['like', 'response_headers', $this->response_headers]);
78 |
79 | return $dataProvider;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/models/WebhookQuery.php:
--------------------------------------------------------------------------------
1 | $query,
30 | 'sort' => [
31 | 'defaultOrder' => [
32 | 'id' => SORT_DESC
33 | ],
34 | ]
35 | ]);
36 |
37 | $this->load($params);
38 |
39 | if (!$this->validate()) {
40 | return $dataProvider;
41 | }
42 |
43 | // grid filtering conditions
44 | $query->andFilterWhere([
45 | 'id' => $this->id,
46 | 'created_at' => $this->created_at,
47 | 'updated_at' => $this->updated_at,
48 | ]);
49 |
50 | $query->andFilterWhere(['like', 'event', $this->event])
51 | ->andFilterWhere(['like', 'description', $this->description])
52 | ->andFilterWhere(['like', 'url', $this->url])
53 | ->andFilterWhere(['like', 'method', $this->method]);
54 |
55 | return $dataProvider;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/views/layouts/main.php:
--------------------------------------------------------------------------------
1 |
15 | beginPage() ?>
16 |
17 |
18 |
19 |
20 |
21 |
22 | = Html::csrfMetaTags() ?>
23 | = Html::encode($this->title) ?>
24 | head() ?>
25 |
26 |
27 | beginBody() ?>
28 |
29 |
30 | 'yii2-webhooks',
33 | 'brandUrl' => \yii\helpers\Url::toRoute(['webhook/index']),
34 | 'options' => [
35 | 'class' => 'navbar-inverse navbar-fixed-top',
36 | ],
37 | ]);
38 | $menuItems = [
39 | ['label' => 'Webhooks', 'url' => Url::toRoute(['/webhooks'])],
40 | ['label' => 'Webhook Logs', 'url' => Url::toRoute(['webhook-log/index'])],
41 | ['label' => ' ← Back to App', 'url' => Yii::$app->homeUrl],
42 | ];
43 |
44 | echo Nav::widget([
45 | 'options' => ['class' => 'navbar-nav navbar-right'],
46 | 'items' => $menuItems,
47 | ]);
48 | NavBar::end();
49 | ?>
50 |
51 |
52 | = Breadcrumbs::widget([
53 | 'homeLink' => [
54 | 'label' => 'yii2-webhooks',
55 | 'url' => Url::toRoute(['/webhooks'])
56 | ],
57 | 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
58 | ]) ?>
59 | = Alert::widget() ?>
60 | = $content ?>
61 |
62 |
63 |
64 |
71 |
72 | endBody() ?>
73 |
74 |
75 | endPage() ?>
76 |
--------------------------------------------------------------------------------
/src/views/webhook-log/index.php:
--------------------------------------------------------------------------------
1 | title = 'Webhook Logs';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 | = GridView::widget([
18 | 'dataProvider' => $dataProvider,
19 | 'filterModel' => $searchModel,
20 | 'columns' => [
21 | 'id',
22 | 'log_time:datetime',
23 | [
24 | 'attribute' => 'response_status_code',
25 | 'content' => function($model) {
26 | if($model->response_status_code === 200) {
27 | return ''.$model->response_status_code.'';
28 | }
29 | return ''.$model->response_status_code.'';
30 | }
31 | ],
32 | 'webhook_event',
33 | 'webhook_method',
34 | 'webhook_url:url',
35 | [
36 | 'class' => 'yii\grid\ActionColumn',
37 | 'buttons' => [
38 | 'view' => function ($url, $model) {
39 | return Html::a('', $url, [
40 | 'title' => Yii::t('app', 'lead-view'),
41 | ]);
42 | },
43 |
44 | 'update' => function ($url, $model) {
45 | return '';
46 | },
47 | 'delete' => function ($url, $model) {
48 | return '';
49 | },
50 | ]
51 |
52 | ],
53 | ],
54 | ]); ?>
55 |
56 |
--------------------------------------------------------------------------------
/src/views/webhook-log/view.php:
--------------------------------------------------------------------------------
1 | title = $model->id;
11 | $this->params['breadcrumbs'][] = ['label' => 'Webhook Logs', 'url' => ['index']];
12 | $this->params['breadcrumbs'][] = $this->title;
13 | ?>
14 |
15 |
16 |
= Html::encode($this->title) ?>
17 |
18 | = DetailView::widget([
19 | 'model' => $model,
20 | 'attributes' => [
21 | 'id',
22 | 'log_time:datetime',
23 | 'webhook_event',
24 | 'webhook_method',
25 | 'webhook_url:url',
26 | 'request_headers:prettyjson',
27 | 'request_payload:prettyjson',
28 | 'response_headers:prettyjson',
29 | 'response_status_code',
30 | ],
31 | ]) ?>
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/views/webhook/_form.php:
--------------------------------------------------------------------------------
1 |
10 |
11 |
30 |
--------------------------------------------------------------------------------
/src/views/webhook/create.php:
--------------------------------------------------------------------------------
1 | title = 'Create Webhook';
9 | $this->params['breadcrumbs'][] = ['label' => 'Webhooks', 'url' => ['index']];
10 | $this->params['breadcrumbs'][] = $this->title;
11 | ?>
12 |
13 |
14 |
= Html::encode($this->title) ?>
15 |
16 | = $this->render('_form', [
17 | 'model' => $model,
18 | ]) ?>
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/views/webhook/index.php:
--------------------------------------------------------------------------------
1 | title = 'Webhooks';
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 |
18 | = Html::a('Create Webhook', ['create'], ['class' => 'btn btn-success']) ?>
19 |
20 |
21 | = GridView::widget([
22 | 'dataProvider' => $dataProvider,
23 | 'filterModel' => $searchModel,
24 | 'columns' => [
25 | 'id',
26 | 'event',
27 | 'url:url',
28 | 'method',
29 |
30 | ['class' => 'yii\grid\ActionColumn'],
31 | ],
32 | ]); ?>
33 |
34 |
--------------------------------------------------------------------------------
/src/views/webhook/update.php:
--------------------------------------------------------------------------------
1 | title = 'Update Webhook: ' . $model->id;
9 | $this->params['breadcrumbs'][] = ['label' => 'Webhooks', 'url' => ['index']];
10 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
11 | $this->params['breadcrumbs'][] = 'Update';
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 | = $this->render('_form', [
18 | 'model' => $model,
19 | ]) ?>
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/views/webhook/view.php:
--------------------------------------------------------------------------------
1 | title = $model->id;
10 | $this->params['breadcrumbs'][] = ['label' => 'Webhooks', 'url' => ['index']];
11 | $this->params['breadcrumbs'][] = $this->title;
12 | ?>
13 |
14 |
15 |
= Html::encode($this->title) ?>
16 |
17 |
18 | = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
19 | = Html::a('Delete', ['delete', 'id' => $model->id], [
20 | 'class' => 'btn btn-danger',
21 | 'data' => [
22 | 'confirm' => 'Are you sure you want to delete this item?',
23 | 'method' => 'post',
24 | ],
25 | ]) ?>
26 |
27 |
28 | = DetailView::widget([
29 | 'model' => $model,
30 | 'attributes' => [
31 | 'id',
32 | 'event',
33 | 'description:ntext',
34 | 'url:url',
35 | 'method',
36 | 'created_at',
37 | 'updated_at',
38 | ],
39 | ]) ?>
40 |
41 |
42 |
--------------------------------------------------------------------------------