Module: LiveQA

Defined in:
lib/liveqa.rb,
lib/liveqa/util.rb,
lib/liveqa/batch.rb,
lib/liveqa/event.rb,
lib/liveqa/group.rb,
lib/liveqa/store.rb,
lib/liveqa/config.rb,
lib/liveqa/errors.rb,
lib/liveqa/message.rb,
lib/liveqa/request.rb,
lib/liveqa/version.rb,
lib/liveqa/watcher.rb,
lib/liveqa/identity.rb,
lib/liveqa/api_resource.rb,
lib/liveqa/library_name.rb,
lib/liveqa/liveqa_object.rb,
lib/liveqa/formated_logger.rb,
lib/liveqa/processor/async.rb,
lib/liveqa/processor/batch.rb,
lib/liveqa/processor/worker.rb,
lib/liveqa/api_operation/save.rb,
lib/liveqa/plugins/rails/data.rb,
lib/liveqa/api_operation/delete.rb,
lib/liveqa/plugins/rails/railtie.rb,
lib/liveqa/plugins/rack/middleware.rb,
lib/liveqa/plugins/rails/middleware_data.rb,
lib/liveqa/plugins/sidekiq/client_middleware.rb,
lib/liveqa/plugins/sidekiq/server_middleware.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Plugins, Processor, Util Classes: APIOperation, APIResource, Batch, Config, ConfigurationError, Event, FormatedLogger, Group, Identity, LiveQAObject, Message, MissingImplementation, Request, RequestError, Store, UnknownRequestMethod, Watcher

Constant Summary collapse

EVENTS_CREATE_ACTION =
'events:create'.freeze
GROUPS_UPDATE_ACTION =
'groups:update'.freeze
IDENTITIES_UPDATE_ACTION =
'identities:update'.freeze
WATCHERS_CREATE_ACTION =
'watchers:create'.freeze
VERSION =
'1.9.4'.freeze
LIBRARY_NAME =
'liveqa'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationsLiveQA::Config (readonly)

Returns configurations.

Returns:



55
56
57
# File 'lib/liveqa.rb', line 55

def configurations
  @configurations
end

Class Method Details

.configure {|@configurations = LiveQA::Config.new| ... } ⇒ Object

Configures the LiveQA API

Examples:

Default configuration

LiveQA.configure do |config|
   config. = 'acc_xx'
   config.space_name = 'LiveQA'
   config.environment_name = 'production'
end

Yields:



66
67
68
69
70
# File 'lib/liveqa.rb', line 66

def configure
  yield @configurations = LiveQA::Config.new

  LiveQA.configurations.valid!
end

.identify(user_id, payload = {}, options = {}) ⇒ Boolean

Send an identify event to the server

Parameters:

  • user (String)

    id from your database

  • payload (Hash) (defaults to: {})

    to be send

  • options (Hash) (defaults to: {})

    for the request

Returns:

  • (Boolean)

    status of the request



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/liveqa.rb', line 109

def identify(user_id, payload = {}, options = {})
  return true unless configurations.enabled

  payload[:type]    = 'identify'
  payload[:user_id] = user_id
  LiveQA::Plugins::Rails::Data.store_data if defined?(LiveQA::Plugins::Rails::Data)

  payload = Message.extended.merge(payload)

  if configurations.async
    return processor.enqueue(
      action: EVENTS_CREATE_ACTION,
      payload: payload,
      options: options.select { |k, _v| %i[space_name environment_name].include?(k) },
    )
  end

  event = Event.create(payload, options)
  event.successful?
end

.set_group(group_id, payload = {}, options = {}) ⇒ Boolean

Send a create/update for a group

Parameters:

  • group (String)

    id from your database

  • payload (Hash) (defaults to: {})

    to be send

  • options (Hash) (defaults to: {})

    for the request

Returns:

  • (Boolean)

    status of the request



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/liveqa.rb', line 138

def set_group(group_id, payload = {}, options = {})
  return true unless configurations.enabled

  payload = Message.base.merge(payload)

  if configurations.async
    return processor.enqueue(
      action: GROUPS_UPDATE_ACTION,
      id: group_id,
      payload: payload,
      options: options.select { |k, _v| %i[space_name environment_name].include?(k) },
    )
  end

  group = Group.update(group_id, payload, options)
  group.successful?
end

.set_identity(user_id, payload = {}, options = {}) ⇒ Boolean

Send a create/update for an identity

Parameters:

  • user (String)

    id from your database

  • payload (Hash) (defaults to: {})

    to be send

  • options (Hash) (defaults to: {})

    for the request

Returns:

  • (Boolean)

    status of the request



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/liveqa.rb', line 164

def set_identity(user_id, payload = {}, options = {})
  return true unless configurations.enabled

  payload = Message.base.merge(payload)

  if configurations.async
    return processor.enqueue(
      action: IDENTITIES_UPDATE_ACTION,
      id: user_id,
      payload: payload,
      options: options.select { |k, _v| %i[space_name environment_name].include?(k) },
    )
  end

  identity = Identity.update(user_id, payload, options)
  identity.successful?
end

.track(name, payload = {}, options = {}) ⇒ Boolean

Send a track event to the server

Parameters:

  • event (String)

    name

  • payload (Hash) (defaults to: {})

    to be send

  • options (Hash) (defaults to: {})

    for the request

Returns:

  • (Boolean)

    status of the request



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/liveqa.rb', line 80

def track(name, payload = {}, options = {})
  return true unless configurations.enabled

  payload[:type] = 'track'
  payload[:name] = name
  LiveQA::Plugins::Rails::Data.store_data if defined?(LiveQA::Plugins::Rails::Data)

  payload = Message.extended.merge(payload)

  if configurations.async
    return processor.enqueue(
      action: EVENTS_CREATE_ACTION,
      payload: payload,
      options: options.select { |k, _v| %i[space_name environment_name].include?(k) },
    )
  end

  event = Event.create(payload, options)
  event.successful?
end

.watch(id_or_name, payload = {}, options = {}) ⇒ Boolean

Send a create a watcher

Parameters:

  • template (String|Integer)

    flow name or id

  • payload (Hash) (defaults to: {})

    to be send

  • options (Hash) (defaults to: {})

    for the request

Returns:

  • (Boolean)

    status of the request



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/liveqa.rb', line 190

def watch(id_or_name, payload = {}, options = {})
  return true unless configurations.enabled

  payload[:template_flow] = id_or_name
  payload = Message.base.merge(payload)

  payload.delete(:session_tracker_id) if payload.delete(:without_session)

  if configurations.async
    return processor.enqueue(
      action: WATCHERS_CREATE_ACTION,
      payload: payload,
      options: options.select { |k, _v| %i[space_name environment_name].include?(k) },
    )
  end

  watcher = Watcher.create(payload, options)
  watcher.successful?
end