hooky 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4ac174ee771e0182a89813e6b5f7d7ad7cd7f3e96c66501ea3f4b3896178da8
4
+ data.tar.gz: 9d14c7457574de4fb30281ba31b4f9facfbc38d3eeaaa6187fb4aab2b85ee3d6
5
+ SHA512:
6
+ metadata.gz: 55265fd5efbf927e15fc4934b3542d6a9befb9937e94f3d3a3103fd75c4d2c0c4956840484b4519622c196c9531d2b4ca1b1466451308506fa4cc47dd89ced8c
7
+ data.tar.gz: c5cadff1fe0503a1c270f374da5c56df4e1c1dbdda00358c888f4b0c807cc66582aa065263d344aaa84f1c18b62f722c477c42a033add57c75185499c46deaa7
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Hooky
2
+
3
+ Hooky is a Ruby gem that provides a simple way to test webhooks.
4
+
5
+ By storing example request data and configuration in a `.hooky` directory in your Rails root directory, you can easily
6
+ test webhooks by running `hooky <webhook_name>`.
7
+
8
+ You can create as many webhooks as you required but they must be named like so:
9
+
10
+ - `.hooky/<webhook_name>/data.json`
11
+ - `.hooky/<webhook_name>/config.json`
12
+
13
+ The `config.json` file contains details such as the URL, HTTP Method and any headers. For example:
14
+
15
+ ```json
16
+ {
17
+ "url": "https://example.com/webhooks/order.created",
18
+ "method": "GET",
19
+ "headers": {
20
+ "Content-Type": "application/json"
21
+ }
22
+ }
23
+ ```
24
+
25
+ The `data.json` file will be the request body that is sent. For example:
26
+
27
+ ```json
28
+ {
29
+ "id": 123,
30
+ "name": "John Doe"
31
+ }
32
+ ```
33
+
34
+ ## Installation
35
+
36
+ Install the gem by running `gem install hooky`.
37
+
38
+ ## Usage
39
+
40
+ ```bash
41
+ # To add the hooky gem to your Gemfile, create a .hooky directory and create an example webhook, run:
42
+ hooky init
43
+
44
+ # To test a webhook, run:
45
+ hooky hook <webhook_name>
46
+ ```
47
+
48
+ To add the gem to your Rails app and create an example webhook, run `bundle exec hooky init`. This will create a `.hooky`
49
+ directory and
50
+
51
+
52
+ Then to test this webhook, run `rails hooky order.created` and it will send a request to the URL specified in the `data.json` file.
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/hooky.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/hooky ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Prevent failures from being reported twice.
4
+ Thread.report_on_exception = false
5
+
6
+ require "bundler/setup"
7
+ require "hooky"
8
+
9
+ begin
10
+ Hooky::CLI.start(ARGV)
11
+ rescue => e
12
+ puts " \e[31mERROR (#{e.class}): #{e.message}\e[0m"
13
+ puts e.backtrace if ENV["VERBOSE"]
14
+ exit 1
15
+ end
data/lib/hooky/cli.rb ADDED
@@ -0,0 +1,80 @@
1
+ require "thor"
2
+
3
+ module Hooky
4
+
5
+ class CLI < Thor
6
+
7
+ def self.exit_on_failure?() true end
8
+
9
+ desc "list", "List all hooks"
10
+ def list
11
+ puts Hooky::Hook.all
12
+ end
13
+
14
+ desc "hook [HOOK]", "Run a hook"
15
+ def hook(hook)
16
+ h = Hooky::Hook.new(hook)
17
+
18
+ puts "Running hook #{hook}..."
19
+ puts h.send_request
20
+
21
+ # puts h.config_file
22
+ # puts h.data_file
23
+ end
24
+
25
+ desc "init", "Create example hook, add Hooky to Gemfile and create a bin/hooky binstub"
26
+ def init
27
+ require "fileutils"
28
+
29
+ unless (example_dir = Pathname.new(File.expand_path(".hooky/example"))).exist?
30
+ example_dir.mkpath
31
+ Pathname.new(File.expand_path("templates/example_hook", __dir__)).each_child do |sample_hook|
32
+ FileUtils.cp sample_hook, example_dir, preserve: true
33
+ end
34
+ puts "Created example hook in .hooky/example"
35
+ end
36
+
37
+ if (binstub = Pathname.new(File.expand_path("bin/hooky"))).exist?
38
+ puts "Binstub already exists in bin/hooky (remove first to create a new one)"
39
+ else
40
+ puts "Adding hookyrb to Gemfile and bundle..."
41
+
42
+ `bundle add hooky --group "development, test"`
43
+ `bundle binstubs hooky`
44
+
45
+ puts "Created binstub file in bin/hooky"
46
+ end
47
+ end
48
+
49
+ desc "version", "Show Hooky version"
50
+ def version
51
+ puts Hooky::VERSION
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ # SSHKit uses instance eval, so we need a global const for ergonomics
59
+ # KAMAL = Kamal::Commander.new
60
+
61
+
62
+ # require "thor"
63
+
64
+ # module Hookynew
65
+
66
+ # class Cli < Thor
67
+
68
+ # desc "hello NAME", "say hello to NAME"
69
+ # def hello(name)
70
+ # puts "Hello #{name}"
71
+ # end
72
+
73
+ # desc "list", "list all hooks"
74
+ # def list
75
+ # puts Hookynew::Hook.all
76
+ # end
77
+
78
+ # end
79
+
80
+ # end
data/lib/hooky/hook.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "httparty"
2
+
3
+ module Hooky
4
+ class Hook
5
+
6
+ attr_accessor :directory
7
+
8
+ def initialize(directory)
9
+ @directory = directory
10
+ end
11
+
12
+ def self.all
13
+ Dir.glob(".hooky/*").map{|d| d.gsub(".hooky/", "")}
14
+ end
15
+
16
+ def config_file
17
+ File.read(".hooky/#{directory}/config.json")
18
+ end
19
+
20
+ def data_file
21
+ File.read(".hooky/#{directory}/data.json")
22
+ end
23
+
24
+ def config
25
+ JSON.parse(config_file)
26
+ end
27
+
28
+ def data
29
+ JSON.parse(data_file)
30
+ end
31
+
32
+ def url
33
+ config["url"]
34
+ end
35
+
36
+ def headers
37
+ config["headers"]
38
+ end
39
+
40
+ def httparty
41
+ if config["method"] =~ /GET/
42
+ HTTParty.get(url, body: data, headers: headers)
43
+ elsif config["method"] =~ /POST/
44
+ HTTParty.post(url, body: data, headers: headers)
45
+ end
46
+ end
47
+
48
+ def send_request
49
+ resp = httparty
50
+
51
+ resp.response
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "url": "http://localhost:3000/example",
3
+ "method": "GET",
4
+ "headers": {
5
+ "Content-Type": "application/json"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payment_id": "chg_abc123",
3
+ "amount": 100,
4
+ "currency": "USD",
5
+ "status": "pending",
6
+ "created_at": "2019-01-01T00:00:00Z"
7
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hooky
4
+ VERSION = "2.0.0"
5
+ end
data/lib/hooky.rb CHANGED
@@ -1,5 +1,8 @@
1
- # Git hooks in Rake. See <tt>README.rdoc</tt> for details.
1
+ require "hooky/version"
2
+
3
+ module Hooky
4
+
5
+ autoload :CLI, "hooky/cli"
6
+ autoload :Hook, "hooky/hook"
2
7
 
3
- class Hooky
4
- VERSION = "1.0.0"
5
8
  end
metadata CHANGED
@@ -1,81 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hooky
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
5
  platform: ruby
6
- authors:
7
- - John Barnette
8
- autorequire:
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-08-20 00:00:00 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.3.2
24
- version:
25
- description: |-
26
- Hooky lets you write Git repository hooks with Rake. If you already
27
- have a Rakefile, write your hooks in Ruby! Hooky provides Tasks for
28
- most Git hooks, and lets you easily add behavior.
29
-
30
- Git hooks are powerful: Check the Git documentation (linked above) for
31
- detailed descriptions and lifecycle order.
32
- email:
33
- - jbarnette@rubyforge.org
34
- executables: []
35
-
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.21.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.21.0
41
+ description:
42
+ email:
43
+ - dean@deanpcmad.com
44
+ executables:
45
+ - hooky
36
46
  extensions: []
37
-
38
- extra_rdoc_files:
39
- - Manifest.txt
40
- - CHANGELOG.rdoc
41
- - README.rdoc
42
- files:
43
- - .autotest
44
- - CHANGELOG.rdoc
45
- - Manifest.txt
46
- - README.rdoc
47
- - Rakefile
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - bin/hooky
48
51
  - lib/hooky.rb
49
- - lib/hooky/tasks.rb
50
- - test/test_hooky.rb
51
- has_rdoc: true
52
- homepage: http://github.com/jbarnette/hooky
53
- licenses: []
54
-
55
- post_install_message:
56
- rdoc_options:
57
- - --main
58
- - README.rdoc
59
- require_paths:
52
+ - lib/hooky/cli.rb
53
+ - lib/hooky/hook.rb
54
+ - lib/hooky/templates/example_hook/config.json
55
+ - lib/hooky/templates/example_hook/data.json
56
+ - lib/hooky/version.rb
57
+ homepage: https://github.com/deanpcmad/hooky
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
60
64
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
62
- requirements:
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
63
67
  - - ">="
64
- - !ruby/object:Gem::Version
65
- version: "0"
66
- version:
67
- required_rubygems_version: !ruby/object:Gem::Requirement
68
- requirements:
68
+ - !ruby/object:Gem::Version
69
+ version: 2.6.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
69
72
  - - ">="
70
- - !ruby/object:Gem::Version
71
- version: "0"
72
- version:
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
73
75
  requirements: []
74
-
75
- rubyforge_project: hooky
76
- rubygems_version: 1.3.5
77
- signing_key:
78
- specification_version: 3
79
- summary: Hooky lets you write Git repository hooks with Rake
80
- test_files:
81
- - test/test_hooky.rb
76
+ rubygems_version: 3.4.20
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Hooky is a tool for testing webhooks
80
+ test_files: []
data/.autotest DELETED
@@ -1,5 +0,0 @@
1
- require "autotest/restart"
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.testlib = "minitest/autorun"
5
- end
data/CHANGELOG.rdoc DELETED
@@ -1,3 +0,0 @@
1
- === 1.0.0 / 2009-08-20
2
-
3
- * Birthday!
data/Manifest.txt DELETED
@@ -1,8 +0,0 @@
1
- .autotest
2
- CHANGELOG.rdoc
3
- Manifest.txt
4
- README.rdoc
5
- Rakefile
6
- lib/hooky.rb
7
- lib/hooky/tasks.rb
8
- test/test_hooky.rb
data/README.rdoc DELETED
@@ -1,98 +0,0 @@
1
- = Hooky
2
-
3
- * http://github.com/jbarnette/hooky
4
- * http://www.kernel.org/pub/software/scm/git/docs/githooks.html
5
-
6
- == Description
7
-
8
- Hooky lets you write Git repository hooks with Rake. If you already
9
- have a Rakefile, write your hooks in Ruby! Hooky provides Tasks for
10
- most Git hooks, and lets you easily add behavior.
11
-
12
- Git hooks are powerful: Check the Git documentation (linked above) for
13
- detailed descriptions and lifecycle order.
14
-
15
- == Examples
16
-
17
- # in your Rakefile
18
- require "hooky/tasks"
19
-
20
- task "git:applypatch-msg", [:file] do |_, args|
21
- puts "Proposed git-am commit msg: #{IO.read(args[:file])}"
22
- end
23
-
24
- task "git:commit-msg", [:file] do |_, args|
25
- puts "Proposed commit msg: #{IO.read(args[:file])}"
26
- end
27
-
28
- task "git:post-applypatch" do
29
- puts "Patch applied by git-am!"
30
- end
31
-
32
- task "git:post-checkout", [:old, :new, :branch] do |_, args|
33
- puts "you just switched branches!" if args[:branch]
34
- puts "old SHA: #{args[:old]}, new SHA: #{args[:new]}"
35
- end
36
-
37
- task "git:post-commit"
38
- puts "You made a commit!"
39
- end
40
-
41
- task "git:post-merge", [:squash] do |_, args|
42
- puts "You just did a merge!"
43
- puts "It was a squash." if args[:squash]
44
- end
45
-
46
- task "git:pre-applypatch" do
47
- puts "git-am is about to commit a patch!"
48
- end
49
-
50
- task "git:pre-auto-gc" do
51
- puts "git gc --auto is about to run!"
52
- end
53
-
54
- task "git:pre-commit" do
55
- puts "You're about to commit!"
56
- end
57
-
58
- task "git:pre-rebase" do
59
- puts "You're about to rebase!"
60
- end
61
-
62
- task "git:prepare-commit-msg", [:file, :source, :sha] do |_, args|
63
- puts "Building a commit message!"
64
- end
65
-
66
- == Installation
67
-
68
- $ gem install hooky
69
-
70
- # in your project
71
- $ rake hooky:install
72
-
73
- <tt>hooky:install</tt> symlinks all hooks to
74
- <tt>.git/hooks/hooky</tt>, a stub that delegates to your Rakefile, but
75
- it won't overwrite any hooks you've already created.
76
-
77
- == License
78
-
79
- Copyright 2009 John Barnette (jbarnette@rubyforge.org)
80
-
81
- Permission is hereby granted, free of charge, to any person obtaining
82
- a copy of this software and associated documentation files (the
83
- 'Software'), to deal in the Software without restriction, including
84
- without limitation the rights to use, copy, modify, merge, publish,
85
- distribute, sublicense, and/or sell copies of the Software, and to
86
- permit persons to whom the Software is furnished to do so, subject to
87
- the following conditions:
88
-
89
- The above copyright notice and this permission notice shall be
90
- included in all copies or substantial portions of the Software.
91
-
92
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
93
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
94
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
95
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
96
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
97
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
98
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require "rubygems"
2
- require "hoe"
3
-
4
- Hoe.plugin :doofus, :git
5
-
6
- Hoe.spec "hooky" do
7
- developer "John Barnette", "jbarnette@rubyforge.org"
8
-
9
- self.extra_rdoc_files = FileList["*.rdoc"]
10
- self.history_file = "CHANGELOG.rdoc"
11
- self.readme_file = "README.rdoc"
12
- self.testlib = :minitest
13
- end
data/lib/hooky/tasks.rb DELETED
@@ -1,66 +0,0 @@
1
- git_hooks = %w(applypatch-msg commit-msg post-applypatch post-checkout
2
- post-commit post-merge pre-applypatch pre-auto-gc pre-commit
3
- pre-rebase prepare-commit-msg)
4
-
5
- git_hook_files = git_hooks.collect { |f| ".git/hooks/#{f}" }
6
-
7
- git_hook_files.each do |f|
8
- file f do |task|
9
- sh "ln -s hooky #{task.name}"
10
- end
11
- end
12
-
13
- desc "Install magical Rake Git hooks. Nondestructive."
14
- task "hooky:install" => [".git/hooks/hooky", *git_hook_files]
15
-
16
- file ".git/hooks/hooky" do |task|
17
- File.open task.name, "w" do |f|
18
- f.puts "#!/bin/sh"
19
- f.puts "export HOOK=$0"
20
- f.puts "export HOOK_ARGS=$@"
21
- f.puts "rake -s hooky"
22
- end
23
-
24
- sh "chmod +x #{task.name}"
25
- end
26
-
27
- # These tasks are intentionally not described in Rake's -T output to
28
- # avoid clutter. The 'hooky' task dispatches to a specific hook
29
- # task. To add behavior to a Git hook in your own Rakefile, 'redefine'
30
- # the appropriate task.
31
-
32
- task :hooky do
33
- ENV["HOOK"] && ENV["HOOK_ARGS"] or raise "Need HOOK and HOOK_ARGS."
34
-
35
- hook = File.basename ENV["HOOK"]
36
- args = ENV["HOOK_ARGS"].split /\s+/
37
-
38
- warn({ :hook => hook, :args => args }.inspect) if ENV["DEBUG"]
39
- Rake::Task["git:#{hook}"].invoke *args
40
- end
41
-
42
- task "git:applypatch-msg", [:file]
43
-
44
- task "git:commit-msg", [:file]
45
-
46
- task "git:post-applypatch"
47
-
48
- task "git:post-checkout", [:old, :new, :branch] do |_, args|
49
- args.to_hash[:branch] = args[:branch] == "1"
50
- end
51
-
52
- task "git:post-commit"
53
-
54
- task "git:post-merge", [:squash] do |_, args|
55
- args.to_hash[:squash] = args[:squash] == "1"
56
- end
57
-
58
- task "git:pre-applypatch"
59
-
60
- task "git:pre-auto-gc"
61
-
62
- task "git:pre-commit"
63
-
64
- task "git:pre-rebase"
65
-
66
- task "git:prepare-commit-msg", [:file, :source, :sha]
data/test/test_hooky.rb DELETED
@@ -1,8 +0,0 @@
1
- require "minitest/autorun"
2
- require "hooky"
3
-
4
- class TestHooky < MiniTest::Unit::TestCase
5
- def test_sanity
6
- flunk "write tests or I will kneecap you"
7
- end
8
- end