Sha256: 4f2fa0d641933132b2ec539dbda5d324b168e6b028d90c805529037b89d759fd

Contents?: true

Size: 550 Bytes

Versions: 6

Compression:

Stored size: 550 Bytes

Contents

require 'oj'
require 'ox'
require 'dagger/ox_extension'

class Parsers

  def initialize(response)
    @body = response.body
    @normalized = response.content_type.to_s.sub('/', '_').split(';').first
  end

  def process
    send(@normalized, @body) if respond_to?(@normalized)
  end

  def application_json(body)
    Oj.load(body)
  rescue Oj::ParseError
    nil
  end

  alias_method :text_javascript, :application_json

  def text_xml(body)
    Ox.parse(body)
  rescue Ox::ParseError
    nil
  end

  alias_method :application_xml, :text_xml

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dagger-0.8.0 lib/dagger/parsers.rb
dagger-0.7.0 lib/dagger/parsers.rb
dagger-0.6.1 lib/dagger/parsers.rb
dagger-0.6.0 lib/dagger/parsers.rb
dagger-0.5.1 lib/dagger/parsers.rb
dagger-0.5.0 lib/dagger/parsers.rb