lib/simple_segment/operations/operation.rb in simple_segment-0.1.0 vs lib/simple_segment/operations/operation.rb in simple_segment-0.1.1
- old
+ new
@@ -28,17 +28,25 @@
{
userId: options[:user_id],
anonymousId: options[:anonymous_id],
context: DEFAULT_CONTEXT.merge(options[:context].to_h),
integrations: options[:integrations],
- timestamp: options.fetch(:timestamp, current_time).iso8601,
+ timestamp: timestamp(options.fetch(:timestamp, current_time)),
sentAt: current_time.iso8601
}
end
def check_identity!
unless options[:user_id] || options[:anonymous_id]
raise ArgumentError, 'user_id or anonymous_id must be present'
+ end
+ end
+
+ def timestamp(timestamp)
+ if timestamp.respond_to?(:iso8601)
+ timestamp.iso8601
+ else
+ Time.iso8601(timestamp).iso8601
end
end
end
end
end