Sha256: 22d8f5ee580f7f4d6c4fed33fc0faaf2f8ca509a06d9ac7953bd2c6cf0cc922b

Contents?: true

Size: 786 Bytes

Versions: 12

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)
          response = @app.call(env)
          parse_dates! response.env[:body]
          response
        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

12 entries across 12 versions & 1 rubygems

Version Path
zendesk_api-0.3.2 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.3.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.3.0 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.2.6 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.2.5 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.2.4 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.2.2 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.2.1 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.1.11 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.1.10 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.1.9 lib/zendesk_api/middleware/response/parse_iso_dates.rb
zendesk_api-0.1.8 lib/zendesk_api/middleware/response/parse_iso_dates.rb