Skip to content

Instantly share code, notes, and snippets.

@creisor
Created April 26, 2016 22:41
Show Gist options
  • Save creisor/da16fcba604d35dad607fbbc612ce042 to your computer and use it in GitHub Desktop.
Save creisor/da16fcba604d35dad607fbbc612ce042 to your computer and use it in GitHub Desktop.
Typhoeus webhook simulator
source 'https://rubygems.org'
gem "typhoeus", '0.6.9'
GEM
remote: https://rubygems.org/
specs:
ethon (0.8.1)
ffi (>= 1.3.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
multipart-post (2.0.0)
typhoeus (0.6.9)
ethon (>= 0.7.1)
PLATFORMS
ruby
DEPENDENCIES
faraday (= 0.9.0)
typhoeus (= 0.6.9)
BUNDLED WITH
1.11.2
#!/usr/bin/env ruby
require 'typhoeus'
require 'json'
require 'uri'
require 'logger'
logger = Logger.new('webhooker.log')
logger.level = Logger::INFO
url_default = 'http://service-processor.snc1'
num_requests = 10
url = ARGV[0] || url_default
payload_file = 'payload.json'
payload = File.open(payload_file, 'r') do |fh|
fh.read
end
body = { :payload => payload }
Typhoeus.configure do |config|
config.verbose = true
end
options = {
:method => :post,
:headers => {
'X-Github-Event' => 'push',
'X-GitHub-Delivery' => '142ec80-ec72-11e5-92b0-c51cb894f8dd',
'Content-Type' => 'application/x-www-form-urlencoded',
'Expect' => ''
},
:body => body
}
hydra = Typhoeus::Hydra.new(max_concurrency: 2)
requests = num_requests.times.map {
request = Typhoeus::Request.new("#{url}/processor", options)
hydra.queue(request)
request
}
hydra.run
responses = requests.map do |request|
response = JSON.load(request.response.body)
unless response['exception']['obj']['status'].first == "404 Not Found"
logger.info(request.response.body)
end
begin
puts response['exception']['obj']['status']
rescue NoMethodError
puts response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment