webhook 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +2 -1
- data/README.md +7 -6
- data/lib/webhook.rb +46 -20
- data/lib/webhook/configuration.rb +33 -0
- data/lib/webhook/version.rb +1 -1
- data/spec/webhook/configuration_spec.rb +43 -0
- metadata +19 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32a93cff9850d21751f4eca676e3e57c69f7620c
|
4
|
+
data.tar.gz: 84f65543bf73073d0eaadd9621702ee60f20d845
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50c96282c69021f9054d4545eaf3d3f95a86ee12c0df3ef9d89fa046cacd0d93cabf928bb7ea5d0393f57ff7d63ba50979d9729c7ba719503450980286ec7357
|
7
|
+
data.tar.gz: 8cc3a8f7f973411747cdfd3bbb35af6076f6395b1570d5dc4658b75ad5cc7199a431a160aa5b417c158988b3129f1e40e04a7d86f70978180e2daa94bb393a70
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# Webhook
|
2
2
|
|
3
|
-
|
3
|
+
[![Code Climate](https://codeclimate.com/github/AbleTech/webhook.png)](https://codeclimate.com/github/AbleTech/webhook)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/AbleTech/webhook.png)](http://travis-ci.org/AbleTech/webhook)
|
5
|
+
|
6
|
+
Client library for making webhook calls. Compatible with Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, REE, JRuby 1.8 and 1.9.
|
4
7
|
|
5
|
-
There are no runtime dependencies.
|
8
|
+
There are no runtime dependencies.
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
10
13
|
|
11
|
-
gem 'webhook', '~> 0.0
|
14
|
+
gem 'webhook', '~> 0.1.0'
|
12
15
|
|
13
16
|
And then execute:
|
14
17
|
|
@@ -34,12 +37,10 @@ Or install it yourself as:
|
|
34
37
|
|
35
38
|
rake spec
|
36
39
|
|
37
|
-
[![Build Status](https://secure.travis-ci.org/AbleTech/webhook.png)](http://travis-ci.org/AbleTech/webhook)
|
38
|
-
|
39
40
|
## Contributing
|
40
41
|
|
41
42
|
1. Fork it
|
42
43
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
44
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
45
|
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
-
5. Create new Pull Request
|
46
|
+
5. Create new Pull Request
|
data/lib/webhook.rb
CHANGED
@@ -1,28 +1,54 @@
|
|
1
1
|
require "webhook/version"
|
2
|
+
require "webhook/configuration"
|
2
3
|
require 'net/http'
|
3
4
|
|
4
5
|
module Webhook
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# A Webhook configuration object. Must act like a hash and return sensible
|
10
|
+
# values for all Webhook configuration options.
|
11
|
+
# @see Webhook::Configuration.
|
12
|
+
attr_writer :configuration
|
13
|
+
|
14
|
+
# The configuration object.
|
15
|
+
# @see Webhook.configure
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# Call this method to modify defaults in your initializers.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# Webhook.configure do |config|
|
24
|
+
# config.user_agent = "Webhook"
|
25
|
+
# end
|
26
|
+
def configure
|
27
|
+
yield(configuration)
|
24
28
|
end
|
25
29
|
|
26
|
-
|
30
|
+
def post(url, form_fields={}, request_headers={}, proxy_settings={})
|
31
|
+
headers = {
|
32
|
+
"User-Agent" => configuration.user_agent
|
33
|
+
}.merge(request_headers)
|
34
|
+
|
35
|
+
uri = URI.parse(url)
|
36
|
+
use_ssl = (uri.scheme.downcase == 'https')
|
37
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
38
|
+
req.form_data = form_fields
|
39
|
+
|
40
|
+
begin
|
41
|
+
http_session = Net::HTTP::Proxy(proxy_settings[:host], proxy_settings[:port]).new(uri.host, uri.port)
|
42
|
+
http_session.use_ssl = true if use_ssl
|
43
|
+
|
44
|
+
response = http_session.start { |http|
|
45
|
+
http.request(req)
|
46
|
+
}
|
47
|
+
rescue => e
|
48
|
+
raise "Unable to open stream: #{uri.to_s}; \n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
49
|
+
end
|
50
|
+
|
51
|
+
return response.code, response.message, response.body
|
52
|
+
end
|
27
53
|
end
|
28
54
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Webhook
|
2
|
+
class Configuration
|
3
|
+
OPTIONS = [:user_agent]
|
4
|
+
|
5
|
+
attr_accessor :user_agent
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@user_agent = "Webhook"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Allows config options to be read like a hash
|
12
|
+
#
|
13
|
+
# @param [Symbol] option Key for a given attribute
|
14
|
+
def [](option)
|
15
|
+
send(option)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash of all configurable options
|
19
|
+
def to_hash
|
20
|
+
OPTIONS.inject({}) do |hash, option|
|
21
|
+
hash[option.to_sym] = self.send(option)
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a hash of all configurable options merged with +hash+
|
27
|
+
#
|
28
|
+
# @param [Hash] hash A set of configuration options that will take precedence over the defaults
|
29
|
+
def merge(hash)
|
30
|
+
to_hash.merge(hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/webhook/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webhook'
|
3
|
+
|
4
|
+
describe Webhook::Configuration do
|
5
|
+
|
6
|
+
it "provides default values" do
|
7
|
+
assert_config_default :user_agent, "Webhook"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "allows values to be overwritten" do
|
11
|
+
assert_config_overridable :user_agent
|
12
|
+
end
|
13
|
+
|
14
|
+
it "acts like a hash" do
|
15
|
+
config = Webhook::Configuration.new
|
16
|
+
hash = config.to_hash
|
17
|
+
Webhook::Configuration::OPTIONS.each do |option|
|
18
|
+
config[option].should eq(hash[option])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is mergable" do
|
23
|
+
config = Webhook::Configuration.new
|
24
|
+
hash = config.to_hash
|
25
|
+
config.merge(:key => 'value').should eq(hash.merge(:key => 'value'))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "gives a new instance if non defined" do
|
29
|
+
Webhook.configuration = nil
|
30
|
+
Webhook.configuration.should be_a_kind_of(Webhook::Configuration)
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_config_default(option, default_value, config = nil)
|
34
|
+
config ||= Webhook::Configuration.new
|
35
|
+
config.send(option).should eq(default_value)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_config_overridable(option, value = 'a value')
|
39
|
+
config = Webhook::Configuration.new
|
40
|
+
config.send(:"#{option}=", value)
|
41
|
+
config.send(option).should eq(value)
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webhook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nigel Ramsay
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: vcr
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: fakeweb
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Execute webhook callbacks easily
|
@@ -89,43 +80,38 @@ files:
|
|
89
80
|
- README.md
|
90
81
|
- Rakefile
|
91
82
|
- lib/webhook.rb
|
83
|
+
- lib/webhook/configuration.rb
|
92
84
|
- lib/webhook/version.rb
|
93
85
|
- spec/cassettes/requestbin/extra_headers.yml
|
94
86
|
- spec/cassettes/requestbin/no_params.yml
|
95
87
|
- spec/cassettes/requestbin/simple_request.yml
|
96
88
|
- spec/cassettes/requestbin/user_agent.yml
|
97
89
|
- spec/spec_helper.rb
|
90
|
+
- spec/webhook/configuration_spec.rb
|
98
91
|
- spec/webhook_spec.rb
|
99
92
|
- webhook.gemspec
|
100
93
|
homepage: ''
|
101
94
|
licenses: []
|
95
|
+
metadata: {}
|
102
96
|
post_install_message:
|
103
97
|
rdoc_options: []
|
104
98
|
require_paths:
|
105
99
|
- lib
|
106
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
101
|
requirements:
|
109
|
-
- -
|
102
|
+
- - '>='
|
110
103
|
- !ruby/object:Gem::Version
|
111
104
|
version: '0'
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
hash: -687198169506099036
|
115
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
106
|
requirements:
|
118
|
-
- -
|
107
|
+
- - '>='
|
119
108
|
- !ruby/object:Gem::Version
|
120
109
|
version: '0'
|
121
|
-
segments:
|
122
|
-
- 0
|
123
|
-
hash: -687198169506099036
|
124
110
|
requirements: []
|
125
111
|
rubyforge_project: webhook
|
126
|
-
rubygems_version:
|
112
|
+
rubygems_version: 2.0.3
|
127
113
|
signing_key:
|
128
|
-
specification_version:
|
114
|
+
specification_version: 4
|
129
115
|
summary: Execute webhook callbacks easily
|
130
116
|
test_files:
|
131
117
|
- spec/cassettes/requestbin/extra_headers.yml
|
@@ -133,4 +119,6 @@ test_files:
|
|
133
119
|
- spec/cassettes/requestbin/simple_request.yml
|
134
120
|
- spec/cassettes/requestbin/user_agent.yml
|
135
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/webhook/configuration_spec.rb
|
136
123
|
- spec/webhook_spec.rb
|
124
|
+
has_rdoc:
|