Sha256: 25c96e27321bf3f78211b9ec30bf70b604568257416f1358131ef84788f0a917

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

class ParseAtom
  include HTTParty

  # Support Atom along with the default parsers: xml, json, etc.
  class Parser::Atom < HTTParty::Parser
    SupportedFormats.merge!({"application/atom+xml" => :atom})

    protected

    # perform atom parsing on body
    def atom
      body.to_atom
    end
  end

  parser Parser::Atom
end

class OnlyParseAtom
  include HTTParty

  # Only support Atom
  class Parser::OnlyAtom < HTTParty::Parser
    SupportedFormats = {"application/atom+xml" => :atom}

    protected

    # perform atom parsing on body
    def atom
      body.to_atom
    end
  end

  parser Parser::OnlyAtom
end

class SkipParsing
  include HTTParty

  # Parse the response body however you like
  class Parser::Simple < HTTParty::Parser
    def parse
      body
    end
  end

  parser Parser::Simple
end

class AdHocParsing
  include HTTParty
  parser(
    proc do |body, format|
      case format
      when :json
        body.to_json
      when :xml
        body.to_xml
      else
        body
      end
    end
  )
end

Version data entries

8 entries across 7 versions & 3 rubygems

Version Path
httparty-0.14.0 examples/custom_parsers.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/1.9.1/gems/httparty-0.13.7/examples/custom_parsers.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/2.0.0/gems/httparty-0.13.7/examples/custom_parsers.rb
httparty-0.13.7 examples/custom_parsers.rb
httparty-0.13.6 examples/custom_parsers.rb
httpserious-0.13.5.lstoll1 examples/custom_parsers.rb
httparty-0.13.5 examples/custom_parsers.rb
httparty-0.13.4 examples/custom_parsers.rb