Sha256: 242a380c29beb1bc6a29d33a4ded28e1bdbaa748370cc06dc379b9ae0b86f42f
Contents?: true
Size: 901 Bytes
Versions: 13
Compression:
Stored size: 901 Bytes
Contents
# Help interpret the general type of a particular object class Interpreter class << self # @param [Object] response API response # @return [Symbol] Type of provided response def response_type_for(response) @response = response if @response.is_a? String if xml? :xml elsif json? :json else :unknown end elsif response.is_a? Hash :hash elsif response.is_a? Nokogiri::XML::NodeSet :xml else :unknown end end # @return [Boolean] Whether valid XML def xml? Nokogiri::XML(@response) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT } rescue Nokogiri::XML::SyntaxError false end # @return [Boolean] Whether valid JSON def json? JSON.parse(@response) rescue JSON::ParserError false end end end
Version data entries
13 entries across 13 versions & 1 rubygems