Class: Fiddler::Parsers::BaseParser
- Inherits:
-
Object
- Object
- Fiddler::Parsers::BaseParser
show all
- Defined in:
- lib/fiddler/parsers/base_parser.rb
Constant Summary
collapse
- SUCCESS_CODES =
(200..299).to_a
- ERROR_CODES =
(400..499).to_a
Class Method Summary
collapse
Class Method Details
.check_response_code(response, reject_blank_lines = true, raise_error_for_empty_response = true) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/fiddler/parsers/base_parser.rb', line 8
def self.check_response_code(response, reject_blank_lines=true, raise_error_for_empty_response=true)
response = safe_encode(response)
lines = response.split("\n")
lines = lines.delete_if { |l| l.nil? or l == "" } if reject_blank_lines
if lines.count == 0
if raise_error_for_empty_response
raise RequestError, "Empty Response"
else
return []
end
else
status_line = lines.shift
version, status_code, status_text = status_line.split(/\s+/,2)
unless SUCCESS_CODES.include?(status_code.to_i)
raise RequestError, status_text
end
lines.shift unless reject_blank_lines
lines
end
end
|
.tokenize_response(response) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/fiddler/parsers/base_parser.rb', line 29
def self.tokenize_response(response)
tokens = Array.new
current = Array.new
response.each do |item|
if(item == "--")
tokens << current
current = Array.new
next
end
current << item
end
tokens << current unless current.empty?
tokens
end
|