require 'contextify' require File.join(File.dirname(__FILE__), 'shared_tasks') namespace :contextify do desc "Verify your contextify api_key by sending test data to the contextify service" task :test => :environment do if defined?(RAILS_DEFAULT_LOGGER) # Rails 2 RAILS_DEFAULT_LOGGER.level = Logger::DEBUG else # Rails 3 Rails.logger = Logger.new(STDOUT) Rails.logger.level = Logger::DEBUG Contextify.configure(true) do |config| config.logger = Rails.logger end end unless Contextify.configuration.api_key puts "Contextify needs an API key configured! Check the README to see how to add it." exit end puts "\nPosting dummy data for 'test@example.com'...\n\n" if Contextify.post "test@example.com", {:test_data => 123} puts "\nContextify is set up and ready to use!" else puts "\nPlease check your Contextify configuration or network settings." end puts end desc "Syncs all user data after the model has been marked. Can be run many times without any side-effects" task :sync => :environment do if Contextify.model.nil? puts "You must set a model to contextify. Did you remember to user `contextify_user :fields...` in your User model? " return end model = Contextify.model.constantize puts "Syncing #{model.all.count} models with Contextify..." model.all.each do |model| model.contextify_sync! end end end