webhook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/webhook.rb +28 -0
- data/lib/webhook/version.rb +3 -0
- data/spec/cassettes/requestbin/extra_headers.yml +40 -0
- data/spec/cassettes/requestbin/no_params.yml +36 -0
- data/spec/cassettes/requestbin/simple_request.yml +36 -0
- data/spec/cassettes/requestbin/user_agent.yml +36 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/webhook_spec.rb +69 -0
- data/webhook.gemspec +27 -0
- metadata +115 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Webhook
|
2
|
+
|
3
|
+
Client library for making webhook calls.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'webhook', :git => "git@github.com:AbleTech/webhook.git"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install webhook
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'webhook'
|
22
|
+
|
23
|
+
code, message, body = Webhook.post('http://requestb.in/yadzsfya', :name => 'Abletech', :age => '6')
|
24
|
+
if code == '200'
|
25
|
+
puts "Success: #{body}"
|
26
|
+
else
|
27
|
+
puts "Error (#{code}): {message}\n#{body}"
|
28
|
+
end
|
29
|
+
|
30
|
+
## Testing
|
31
|
+
|
32
|
+
rspec
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/webhook.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "webhook/version"
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Webhook
|
5
|
+
def self.post(url, form_fields={}, request_headers={})
|
6
|
+
headers = {
|
7
|
+
"User-Agent" => "Abletech WebHook/#{VERSION}"
|
8
|
+
}.merge(request_headers)
|
9
|
+
|
10
|
+
uri = URI.parse(url)
|
11
|
+
use_ssl = (uri.scheme.downcase == 'https')
|
12
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
13
|
+
req.form_data = form_fields
|
14
|
+
|
15
|
+
begin
|
16
|
+
http_session = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http_session.use_ssl = true if use_ssl
|
18
|
+
|
19
|
+
response = http_session.start { |http|
|
20
|
+
http.request(req)
|
21
|
+
}
|
22
|
+
rescue => e
|
23
|
+
raise "Unable to open stream: #{uri.to_s}; \n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
return response.code, response.message, response.body
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://requestb.in/yadzsfya
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: time=to+go
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Abletech WebHook/0.0.1
|
12
|
+
Referer:
|
13
|
+
- http://www.abletech.co.nz
|
14
|
+
Initiator:
|
15
|
+
- http://www.addressfinder.co.nz
|
16
|
+
Accept:
|
17
|
+
- ! '*/*'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- text/html; charset=utf-8
|
27
|
+
Date:
|
28
|
+
- Fri, 06 Apr 2012 03:44:10 GMT
|
29
|
+
Content-Length:
|
30
|
+
- '3'
|
31
|
+
Connection:
|
32
|
+
- Keep-Alive
|
33
|
+
body:
|
34
|
+
encoding: US-ASCII
|
35
|
+
string: ! 'ok
|
36
|
+
|
37
|
+
'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Fri, 06 Apr 2012 03:44:10 GMT
|
40
|
+
recorded_with: VCR 2.0.1
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://requestb.in/yadzsfya
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Abletech WebHook/0.0.1
|
12
|
+
Accept:
|
13
|
+
- ! '*/*'
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/html; charset=utf-8
|
23
|
+
Date:
|
24
|
+
- Fri, 06 Apr 2012 03:37:32 GMT
|
25
|
+
Content-Length:
|
26
|
+
- '3'
|
27
|
+
Connection:
|
28
|
+
- Keep-Alive
|
29
|
+
body:
|
30
|
+
encoding: US-ASCII
|
31
|
+
string: ! 'ok
|
32
|
+
|
33
|
+
'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Fri, 06 Apr 2012 03:37:32 GMT
|
36
|
+
recorded_with: VCR 2.0.1
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://requestb.in/yadzsfya
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: name=Abletech
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Abletech WebHook/0.0.1
|
12
|
+
Accept:
|
13
|
+
- ! '*/*'
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/html; charset=utf-8
|
23
|
+
Date:
|
24
|
+
- Fri, 06 Apr 2012 03:37:31 GMT
|
25
|
+
Content-Length:
|
26
|
+
- '3'
|
27
|
+
Connection:
|
28
|
+
- Keep-Alive
|
29
|
+
body:
|
30
|
+
encoding: US-ASCII
|
31
|
+
string: ! 'ok
|
32
|
+
|
33
|
+
'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Fri, 06 Apr 2012 03:37:31 GMT
|
36
|
+
recorded_with: VCR 2.0.1
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://requestb.in/yadzsfya
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: time=to+go
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- VCR/Agent 1.0
|
12
|
+
Accept:
|
13
|
+
- ! '*/*'
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/html; charset=utf-8
|
23
|
+
Date:
|
24
|
+
- Fri, 06 Apr 2012 04:04:10 GMT
|
25
|
+
Content-Length:
|
26
|
+
- '3'
|
27
|
+
Connection:
|
28
|
+
- Keep-Alive
|
29
|
+
body:
|
30
|
+
encoding: US-ASCII
|
31
|
+
string: ! 'ok
|
32
|
+
|
33
|
+
'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Fri, 06 Apr 2012 04:04:11 GMT
|
36
|
+
recorded_with: VCR 2.0.1
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
VCR.configure do |c|
|
10
|
+
c.cassette_library_dir = 'spec/cassettes'
|
11
|
+
c.hook_into :webmock # or :fakeweb
|
12
|
+
c.default_cassette_options = { :record => :none }
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.extend VCR::RSpec::Macros
|
17
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
config.filter_run :focus
|
20
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webhook'
|
3
|
+
|
4
|
+
describe Webhook do
|
5
|
+
describe :post do
|
6
|
+
context 'with good params' do
|
7
|
+
use_vcr_cassette 'requestbin/simple_request'
|
8
|
+
|
9
|
+
it 'returns a simple 200 response' do
|
10
|
+
code, message, body = Webhook.post('http://requestb.in/yadzsfya', :name => 'Abletech')
|
11
|
+
code.should eq('200')
|
12
|
+
message.should eq("OK")
|
13
|
+
body.should match(/ok/)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with no params' do
|
18
|
+
use_vcr_cassette 'requestbin/no_params'
|
19
|
+
|
20
|
+
it 'returns a simple 200 response' do
|
21
|
+
code, message, body = Webhook.post('http://requestb.in/yadzsfya')
|
22
|
+
code.should eq('200')
|
23
|
+
message.should eq("OK")
|
24
|
+
body.should match(/ok/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with two request headers' do
|
29
|
+
use_vcr_cassette 'requestbin/extra_headers'
|
30
|
+
|
31
|
+
it 'returns a simple 200 response' do
|
32
|
+
code, message, body = Webhook.post(
|
33
|
+
'http://requestb.in/yadzsfya',
|
34
|
+
{
|
35
|
+
'time' => 'to go'
|
36
|
+
},
|
37
|
+
{
|
38
|
+
'Referer' => 'http://www.abletech.co.nz',
|
39
|
+
'Initiator' => 'http://www.addressfinder.co.nz'
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
code.should eq('200')
|
44
|
+
message.should eq("OK")
|
45
|
+
body.should match(/ok/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a new User-Agent header' do
|
50
|
+
use_vcr_cassette 'requestbin/user_agent'
|
51
|
+
|
52
|
+
it 'returns a simple 200 response' do
|
53
|
+
code, message, body = Webhook.post(
|
54
|
+
'http://requestb.in/yadzsfya',
|
55
|
+
{
|
56
|
+
'time' => 'to go'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
'User-Agent' => 'VCR/Agent 1.0'
|
60
|
+
}
|
61
|
+
)
|
62
|
+
|
63
|
+
code.should eq('200')
|
64
|
+
message.should eq("OK")
|
65
|
+
body.should match(/ok/)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/webhook.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "webhook/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "webhook"
|
7
|
+
s.version = Webhook::VERSION
|
8
|
+
s.authors = ["Nigel Ramsay"]
|
9
|
+
s.email = ["nigel.ramsay@abletech.co.nz"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Execute webhook callbacks easily}
|
12
|
+
s.description = %q{Execute webhook callbacks easily}
|
13
|
+
|
14
|
+
s.rubyforge_project = "webhook"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "vcr"
|
25
|
+
s.add_development_dependency "webmock"
|
26
|
+
# s.add_runtime_dependency "rest-client"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webhook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nigel Ramsay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70332983852700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70332983852700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70332983851960 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70332983851960
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: vcr
|
38
|
+
requirement: &70332983851480 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70332983851480
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: webmock
|
49
|
+
requirement: &70332983851060 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70332983851060
|
58
|
+
description: Execute webhook callbacks easily
|
59
|
+
email:
|
60
|
+
- nigel.ramsay@abletech.co.nz
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/webhook.rb
|
71
|
+
- lib/webhook/version.rb
|
72
|
+
- spec/cassettes/requestbin/extra_headers.yml
|
73
|
+
- spec/cassettes/requestbin/no_params.yml
|
74
|
+
- spec/cassettes/requestbin/simple_request.yml
|
75
|
+
- spec/cassettes/requestbin/user_agent.yml
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/webhook_spec.rb
|
78
|
+
- webhook.gemspec
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: -3836839300880113512
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
hash: -3836839300880113512
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project: webhook
|
105
|
+
rubygems_version: 1.8.11
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Execute webhook callbacks easily
|
109
|
+
test_files:
|
110
|
+
- spec/cassettes/requestbin/extra_headers.yml
|
111
|
+
- spec/cassettes/requestbin/no_params.yml
|
112
|
+
- spec/cassettes/requestbin/simple_request.yml
|
113
|
+
- spec/cassettes/requestbin/user_agent.yml
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/webhook_spec.rb
|