tribune-is_it_working 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f70db6751d5a718bc6c9c4210f01ecccabe49fe5be8ad6422a2a2992598df58
4
- data.tar.gz: 973f90428a9a853723cf309f74ed0719447585ee630393382acfdae9ae84239a
3
+ metadata.gz: b22be9cda692ebefffa0f9af6877afa972d1dbbc83d12d202163767c9d360dd4
4
+ data.tar.gz: e61c1188e1061ccd69ea3c83eb036d83fa9184b61058bd293a49ac07022f4ebf
5
5
  SHA512:
6
- metadata.gz: 60c6c990e0888cca33a78a71c1aaec08cf6d57cf51504c81c0fa2732c7e10e579b0afe1ed1b3a39c467cc8a176cc7cf3ffdd31f49e22060f524bacb1a824f8f9
7
- data.tar.gz: 43f6eb2a43e569e7fc4d8c0dcf383b02581cf7a8041d9536a5c81da1e4ce06f38ea01c4df7002042b5db15b48528590872ece003b8d05b9eea614fddf8fba101
6
+ metadata.gz: affa26c31930fe117b92e37e07c8265eadadcbb8685f3c74bfb1fe00d53197c82cf035cc9665fce0d9959069dcd0293142830f72df2537ad5c5cabd97dc83d5e
7
+ data.tar.gz: 6b3ed70ced13c6b0f92b8a5c40f60d6cb031d68f50bdc6b3f429659e26e336364933dcb01e26e66819f03f972055d8493202de179c9d595c7ce10edab5436120
@@ -20,30 +20,41 @@ module IsItWorking
20
20
  #
21
21
  # IsItWorking::Handler.new do |h|
22
22
  # h.check :url, :get => "http://services.example.com/api", :headers => {"Accept" => "text/xml"}
23
+ # h.check :url, :post => "http://services.example.com/api",:headers => {"Content-Type" => "application/json"}
23
24
  # end
24
25
  class UrlCheck
26
+ attr_accessor :request_method
25
27
  def initialize(options={})
26
- raise ArgumentError.new(":get must provide the URL to check") unless options[:get]
27
- @uri = URI.parse(options[:get])
28
+ # TODO: Add support for PUT, DELETE & PATCH request methods
29
+ raise ArgumentError.new(":get|:post must provide the URL to check") unless options[:get] || options[:post]
30
+ # request method (get|post|put|delete)
31
+ @request_method = if options.key?(:get)
32
+ :get
33
+ elsif options.key?(:post)
34
+ :post
35
+ else
36
+ :get # fallback
37
+ end
38
+ @uri = URI.parse(options[request_method])
28
39
  @headers = options[:headers] || {}
29
40
  @proxy = options[:proxy]
30
41
  @username = options[:username]
31
42
  @password = options[:password]
32
43
  @open_timeout = options[:open_timeout] || 5
33
44
  @read_timeout = options[:read_timeout] || 10
34
- @alias = options[:alias] || options[:get]
45
+ @alias = options[:alias] || options[request_method]
35
46
  end
36
47
 
37
48
  def call(status)
38
49
  t = Time.now
39
50
  response = perform_http_request
40
51
  if response.is_a?(Net::HTTPSuccess)
41
- status.ok("GET #{@alias} responded with response '#{response.code} #{response.message}'")
52
+ status.ok("#{request_method.upcase} #{@alias} responded with response '#{response.code} #{response.message}'")
42
53
  else
43
- status.fail("GET #{@alias} failed with response '#{response.code} #{response.message}'")
54
+ status.fail("#{request_method.upcase} #{@alias} failed with response '#{response.code} #{response.message}'")
44
55
  end
45
56
  rescue Timeout::Error
46
- status.fail("GET #{@alias} timed out after #{Time.now - t} seconds")
57
+ status.fail("#{request_method.upcase} #{@alias} timed out after #{Time.now - t} seconds")
47
58
  end
48
59
 
49
60
  private
@@ -70,7 +81,12 @@ module IsItWorking
70
81
 
71
82
  # Perform an HTTP request and return the response
72
83
  def perform_http_request #:nodoc:
73
- request = Net::HTTP::Get.new(@uri.request_uri, @headers)
84
+ case request_method
85
+ when :post
86
+ request = Net::HTTP::Post.new(@uri.request_uri, @headers)
87
+ else
88
+ request = Net::HTTP::Get.new(@uri.request_uri, @headers)
89
+ end
74
90
  request.basic_auth(@username, @password) if @username || @password
75
91
  http = instantiate_http
76
92
  http.start do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tribune-is_it_working
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand