Sha256: d2d1e6661fd3653ffa11ecadef5592ef1051e38c39470c372db0c840b68c19bf

Contents?: true

Size: 786 Bytes

Versions: 30

Compression:

Stored size: 786 Bytes

Contents

require 'time'
require "faraday/response"

module ZendeskAPI
  module Middleware
    module Response
      # Parse ISO dates from response body
      # @private
      class ParseIsoDates < Faraday::Response::Middleware
        def call(env)
          @app.call(env).on_complete do |env|
            parse_dates!(env[:body])
          end
        end

        private

        def parse_dates!(value)
          case value
          when Hash then value.each { |key, element| value[key] = parse_dates!(element) }
          when Array then value.each_with_index { |element, index| value[index] = parse_dates!(element) }
          when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\Z/m then Time.parse(value)
          else
            value
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
zendesk_api-1.37.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.36.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.35.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.34.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
discourse_zendesk_api-1.0.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
discourse_zendesk_api-1.0.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.33.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.32.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.31.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.30.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.29.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.28.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.27.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.26.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.25.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.24.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.23.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.22.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.21.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.20.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb