Class: Webspicy::Web::Invocation
Instance Attribute Summary
#client, #response, #test_case
Instance Method Summary
collapse
#initialize
Instance Method Details
#done? ⇒ Boolean
15
16
17
|
# File 'lib/webspicy/web/invocation.rb', line 15
def done?
!response.nil?
end
|
#is_empty_response? ⇒ Boolean
27
28
29
|
# File 'lib/webspicy/web/invocation.rb', line 27
def is_empty_response?
response_code == 204
end
|
#is_expected_success? ⇒ Boolean
19
20
21
|
# File 'lib/webspicy/web/invocation.rb', line 19
def is_expected_success?
test_case.expected_status.to_i >= 200 && test_case.expected_status.to_i < 300
end
|
#is_redirect? ⇒ Boolean
31
32
33
|
# File 'lib/webspicy/web/invocation.rb', line 31
def is_redirect?
response_code >= 300 && response_code < 400
end
|
#is_structured_output? ⇒ Boolean
39
40
41
42
43
|
# File 'lib/webspicy/web/invocation.rb', line 39
def is_structured_output?
ct = response.content_type || test_case.expected_content_type
ct = ct.mime_type if ct.respond_to?(:mime_type)
ct =~ /json/
end
|
#is_success? ⇒ Boolean
23
24
25
|
# File 'lib/webspicy/web/invocation.rb', line 23
def is_success?
response_code >= 200 && response_code < 300
end
|
#loaded_output ⇒ Object
Also known as:
loaded_body
45
46
47
48
49
50
51
52
|
# File 'lib/webspicy/web/invocation.rb', line 45
def loaded_output
if is_structured_output?
raise "Body empty while expected" if raw_output.empty?
@loaded_output ||= ::JSON.parse(response.body)
else
raw_output
end
end
|
#output ⇒ Object
Also known as:
dressed_body, error
55
56
57
58
59
60
61
62
63
|
# File 'lib/webspicy/web/invocation.rb', line 55
def output
return loaded_output unless is_structured_output?
schema = is_expected_success? ? service.output_schema : service.error_schema
begin
schema.dress(loaded_output)
rescue Finitio::TypeError => ex
ex
end
end
|
#raw_output ⇒ Object
35
36
37
|
# File 'lib/webspicy/web/invocation.rb', line 35
def raw_output
response.body.to_s
end
|
#response_code ⇒ Object
7
8
9
10
11
|
# File 'lib/webspicy/web/invocation.rb', line 7
def response_code
code = response.status
code = code.code unless code.is_a?(Integer)
code
end
|