Class: Mixpanel::ServiceAccountCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/mixpanel-ruby/credentials.rb

Overview

Service account credentials for server-to-server authentication This is the recommended authentication method over API keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, secret, project_id) ⇒ ServiceAccountCredentials

Create service account credentials

Parameters:

  • username (String)

    Service account username

  • secret (String)

    Service account secret

  • project_id (String, Integer)

    Mixpanel project ID (accepts string or integer)

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mixpanel-ruby/credentials.rb', line 11

def initialize(username, secret, project_id)
  raise ArgumentError, 'username is required' if username.nil? || username.empty?
  raise ArgumentError, 'secret is required' if secret.nil? || secret.empty?
  raise ArgumentError, 'project_id is required' if project_id.nil?

  # Convert project_id to string if it's an integer (Mixpanel dashboard shows numeric IDs)
  project_id = project_id.to_s if project_id.is_a?(Integer)
  raise ArgumentError, 'project_id is required' if project_id.empty?

  @username = username
  @secret = secret
  @project_id = project_id
end

Instance Attribute Details

#project_idObject (readonly)

Returns the value of attribute project_id.



5
6
7
# File 'lib/mixpanel-ruby/credentials.rb', line 5

def project_id
  @project_id
end

#secretObject (readonly)

Returns the value of attribute secret.



5
6
7
# File 'lib/mixpanel-ruby/credentials.rb', line 5

def secret
  @secret
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/mixpanel-ruby/credentials.rb', line 5

def username
  @username
end