Sha256: 5d4699feb907195a6c765dfa04a6ff3b90e3ccbd4b967dbf0a990aad9deb36f1

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require 'zenbox'
require File.join(File.dirname(__FILE__), 'shared_tasks')

namespace :zenbox do
  desc "Verify your zenbox api_key by sending test data to the zenbox 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
      Zenbox.configure(true) do |config|
        config.logger = Rails.logger
      end
    end

    unless Zenbox.configuration.api_key
      puts "Zenbox 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 Zenbox.post "test@example.com", {:test_data => 123}
      puts "\nZenbox is set up and ready to use!"
    else
      puts "\nPlease check your Zenbox 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 Zenbox.model.nil?
      puts "You must set a model to zenbox. Did you remember to user `zenbox_user :fields...` in your User model? "
      return
    end

    model = Zenbox.model.constantize

    puts "Syncing #{model.all.count} models with Zenbox..." 

    reset = "\r\e[0k"

    count = model.all.count

    model.all.each_with_index do |model, index|
      progress = ((index.to_f + 1) / count * 100).round(2)
      output = "#{progress}%: #{model.email}"
      print "#{reset}"
      print output
      model.zenbox_sync!
    end

    puts " - Finished!"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zenbox-0.0.7 lib/zenbox/tasks.rb
zenbox-0.0.6 lib/zenbox/tasks.rb