Class: Interpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/soaspec/interpreter.rb

Overview

Help interpret the general type of a particular object

Class Method Summary collapse

Class Method Details

.response_type_for(response) ⇒ Symbol

Returns Type of provided response.

Parameters:

  • response (Object)

    API response

Returns:

  • (Symbol)

    Type of provided response



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/soaspec/interpreter.rb', line 7

def self.response_type_for(response)
  if response.is_a? String
    case response.body[0]
    when '<'
      :xml
    when '{', '['
      :json
    else
      :unknown
    end
  elsif response.is_a? Hash
    :hash
  elsif response.is_a? Nokogiri::XML::NodeSet
    :xml
  else
    :unknown
  end
end