Sha256: ca95771c12180cb4531dd72fd218ba7346575233cac052d775b951309b1dd8f8
Contents?: true
Size: 1.36 KB
Versions: 3
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true module SimpleSegment module Operations class Operation include SimpleSegment::Utils DEFAULT_CONTEXT = { library: { name: 'simple_segment', version: SimpleSegment::VERSION } }.freeze def initialize(client, options = {}) @options = options @context = DEFAULT_CONTEXT.merge(options[:context].to_h) @request = Request.new(client) end def call raise 'Must be implemented in a subclass' end private attr_reader :options, :request, :context def base_payload check_identity! current_time = Time.now { userId: options[:user_id], anonymousId: options[:anonymous_id], context: context, integrations: options[:integrations], timestamp: timestamp(options.fetch(:timestamp, current_time)), sentAt: current_time.iso8601, messageId: options[:message_id] } end def check_identity! raise ArgumentError, 'user_id or anonymous_id must be present' \ unless options[:user_id] || options[:anonymous_id] end def timestamp(timestamp) if timestamp.respond_to?(:iso8601) timestamp.iso8601 else Time.iso8601(timestamp).iso8601 end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems