Class: Opener::CallbackHandler::Strategies::Http
- Inherits:
-
Object
- Object
- Opener::CallbackHandler::Strategies::Http
- Defined in:
- lib/opener/callback_handler/strategies/http.rb
Overview
Strategy for submitting data to a regular HTTP URL. This strategy submits data as JSON while making sure the correct Content-Type header is set.
Constant Summary collapse
- HEADERS =
The headers to use when submitting data.
{ 'Content-Type' => 'application/json' }
Instance Attribute Summary collapse
- #http ⇒ HTTPClient readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Http
constructor
A new instance of Http.
- #process(url, params = {}) ⇒ Object
Constructor Details
#initialize ⇒ Http
Returns a new instance of Http.
32 33 34 |
# File 'lib/opener/callback_handler/strategies/http.rb', line 32 def initialize @http = HTTPClient.new end |
Instance Attribute Details
#http ⇒ HTTPClient (readonly)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/opener/callback_handler/strategies/http.rb', line 12 class Http attr_reader :http ## # The headers to use when submitting data. # # @return [Hash] # HEADERS = { 'Content-Type' => 'application/json' } ## # @param [String] url # @return [TrueClass|FalseClass] # def self.pass_validation?(url) return !!Regexp.new("^https?:\/\/.+").match(url) end def initialize @http = HTTPClient.new end ## # @param [String] url # @param [Hash] params # def process(url, params = {}) body = JSON.dump(params) http.post(url, body, HEADERS) end end |
Class Method Details
.pass_validation?(url) ⇒ TrueClass|FalseClass
28 29 30 |
# File 'lib/opener/callback_handler/strategies/http.rb', line 28 def self.pass_validation?(url) return !!Regexp.new("^https?:\/\/.+").match(url) end |
Instance Method Details
#process(url, params = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/opener/callback_handler/strategies/http.rb', line 40 def process(url, params = {}) body = JSON.dump(params) http.post(url, body, HEADERS) end |