Sha256: 420e007412889dc927e7617c70f2c3126387056b5b6a638d3e2666564c63e891

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module SendgridThreads
  class Api
    attr_reader :connection

    def initialize( params = {} )
      @connection = SendgridThreads::Client.new(params)
    end

    def identify(user_id, traits = {}, timestamp = Time.now )
      body = {userId: user_id, traits: traits, timestamp: utc_iso8601(timestamp)}
      @connection.post("identify", body)
    end

    def track(user_id, event, properties = {}, timestamp = Time.now)
      body = {userId: user_id, event: event, timestamp: utc_iso8601(timestamp), properties: properties}
      @connection.post("track", body)
    end

    def page_view(user_id, name, properties = {}, timestamp = Time.now)
      body = {userId: user_id, name: name, timestamp: utc_iso8601(timestamp), properties: properties}
      @connection.post("page", body)
    end

    def remove(user_id, timestamp = Time.now)
      body = {userId: user_id, timestamp: utc_iso8601(timestamp)}
      @connection.post("remove", body)
    end

    private

    def utc_iso8601(timestamp)
      timestamp.utc.iso8601.gsub(/Z$/, '.000Z')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sendgrid-threads-0.1.0 lib/sendgrid_threads/api.rb