Module: Mixpanel::Client::Utils

Defined in:
lib/mixpanel/utils.rb

Overview

Mixpanel API Ruby Client Library

Utility helpers

Copyright © 2009+ Keolo Keagy See LICENSE for details

Class Method Summary collapse

Class Method Details

.generate_signature(args, api_secret) ⇒ String

Return a string composed of hashed values specified by the mixpanel data API

Returns:

  • (String)

    md5 hash signature required by mixpanel data API



23
24
25
26
27
28
29
30
# File 'lib/mixpanel/utils.rb', line 23

def self.generate_signature(args, api_secret)
  Digest::MD5.hexdigest(
    args.map { |key, val| "#{key}=#{val}" }
    .sort
    .join +
    api_secret
  )
end

.to_hash(data, format) ⇒ JSON, String

Return a JSON object or a string depending on a given format

Parameters:

  • data (String)

    either CSV or JSON formatted

Returns:

  • (JSON, String)

    data



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mixpanel/utils.rb', line 36

def self.to_hash(data, format)
  if format == 'csv' || format == 'raw'
    data
  else
    begin
      JSON.parse(data)
    rescue JSON::ParserError => error
      raise ParseError, error
    end
  end
end