Sha256: e72b05cf8c2fbe5829f24b30e606b8051cca4520dea063c9209bbcbba2142359

Contents?: true

Size: 1.02 KB

Versions: 33

Compression:

Stored size: 1.02 KB

Contents

class ParseAtom
  include HTTParty

  # Support Atom along with the default parsers: xml, json, yaml, 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.new do |body, format|
      case format
      when :json
        body.to_json
      when :xml
        body.to_xml
      else
        body
      end
    end
  )
end

Version data entries

33 entries across 33 versions & 8 rubygems

Version Path
dkastner-httparty-0.9.0 examples/custom_parsers.rb
httparty-0.9.0 examples/custom_parsers.rb
httparty-0.8.3 examples/custom_parsers.rb
httparty-0.8.2 examples/custom_parsers.rb
nutshell-crm-0.0.6.alpha vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
nutshell-crm-0.0.5 vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
nutshell-crm-0.0.4 vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
nutshell-crm-0.0.3 vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
nutshell-crm-0.0.2 vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
nutshell-crm-0.0.1 vendor/bundle/gems/httparty-0.8.1/examples/custom_parsers.rb
httparty-0.8.1 examples/custom_parsers.rb
httparty-0.8.0 examples/custom_parsers.rb
httparty2-0.7.10 examples/custom_parsers.rb
httparty-0.7.8 examples/custom_parsers.rb
httparty-0.7.7 examples/custom_parsers.rb
httparty-0.7.6 examples/custom_parsers.rb
httparty-0.7.4 examples/custom_parsers.rb
httparty-0.7.3 examples/custom_parsers.rb
httparty-0.7.2 examples/custom_parsers.rb
httparty-0.7.0 examples/custom_parsers.rb