Class: WebHookDispatcher
- Inherits:
-
Object
- Object
- WebHookDispatcher
- Defined in:
- lib/webhook-dispatcher/core.rb,
lib/webhook-dispatcher/version.rb,
lib/webhook-dispatcher/request/base.rb,
lib/webhook-dispatcher/acl/deny_entry.rb,
lib/webhook-dispatcher/acl/entry_base.rb,
lib/webhook-dispatcher/acl/allow_entry.rb
Defined Under Namespace
Modules: Request Classes: Acl, Response
Constant Summary collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.acl ⇒ Object
Returns the value of attribute acl.
-
.open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
.read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
.user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Attribute Summary collapse
-
#acl ⇒ Object
Returns the value of attribute acl.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Class Method Summary collapse
Instance Method Summary collapse
- #acl_with(&block) ⇒ Object
- #get(uri) ⇒ Object
- #head(uri) ⇒ Object
-
#initialize(options = {}) ⇒ WebHookDispatcher
constructor
A new instance of WebHookDispatcher.
- #post(uri, body = nil) ⇒ Object
- #request(request) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ WebHookDispatcher
Returns a new instance of WebHookDispatcher.
11 12 13 14 15 16 17 18 |
# File 'lib/webhook-dispatcher/core.rb', line 11 def initialize( = {}) = .dup @open_timeout = .delete(:open_timeout) || self.class.open_timeout || self.class.default_open_timeout @read_timeout = .delete(:read_timeout) || self.class.read_timeout || self.class.default_read_timeout @user_agent = .delete(:user_agent) || self.class.user_agent || self.class.default_user_agent @acl = .delete(:acl) || self.class.acl || self.class.default_acl raise(ArgumentError, "invalid parameter") unless .empty? end |
Class Attribute Details
.acl ⇒ Object
Returns the value of attribute acl.
26 27 28 |
# File 'lib/webhook-dispatcher/core.rb', line 26 def acl @acl end |
.open_timeout ⇒ Object
Returns the value of attribute open_timeout.
26 27 28 |
# File 'lib/webhook-dispatcher/core.rb', line 26 def open_timeout @open_timeout end |
.read_timeout ⇒ Object
Returns the value of attribute read_timeout.
26 27 28 |
# File 'lib/webhook-dispatcher/core.rb', line 26 def read_timeout @read_timeout end |
.user_agent ⇒ Object
Returns the value of attribute user_agent.
26 27 28 |
# File 'lib/webhook-dispatcher/core.rb', line 26 def user_agent @user_agent end |
Instance Attribute Details
#acl ⇒ Object
Returns the value of attribute acl.
38 39 40 |
# File 'lib/webhook-dispatcher/core.rb', line 38 def acl @acl end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
38 39 40 |
# File 'lib/webhook-dispatcher/core.rb', line 38 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
38 39 40 |
# File 'lib/webhook-dispatcher/core.rb', line 38 def read_timeout @read_timeout end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
38 39 40 |
# File 'lib/webhook-dispatcher/core.rb', line 38 def user_agent @user_agent end |
Class Method Details
Instance Method Details
#acl_with(&block) ⇒ Object
40 41 42 |
# File 'lib/webhook-dispatcher/core.rb', line 40 def acl_with(&block) self.acl = Acl.with(&block) end |
#get(uri) ⇒ Object
86 87 88 |
# File 'lib/webhook-dispatcher/core.rb', line 86 def get(uri) return self.request(Request::Get.new(uri)) end |
#head(uri) ⇒ Object
90 91 92 |
# File 'lib/webhook-dispatcher/core.rb', line 90 def head(uri) return self.request(Request::Head.new(uri)) end |
#post(uri, body = nil) ⇒ Object
94 95 96 |
# File 'lib/webhook-dispatcher/core.rb', line 94 def post(uri, body = nil) return self.request(Request::Post.new(uri, body)) end |
#request(request) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/webhook-dispatcher/core.rb', line 44 def request(request) http_conn = request.create_http_connector http_req = request.create_http_request setup_http_connector(http_conn) setup_http_request(http_req) begin if @acl.deny?(http_conn.address, http_conn.port) return Response.new( :status => :denied, :message => "denied.") end http_res = http_conn.start { http_conn.request(http_req) } return Response.new( :status => (http_res.kind_of?(Net::HTTPSuccess) ? :success : :failure), :http_code => http_res.code.to_i, :message => http_res.) rescue TimeoutError => e return Response.new( :status => :timeout, :message => "timeout.", :exception => e) rescue Errno::ECONNREFUSED => e return Response.new( :status => :refused, :message => "connection refused.", :exception => e) rescue Errno::ECONNRESET => e return Response.new( :status => :reset, :message => "connection reset by peer.", :exception => e) rescue => e return Response.new( :status => :error, :message => "#{e.class}: #{e.}", :exception => e) end end |