module Smtpcom::Sendapi::Utils
Public Class Methods
format_response_row(row)
click to toggle source
# File lib/smtpcom/sendapi/utils.rb, line 21 def format_response_row(row) row.each do |k, v| row[k] = parse_time(v) if v.is_a?(String) && v =~ /\/Date\(\d{13}\)\// end underscore_hash(row) .reject { |k, _v| k.start_with? '_' } .inject({}) { |res, (k, v)| res[k.to_sym] = v; res } end
parse_time(str)
click to toggle source
# File lib/smtpcom/sendapi/utils.rb, line 17 def parse_time(str) Time.at(str.scan(/\d{13}/).first.to_i / 1000) end
underscore(str)
click to toggle source
# File lib/smtpcom/sendapi/utils.rb, line 5 def underscore(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .downcase end
underscore_hash(h)
click to toggle source
# File lib/smtpcom/sendapi/utils.rb, line 13 def underscore_hash(h) Hash[h.map { |k, v| [Utils.underscore(k), v] }] end