clicksign-webhooks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +111 -0
  4. data/Rakefile +22 -0
  5. data/app/controllers/clicksign/webhooks/application_controller.rb +6 -0
  6. data/app/controllers/clicksign/webhooks/events_controller.rb +21 -0
  7. data/config/routes.rb +3 -0
  8. data/lib/clicksign/webhooks.rb +18 -0
  9. data/lib/clicksign/webhooks/engine.rb +7 -0
  10. data/lib/clicksign/webhooks/version.rb +5 -0
  11. data/lib/tasks/clicksign/webhooks_tasks.rake +4 -0
  12. data/spec/requests/event_spec.rb +25 -0
  13. data/spec/spec_helper.rb +29 -0
  14. data/spec/test_app/Rakefile +6 -0
  15. data/spec/test_app/app/controllers/application_controller.rb +2 -0
  16. data/spec/test_app/bin/bundle +3 -0
  17. data/spec/test_app/bin/rails +4 -0
  18. data/spec/test_app/bin/rake +4 -0
  19. data/spec/test_app/bin/setup +36 -0
  20. data/spec/test_app/bin/update +31 -0
  21. data/spec/test_app/bin/yarn +11 -0
  22. data/spec/test_app/config.ru +5 -0
  23. data/spec/test_app/config/application.rb +28 -0
  24. data/spec/test_app/config/boot.rb +5 -0
  25. data/spec/test_app/config/cable.yml +10 -0
  26. data/spec/test_app/config/database.yml +0 -0
  27. data/spec/test_app/config/environment.rb +5 -0
  28. data/spec/test_app/config/environments/development.rb +19 -0
  29. data/spec/test_app/config/environments/production.rb +18 -0
  30. data/spec/test_app/config/environments/test.rb +15 -0
  31. data/spec/test_app/config/initializers/application_controller_renderer.rb +8 -0
  32. data/spec/test_app/config/initializers/assets.rb +14 -0
  33. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  34. data/spec/test_app/config/initializers/content_security_policy.rb +25 -0
  35. data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
  36. data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/spec/test_app/config/initializers/inflections.rb +16 -0
  38. data/spec/test_app/config/initializers/mime_types.rb +4 -0
  39. data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
  40. data/spec/test_app/config/locales/en.yml +33 -0
  41. data/spec/test_app/config/puma.rb +34 -0
  42. data/spec/test_app/config/routes.rb +3 -0
  43. data/spec/test_app/config/spring.rb +6 -0
  44. data/spec/test_app/log/development.log +251 -0
  45. data/spec/test_app/log/production.log +0 -0
  46. data/spec/test_app/log/test.log +52 -0
  47. data/spec/test_app/package.json +5 -0
  48. data/spec/test_app/public/404.html +67 -0
  49. data/spec/test_app/public/422.html +67 -0
  50. data/spec/test_app/public/500.html +66 -0
  51. data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
  52. data/spec/test_app/public/apple-touch-icon.png +0 -0
  53. data/spec/test_app/public/favicon.ico +0 -0
  54. metadata +180 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b563cd44ac9a368bbaf250193e2dbbff62dff5b4aee62c9587a13dfd3befb21e
4
+ data.tar.gz: adfb39017534f74aeac9244711274c662ff07273d85f496ec12c318cc82a5115
5
+ SHA512:
6
+ metadata.gz: 4dc440d12165352c1656bf9a01e0716445c8240f66e3060334366087708c189599e8da9f257e1821c83bee7478e58302db38c5a8d3a82e7b5158dbb8cfede6b0
7
+ data.tar.gz: 0ad6fa752fbdd86c54b186e53852c80f13ff09aab9b937125f186396e03924e105e4ce720022b2bf0c9cd63bed819cde101baf96db263fdf0f481a917178b146
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Francisco Martins
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # Clicksign::Webhooks
2
+
3
+ To fully understand Clicksign webhooks system, click [here](https://developers.clicksign.com/docs/introducao-a-webhooks)
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'clicksign-webhooks'
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ $ bundle
15
+ ```
16
+
17
+ Or install it yourself as:
18
+ ```bash
19
+ $ gem install clicksign-webhooks
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ First, mount this engine on your app.
25
+
26
+ ```ruby
27
+ Rails.application.routes.draw do
28
+ ...
29
+ mount Clicksign::Webhooks::Engine => "/clicksign-webhooks"
30
+ ...
31
+ end
32
+
33
+ ```
34
+
35
+ Depending on your version of rails, use either `rails routes -g clicksign-webhooks` or `rake routes | grep clicksign-webhooks`, to see the path:
36
+
37
+ ```bash
38
+ $ rake routes | grep clicksign-webhooks
39
+ Routes for Clicksign::Webhooks::Engine:
40
+ event POST /event(.:format) clicksign/webhooks/events#create
41
+ ```
42
+
43
+ Your rails app able to receive a `POST` at `/clicksign-webhooks/event`.
44
+
45
+ Then create a initializer using a `Proc` to each possible event:
46
+
47
+ ```ruby
48
+ Clicksign::Webhooks.configure do |config|
49
+ # You have to setup one Proc for each event
50
+
51
+ config.on_upload = ->(event) {
52
+ # Do something with sent event parameters
53
+ }
54
+
55
+ # ...
56
+ end
57
+ ```
58
+
59
+ The argument `event` is a `Hash`:
60
+
61
+ ```ruby
62
+ {
63
+ "event":{
64
+ "name":"add_signer",
65
+ "data":{
66
+ "user":{
67
+ "email":"...",
68
+ "name":"..."
69
+ },
70
+ "account":{
71
+ "key":"..."
72
+ },
73
+ "signers":[
74
+ {
75
+ "key":"...",
76
+ "email":"...",
77
+ "created_at":"...",
78
+ "sign_as":"witness",
79
+ "auths":["email"],
80
+ "phone_number":"...",
81
+ "phone_number_hash":"..."
82
+ }
83
+ ]
84
+ },
85
+ "occurred_at":"..."
86
+ },
87
+ "document":{...},
88
+ "signers":[...],
89
+ "events":[{...}]
90
+ }
91
+ ```
92
+
93
+ ##### Available event callbacks:
94
+
95
+ - on_upload
96
+ - on_add_signer
97
+ - on_remove_signer
98
+ - on_sign
99
+ - on_close
100
+ - on_auto_close,
101
+ - on_deadline
102
+ - on_cancel
103
+ - on_update_deadline
104
+ - on_update_auto_close
105
+
106
+ ## Contributing
107
+
108
+ Feel free to contribute. Pull requests are welcome.
109
+
110
+ ## License
111
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Clicksign::Webhooks'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("spec/test_app/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ module Clicksign
2
+ module Webhooks
3
+ class ApplicationController < ActionController::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ require_dependency "clicksign/webhooks/application_controller"
2
+
3
+ module Clicksign::Webhooks
4
+ class EventsController < ApplicationController
5
+ def create
6
+ Clicksign::Webhooks.send(callback).call(event_params)
7
+ head 200
8
+ rescue NoMethodError
9
+ Rails.logger.warn("Invalid configuration: #{callback}")
10
+ head 422
11
+ end
12
+
13
+ def event_params
14
+ params.require(:event).permit!
15
+ end
16
+
17
+ def callback
18
+ "on_#{event_params[:name]}"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ Clicksign::Webhooks::Engine.routes.draw do
2
+ resource :event, only: [:create]
3
+ end
@@ -0,0 +1,18 @@
1
+ require "clicksign/webhooks/engine"
2
+
3
+ module Clicksign
4
+ module Webhooks
5
+ EVENTS = [
6
+ :upload, :add_signer, :remove_signer, :sign, :close, :auto_close,
7
+ :deadline, :cancel, :update_deadline, :update_auto_close
8
+ ].map { |event| "on_#{event}" }
9
+
10
+ class << self
11
+ attr_accessor *EVENTS
12
+
13
+ def configure
14
+ yield(self) if block_given?
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Clicksign
2
+ module Webhooks
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Clicksign::Webhooks
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Clicksign
2
+ module Webhooks
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :clicksign_webhooks do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Clicksign::Webhooks::EventsController, type: :request do
4
+ let(:on_upload) do
5
+ Proc.new { |event| event }
6
+ end
7
+
8
+ before do
9
+ Clicksign::Webhooks.configure do |config|
10
+ config.on_upload = on_upload
11
+ end
12
+ end
13
+
14
+ it do
15
+ expect(on_upload).to receive(:call).once
16
+ post '/clicksign-webhooks/event', params: { event: { name: 'upload' } }
17
+ expect(response.code).to eq('200')
18
+ end
19
+
20
+ it do
21
+ expect(on_upload).to_not receive(:call)
22
+ post '/clicksign-webhooks/event', params: { event: { name: 'invalid' } }
23
+ expect(response.code).to eq('422')
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require File.expand_path("../test_app/config/environment", __FILE__)
4
+
5
+ require 'bundler/setup'
6
+ require 'simplecov'
7
+
8
+ SimpleCov.start do
9
+ add_filter '/spec'
10
+ end
11
+
12
+ require 'rspec/rails'
13
+ require 'clicksign/webhooks'
14
+
15
+ Dir[
16
+ File.expand_path('../support/**/*.rb', __FILE__)
17
+ ].each { |f| require f }
18
+
19
+ RSpec.configure do |config|
20
+ # Enable flags like --only-failures and --next-failure
21
+ config.example_status_persistence_file_path = ".rspec_status"
22
+
23
+ # Disable RSpec exposing methods globally on `Module` and `main`
24
+ config.disable_monkey_patching!
25
+
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:setup'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path('..', __dir__)
3
+ Dir.chdir(APP_ROOT) do
4
+ begin
5
+ exec "yarnpkg", *ARGV
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,28 @@
1
+ require_relative 'boot'
2
+
3
+ # require "rails"
4
+ # Pick the frameworks you want:
5
+ # require "active_model/railtie"
6
+ # require "active_job/railtie"
7
+ # require "active_record/railtie"
8
+ # require "active_storage/engine"
9
+ require "action_controller/railtie"
10
+ # require "action_mailer/railtie"
11
+ # require "action_view/railtie"
12
+ # require "action_cable/engine"
13
+ # require "sprockets/railtie"
14
+ # require "rails/test_unit/railtie"
15
+
16
+ Bundler.require(*Rails.groups)
17
+ require "clicksign/webhooks"
18
+
19
+ module TestApp
20
+ class Application < Rails::Application
21
+ # Initialize configuration defaults for originally generated Rails version.
22
+
23
+ # Settings in config/environments/* take precedence over those specified here.
24
+ # Application configuration can go into files in config/initializers
25
+ # -- all .rb files in that directory are automatically loaded after loading
26
+ # the framework and any gems in your application.
27
+ end
28
+ end