Sha256: 9a534c2fe573be5b8aa3833b5d627c57d787dfb1b20fa1b527ab7b89f7d99825

Contents?: true

Size: 1.13 KB

Versions: 139

Compression:

Stored size: 1.13 KB

Contents

dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'

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

139 entries across 114 versions & 6 rubygems

Version Path
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/custom_parsers.rb