clients/kratos/ruby/lib/ory-kratos-client/api_client.rb
# Convert data to the given return type.
# @param [Object] data Data to be converted
# @param [String] return_type Return type
# @return [Mixed] Data in a particular type
Convert data to the given return type.
Convert data to the given return type .
def convert_to_type(data, return_type)
      return nil if data.nil?
      case return_type
      when 'String'
        data.to_s
      when 'Integer'
        data.to_i
      when 'Float'
        data.to_f
      when 'Boolean'
        data == true
      when 'Time'
        Time.parse data
      when 'Date'
        Date.parse data
      when 'Object'
        data
      when /\AArray<(.+)>\z/
        sub_type = $1
        data.map { |item| convert_to_type(item, sub_type) }
      when /\AHash\<String, (.+)\>\z/
        sub_type = $1
        {}.tap do |hash|
          data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
        end
      else
        klass = OryHydraClient.const_get(return_type)
        klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
      end
    end
def convert_to_type ( data , return_type ) return nil if data . nil? case return_type when 'String' data . to_s when 'Integer' data . to_i when 'Float' data . to_f when 'Boolean' data == true when 'Time' Time . parse data when 'Date' Date . parse data when 'Object' data when / \A Array<(.+)> \z / sub_type = $1 data . map { | item | convert_to_type ( item , sub_type ) } when / \A Hash \< String, (.+) \> \z / sub_type = $1 { } . tap do | hash | data . each { | k , v | hash [ k ] = convert_to_type ( v , sub_type ) } end else klass = OryHydraClient . const_get ( return_type ) klass . respond_to? ( :openapi_one_of ) ? klass . build ( data ) : klass . build_from_hash ( data ) end end
Convert data to the given return type.
Convert data to the given return type .
# parse date time (expecting ISO 8601 format) # parse date time (expecting ISO 8601 format) # generic object (usually a Hash), return directly # e.g. Array<Pet> # e.g. Hash<String, Integer> # models (e.g. Pet) or oneOf
Data in a particular type
Data in a particular type
Mixed
data
<not_specific>
return_type
<not_specific>
<not_specific>
return_type Return type
return_type Return type