Skip to content
Extraits de code Groupes Projets
rake_helpers.rb 1,13 ko
Newer Older
  • Learn to ignore specific revisions
  • maxwell's avatar
    maxwell a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    module RakeHelpers
    
    maxwell's avatar
    maxwell a validé
      def process_emails(csv, num_to_process, offset, num_invites=10, test=true)
    
    Sarah Mei's avatar
    Sarah Mei a validé
        if RUBY_VERSION.include? "1.8"
           require 'fastercsv'
    
    Raphael's avatar
    Raphael a validé
           backers = FasterCSV.read(csv)
    
    Sarah Mei's avatar
    Sarah Mei a validé
         else
           require 'csv'
           backers = CSV.read(csv)
         end
    
    maxwell's avatar
    maxwell a validé
        puts "IN TEST MODE" if test
    
    maxwell's avatar
    maxwell a validé
        churn_through = 0
        num_to_process.times do |n|
          if backers[n+offset] == nil
            break
          end
          churn_through = n
          backer_name = backers[n+offset][0].to_s.strip
          backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
    
    Raphael's avatar
    Raphael a validé
          unless User.find_by_email(backer_email)
    
            puts "sending email to: #{backer_name} #{backer_email}" unless Rails.env == 'test'
    
            Invitation.create_invitee(:service => 'email', :identifier => backer_email, :name => backer_name, :invites => num_invites) unless test
    
            puts "user with the email exists: #{backer_email} ,  #{backer_name} " unless Rails.env == 'test'
    
    maxwell's avatar
    maxwell a validé
        end
        churn_through
      end
    end