Sha256: 810cf024042f7514ed5605500b11e5c0e6fb559214c3716a19a7a350e8ce525d

Contents?: true

Size: 785 Bytes

Versions: 87

Compression:

Stored size: 785 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

87 entries across 87 versions & 1 rubygems

Version Path
zendesk_api-1.13.4 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.13.3 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.13.2 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.13.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.12.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.12.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.7 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.6 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.5 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.4 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.3 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.2 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.11.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.10.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.9.6 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.9.5 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.9.4 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.9.3 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-1.9.2 lib/zendesk_api/middleware/response/parse_iso_dates.rb