Class: Podio::Middleware::DateConversion

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/podio/middleware/date_conversion.rb

Instance Method Summary collapse

Instance Method Details

#convert_dates(body) ⇒ Object

Converts all attributes ending with “_on” to datetime and ending with “date” to date



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/podio/middleware/date_conversion.rb', line 9

def convert_dates(body)
  [body].flatten.compact.each do |hash|
    hash.each do |key, value|
      if value.is_a?(Hash)
        convert_dates(value)
      elsif value.is_a?(Array)
        value.each_with_index { |item, index| hash[key][index] = convert_field(key, item) }
      else
        hash[key] = convert_field(key, value)
      end
    end
  end
end

#on_complete(env) ⇒ Object



4
5
6
# File 'lib/podio/middleware/date_conversion.rb', line 4

def on_complete(env)
  convert_dates(env[:body]) if env[:body].is_a?(Hash)
end