-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/webhook' into develop
# Conflicts: # Gemfile.lock # README.md
- Loading branch information
Showing
31 changed files
with
470 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the webhooks controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require './lib/pagination' | ||
|
||
class WebhooksController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :set_webhook, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /webhooks | ||
# GET /webhooks.json | ||
def index | ||
page = params[:page].presence || 1 | ||
per = params[:per].presence || Pagination.per | ||
@webhooks = Webhook.by_date.page(page).per(per) | ||
end | ||
|
||
# GET /webhooks/1 | ||
# GET /webhooks/1.json | ||
def show | ||
end | ||
|
||
# GET /webhooks/new | ||
def new | ||
@webhook = Webhook.new | ||
end | ||
|
||
# GET /webhooks/1/edit | ||
def edit | ||
end | ||
|
||
# POST /webhooks | ||
# POST /webhooks.json | ||
def create | ||
@webhook = Webhook.new(webhook_params) | ||
|
||
respond_to do |format| | ||
if @webhook.save | ||
format.html { redirect_to @webhook, notice: 'Webhook was successfully created.' } | ||
format.json { render :show, status: :created, location: @webhook } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @webhook.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /webhooks/1 | ||
# PATCH/PUT /webhooks/1.json | ||
def update | ||
respond_to do |format| | ||
if @webhook.update(webhook_params) | ||
format.html { redirect_to @webhook, notice: 'Webhook was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @webhook } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @webhook.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /webhooks/1 | ||
# DELETE /webhooks/1.json | ||
def destroy | ||
@webhook.destroy | ||
respond_to do |format| | ||
format.html { redirect_to webhooks_url, notice: 'Webhook was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_webhook | ||
@webhook = Webhook.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def webhook_params | ||
params.require(:webhook).permit(:url, :api_key, :user_id, :method, :is_active).merge(user_id: current_user.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module WebhooksHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Webhook < ApplicationRecord | ||
validates :url, presence: true, format: URI::regexp(%w[http https]) | ||
validates :api_key, presence: true | ||
METHOD_OPTIONS = %w(post put get) | ||
validates :method, :inclusion => {:in => METHOD_OPTIONS} | ||
scope :by_date, -> { order('id DESC') } | ||
scope :active, -> { where(is_active: true) } | ||
enum methods: { post: "post", put: "put", get: "get"} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Client | ||
class Submit < ApplicationService | ||
def initialize(webhook, callback_id, callback_value, callback_format) | ||
@webhook = webhook | ||
@callback_id = callback_id | ||
@callback_value = callback_value | ||
@callback_format = callback_format | ||
end | ||
|
||
def call | ||
begin | ||
url = @webhook.url | ||
api_key = @webhook.api_key | ||
callback_id = @callback_id | ||
callback_value = @callback_value | ||
callback_format = @callback_format | ||
headers = {} | ||
uri = URI.parse(url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
response = http.post(uri.path, "callback_id=#{callback_id}&callback_value=#{callback_value}&callback_format=#{callback_format}&api_key=#{api_key}", headers) | ||
rescue => e | ||
Sidekiq.logger.info e | ||
ensure | ||
Sidekiq.logger.info response | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h1 class="title">Encode > New Encode</h1> | ||
<h1 class="title">Encode > New</h1> | ||
|
||
<%= render 'form', encode: @encode %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<%= form_with(model: webhook, local: true) do |form| %> | ||
<% if webhook.errors.any? %> | ||
<div class="notification is-danger"> | ||
<strong><%= pluralize(webhook.errors.count, "error") %> prohibited this webhook from being saved:</strong> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label is-normal"> | ||
<%= form.label :url, class: "label" %> | ||
</div> | ||
<div class="field-body"> | ||
<div class="field"> | ||
<div class="control"> | ||
<%= form.text_field :url, class: webhook.errors[:url].size > 0 ? "input is-danger": "input" , placeholder: "url" %> | ||
</div> | ||
<% webhook.errors[:url].each do |message| %> | ||
<p class="help is-danger"> | ||
<%= message %> | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label is-normal"> | ||
<%= form.label :api_key, class: "label" %> | ||
</div> | ||
<div class="field-body"> | ||
<div class="field"> | ||
<div class="control"> | ||
<%= form.text_field :api_key, class: webhook.errors[:api_key].size > 0 ? "input is-danger": "input" , placeholder: "api_key" %> | ||
</div> | ||
<% webhook.errors[:api_key].each do |message| %> | ||
<p class="help is-danger"> | ||
<%= message %> | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label is-normal"> | ||
<%= form.label :method, class: "label" %> | ||
</div> | ||
<div class="field-body"> | ||
<div class="field"> | ||
<div class="control"> | ||
<%= form.select :method, Webhook::METHOD_OPTIONS, { :include_blank => '-- Select One --' }, class: webhook.errors[:method].size > 0 ? "input is-danger": "input" %> | ||
</div> | ||
<% webhook.errors[:method].each do |message| %> | ||
<p class="help is-danger"> | ||
<%= message %> | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label is-normal"> | ||
</div> | ||
<div class="field-body"> | ||
<div class="field"> | ||
<div class="control"> | ||
<%= form.label :is_active do %> | ||
<%= form.check_box :is_active %> | ||
is_active | ||
<% end %> | ||
</div> | ||
<% webhook.errors[:is_active].each do |message| %> | ||
<p class="help is-danger"> | ||
<%= message %> | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label"> | ||
<!-- Left empty for spacing --> | ||
</div> | ||
<div class="field-body"> | ||
<%= form.submit class: "button is-primary" %> | ||
</div> | ||
</div> | ||
|
||
<div class="field is-horizontal"> | ||
<div class="field-label"> | ||
<!-- Left empty for spacing --> | ||
</div> | ||
<div class="field-body"> | ||
<%= link_to 'Back', webhooks_path, class: "button is-warning" %> | ||
</div> | ||
</div> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! webhook, :id, :url, :api_key, :user_id, :method, :is_active, :created_at, :updated_at | ||
json.url webhook_url(webhook, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1 class="title">Webhook > Edit </h1> | ||
<%= render 'form', webhook: @webhook %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<h1 class="title">Webhooks > List</h1> | ||
<div class="table-container"> | ||
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth" id="encodes"> | ||
<thead> | ||
<tr> | ||
<th>Url</th> | ||
<th>Api key</th> | ||
<th>User</th> | ||
<th>Method</th> | ||
<th>Is active</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @webhooks.each do |webhook| %> | ||
<tr> | ||
<td><%= webhook.url %></td> | ||
<td><%= webhook.api_key %></td> | ||
<td><%= webhook.user_id %></td> | ||
<td><%= webhook.method %></td> | ||
<td><%= webhook.is_active %></td> | ||
<td> | ||
<%= link_to 'Show', webhook, class: "button is-link" %> | ||
<%= link_to 'Edit', edit_webhook_path(webhook), class: "button is-primary" %> | ||
<%= link_to 'Destroy', webhook, method: :delete, data: { confirm: 'Are you sure?' }, class: "button is-danger" %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<%= link_to 'New Webhook', new_webhook_path, class: "button is-primary" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @webhooks, partial: "webhooks/webhook", as: :webhook |
Oops, something went wrong.