Skip to content

Instantly share code, notes, and snippets.

@justinko
Created November 14, 2012 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinko/4074998 to your computer and use it in GitHub Desktop.
Save justinko/4074998 to your computer and use it in GitHub Desktop.
class SyncToAnalyticsService
ConnectionFailure = Class.new(StandardError)
def self.perform(data)
new(data).perform
end
def initialize(data)
@data = data.symbolize_keys
@account = Account.find(@data[:account_id])
@analytics_client = Analytics::Client.new(CC.config[:analytics_api_key])
end
def perform
@account.users.each do |user|
@analytics_client.create_or_update(
id: user.id,
email: user.email,
account_id: @account.id,
account_admin: @account.administered_by?(user),
account_name: @account.name,
account_user_count: @account.users.count
)
end
rescue SocketError => ex
raise ConnectionFailure.new(ex.message)
end
end
class SyncToAnalyticsService
ConnectionFailure = Class.new(StandardError)
def self.perform(data)
data = data.symbolize_keys
account = Account.find(data[:account_id])
analytics_client = Analytics::Client.new(CC.config[:analytics_api_key])
account.users.each do |user|
analytics_client.create_or_update(
id: user.id,
email: user.email,
account_id: account.id,
account_admin: account.administered_by?(user),
account_name: account.name,
account_user_count: account.users.count
)
end
rescue SocketError => ex
raise ConnectionFailure.new(ex.message)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment