class DeskApi::Response::ParseDates

The {DeskApi::Response::ParseDates} middleware parses strings to dates if they look like ISO8601

@author Thomas Stachl <tstachl@salesforce.com> @copyright Copyright © 2013-2016 Salesforce.com @license BSD 3-Clause License

Public Instance Methods

on_complete(env) click to toggle source

Calls the `parse_dates` method on the body

# File lib/desk_api/response/parse_dates.rb, line 41
def on_complete(env)
  env[:body] = parse_dates env[:body]
end

Private Instance Methods

parse_dates(value) click to toggle source

Checks the value and calls it self for Hash/Array, parses strings that look like ISO8601 or returns the value

@return [Mixed]

# File lib/desk_api/response/parse_dates.rb, line 52
def parse_dates(value)
  case value
  when Hash
    value.each_pair do |key, element|
      value[key] = parse_dates element
    end
  when Array
    value.each_with_index do |element, index|
      value[index] = parse_dates element
    end
  when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z\Z/m
    Time.parse value
  else
    value
  end
end