Class: Faraday::Response::CSV

Inherits:
FaradayMiddleware::ResponseMiddleware
  • Object
show all
Defined in:
lib/faraday/response/csv.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ CSV

Returns a new instance of CSV.



13
14
15
16
# File 'lib/faraday/response/csv.rb', line 13

def initialize(app = nil, options = {})
  super(app, options)
  @parser_options = options[:parser_options] || {}
end

Instance Method Details

#parse(body) ⇒ Object

Parse the response body.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/faraday/response/csv.rb', line 19

def parse(body)
  if self.class.parser
    begin
      self.class.parser.call(body, @parser_options)
    rescue StandardError, SyntaxError => err
      raise err if err.is_a? SyntaxError and err.class.name != 'Psych::SyntaxError'
      raise Faraday::Error::ParsingError, err
    end
  else
    body
  end
end