Class: Quinoa::Service
- Inherits:
-
Object
- Object
- Quinoa::Service
- Defined in:
- lib/quinoa/service.rb
Instance Attribute Summary collapse
-
#accept ⇒ Object
Returns the value of attribute accept.
-
#assertions ⇒ Object
Returns the value of attribute assertions.
-
#authorization ⇒ Object
Returns the value of attribute authorization.
-
#body ⇒ Object
Returns the value of attribute body.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#custom_headers ⇒ Object
Returns the value of attribute custom_headers.
-
#expectations ⇒ Object
Returns the value of attribute expectations.
-
#path ⇒ Object
Returns the value of attribute path.
-
#response ⇒ Object
Returns the value of attribute response.
-
#time ⇒ Object
Returns the value of attribute time.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_custom_header(custom_header_name, custom_header_value) ⇒ Object
- #add_expected_body_string(value) ⇒ Object
- #add_expected_max_response_time(value) ⇒ Object
- #add_expected_status(value) ⇒ Object
- #check! ⇒ Object
- #get!(url = nil) ⇒ Object
-
#initialize(url) ⇒ Service
constructor
A new instance of Service.
- #post!(url = nil) ⇒ Object
- #put!(url = nil) ⇒ Object
- #remove_custom_header(custom_header_name) ⇒ Object
- #report ⇒ Object
- #response_accept ⇒ Object
- #response_body ⇒ Object
- #response_code ⇒ Object
- #response_content_type ⇒ Object
- #response_location ⇒ Object
Constructor Details
#initialize(url) ⇒ Service
Returns a new instance of Service.
11 12 13 14 15 16 17 18 19 |
# File 'lib/quinoa/service.rb', line 11 def initialize url self.time = "" self.path = "" self. = "" self.custom_headers = {} self.expectations = {} self.assertions = {} self.url = url end |
Instance Attribute Details
#accept ⇒ Object
Returns the value of attribute accept.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def accept @accept end |
#assertions ⇒ Object
Returns the value of attribute assertions.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def assertions @assertions end |
#authorization ⇒ Object
Returns the value of attribute authorization.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def @authorization end |
#body ⇒ Object
Returns the value of attribute body.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def body @body end |
#content_type ⇒ Object
Returns the value of attribute content_type.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def content_type @content_type end |
#custom_headers ⇒ Object
Returns the value of attribute custom_headers.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def custom_headers @custom_headers end |
#expectations ⇒ Object
Returns the value of attribute expectations.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def expectations @expectations end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def path @path end |
#response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def response @response end |
#time ⇒ Object
Returns the value of attribute time.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def time @time end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/quinoa/service.rb', line 9 def url @url end |
Instance Method Details
#add_custom_header(custom_header_name, custom_header_value) ⇒ Object
73 74 75 |
# File 'lib/quinoa/service.rb', line 73 def add_custom_header custom_header_name, custom_header_value self.custom_headers.merge! custom_header_name.to_sym => custom_header_value.to_s end |
#add_expected_body_string(value) ⇒ Object
117 118 119 |
# File 'lib/quinoa/service.rb', line 117 def add_expected_body_string value add_expectation "body", value, "contains" end |
#add_expected_max_response_time(value) ⇒ Object
121 122 123 |
# File 'lib/quinoa/service.rb', line 121 def add_expected_max_response_time value add_expectation "response_time", value, "under" end |
#add_expected_status(value) ⇒ Object
113 114 115 |
# File 'lib/quinoa/service.rb', line 113 def add_expected_status value add_expectation "status_code", value, "eq", :fail end |
#check! ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/quinoa/service.rb', line 95 def check! #TO DO: Handle case when response is nil exit 0 if self.response.nil? self.expectations.each do | expectation | assertion_item = expectation[0] expectation_map = Hash[*expectation][assertion_item] self.assertions.merge! get_assertion_record( assertion_item, expectation_map[:value], check_attribute?( assertion_item, expectation_map[:value], expectation_map[:compare_using]), expectation_map[:level]) end end |
#get!(url = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quinoa/service.rb', line 29 def get! url=nil begin if url == nil get_time { RestClient.get( self.url + self.path, {:accept => self.accept, :authorization => self.}.merge!(self.custom_headers) ) } else get_time { RestClient.get( url, {:accept => self.accept, :authorization => self.}.merge!(self.custom_headers) ) } end rescue => e self.response = e.response end end |
#post!(url = nil) ⇒ Object
25 26 27 |
# File 'lib/quinoa/service.rb', line 25 def post! url=nil p_methods("post", url) end |
#put!(url = nil) ⇒ Object
21 22 23 |
# File 'lib/quinoa/service.rb', line 21 def put! url=nil p_methods("put", url) end |
#remove_custom_header(custom_header_name) ⇒ Object
77 78 79 |
# File 'lib/quinoa/service.rb', line 77 def remove_custom_header custom_header_name self.custom_headers.delete custom_header_name.to_sym end |
#report ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/quinoa/service.rb', line 81 def report JSON.pretty_generate( { :health => get_health(self.assertions.map{|a| a[1][:status]}), :response => { :status_code => self.response.code, :response_body => self.response.body, :response_time => self.time.real }, :assertions => self.assertions } ) end |
#response_accept ⇒ Object
57 58 59 |
# File 'lib/quinoa/service.rb', line 57 def response_accept self.response.headers[:accept] end |
#response_body ⇒ Object
65 66 67 |
# File 'lib/quinoa/service.rb', line 65 def response_body self.response.body end |
#response_code ⇒ Object
53 54 55 |
# File 'lib/quinoa/service.rb', line 53 def response_code self.response.code end |
#response_content_type ⇒ Object
61 62 63 |
# File 'lib/quinoa/service.rb', line 61 def response_content_type self.response.headers[:content_type] end |
#response_location ⇒ Object
69 70 71 |
# File 'lib/quinoa/service.rb', line 69 def response_location self.response.headers[:location] end |