Sha256: 83fb29f4b5414b752974cf62c1490fa5765f86d6f181b73885830625056c7803

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

module Twilio
  def self.serialize_iso8601_date(date)
    if date.eql?(:unset)
      date
    elsif date.is_a?(Date)
      date.iso8601
    elsif date.is_a?(Time)
      date.strftime('%Y-%m-%d')
    elsif date.is_a?(String)
      date
    end
  end

  def self.serialize_iso8601_datetime(date)
    if date.eql?(:unset)
      date
    elsif date.is_a?(Date)
      Time.new(date.year, date.month, date.day).utc.iso8601
    elsif date.is_a?(Time)
      date.utc.iso8601
    elsif date.is_a?(String)
      date
    end
  end

  def self.deserialize_rfc2822(date)
    Time.rfc2822(date) unless date.nil?
  end

  def self.deserialize_iso8601_date(date)
    Date.parse(date) unless date.nil?
  end

  def self.deserialize_iso8601_datetime(date)
    Time.parse(date) unless date.nil?
  end

  def self.serialize_object(object)
    if object.is_a?(Hash) || object.is_a?(Array)
      JSON.generate(object)
    else
      object
    end
  end

  def self.flatten(map, result = {}, previous = [])
    map.each do |key, value|
      if value.is_a? Hash
        self.flatten(value, result, previous + [key])
      else
        result[(previous + [key]).join('.')] = value
      end
    end

    result
  end

  def self.prefixed_collapsible_map(map, prefix)
    result = {}
    if map.is_a? Hash
      flattened = self.flatten(map)
      result = {}
      flattened.each do |key, value|
        result[prefix + '.' + key] = value
      end
    end

    result
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
twilio-ruby-5.4.3 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.4.2 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.4.1 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.4.0 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.3.1 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.3.0 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.2.3 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.2.2 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.2.1 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.2.0 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.1.2 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.1.1 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.1.0 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.0.0.alpha1 lib/twilio-ruby/framework/serialize.rb
twilio-ruby-5.0.0 lib/twilio-ruby/framework/serialize.rb