Class: Mpql::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/mpql/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Exit with non-zero status on errors

Returns:

  • (Boolean)


12
13
14
# File 'lib/mpql/cli.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

#cohortsObject



145
146
147
148
149
150
# File 'lib/mpql/cli.rb', line 145

def cohorts
  result = client.cohorts(**optional_params)
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#engageObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/mpql/cli.rb', line 170

def engage
  params = optional_params(:where, :page, :session_id)
  distinct_ids = options[:distinct_id]
  if distinct_ids && distinct_ids.length == 1
    params[:distinct_id] = distinct_ids.first
  elsif distinct_ids && distinct_ids.length > 1
    conditions = distinct_ids.map { |id| %(properties["$distinct_id"] == "#{id}") }
    where_clause = conditions.join(" or ")
    params[:where] = params[:where] ? "(#{params[:where]}) and (#{where_clause})" : where_clause
  end
  result = client.engage(**params)
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#exportObject



199
200
201
202
203
204
205
206
207
208
# File 'lib/mpql/cli.rb', line 199

def export
  result = client.export(
    event: options[:event],
    from_date: parse_date(options[:from]),
    to_date: parse_date(options[:to])
  )
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#funnelsObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mpql/cli.rb', line 75

def funnels
  result = client.funnels(
    funnel_id: options[:funnel_id],
    from_date: parse_date(options[:from]),
    to_date: parse_date(options[:to]),
    **optional_params(:on, :where, :limit)
  )
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#insightsObject



125
126
127
128
129
130
131
132
133
# File 'lib/mpql/cli.rb', line 125

def insights
  result = client.insights(
    bookmark_id: options[:bookmark_id],
    **optional_params
  )
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#retentionObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/mpql/cli.rb', line 105

def retention
  result = client.retention(
    from_date: parse_date(options[:from]),
    to_date: parse_date(options[:to]),
    **optional_params(:born_event, :event, :retention_type, :on, :unit, :interval)
  )
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#segmentationObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mpql/cli.rb', line 47

def segmentation
  result = client.segmentation(
    event: options[:event],
    from_date: parse_date(options[:from]),
    to_date: parse_date(options[:to]),
    **optional_params(:on, :unit, :where, :type, :limit)
  )
  output(result)
rescue Mpql::Error => e
  error_exit(e)
end

#versionObject



211
212
213
# File 'lib/mpql/cli.rb', line 211

def version
  puts Mpql::VERSION
end