Client library for making WebHook calls with exchangeable delivery methods. The purpose of this library is to be similar to the popular mail gem, which supports multiple delivery methods to deliver the mail. One of the most useful features is the option to use tools like letter_opener and letter_opener_web during development.
Currently supported delivery methods are
- Faraday - Uses Faraday to make the WebHook requests
- Console - Outputs all requests to the console
- ...
See lib/ix/web_hook/delivery_methods.
Add this line to your application's Gemfile:
gem 'ix-web_hook', '~> 0.0.0'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ix-web_hook
require 'ix-web_hook'
web_hook = IX::WebHook.new(
url: "http://any.url",
header: { "custom" => "header" }
option: {
"custom" => "option"
}
)
response = web_hook.deliver
if response.status == 200
puts "Success: #{response.body}"
else
puts "Error: #{response.body}"
end
web_hook = IX::WebHook.new do
url "http://any.url"
header "custom" => "header"
option "http-method" => :post, "custom" => "option"
end
response = web_hook.deliver
if response.status == 200
puts "Success: #{response.body}"
else
puts "Error: #{response.body}"
end
response = IX::WebHook.deliver do
url "http://any.url"
header "custom" => "header"
option "http-method" => :post, "custom" => "option"
end
if response.status == 200
puts "Success: #{response.body}"
else
puts "Error: #{response.body}"
end
You can configure your webhook defaults using the following block. If you are using Rails, you would normally add this code block in config/initializers/ix_web_hook.rb
.
IX::WebHook.configure do |config|
config.header "any-http-header" => "value"
config.option "any-client-option" => "value"
config.delivery_method :faraday # :console, :test any derived from IX::WebHook::DeliveryMethod or implementing #deliver(request).
end
Note, that all default configuration can be overwritten in each instance.
rake spec
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request