Last active
January 26, 2018 17:12
-
-
Save siraz-provectus/c84abe317bef5a6a7e9fe70d4d166577 to your computer and use it in GitHub Desktop.
users-export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
excel_builder = Exports::UserExcelExport.new(sm_response.profiles) | |
file_name = "users.xls" | |
headers['Content-Type'] = "text/xls" | |
headers['Content-disposition'] = "attachment; filename=\"#{file_name}\"" | |
headers['X-Accel-Buffering'] = 'no' | |
headers['Cache-Control'] ||= 'no-cache' | |
headers.delete('Content-Length') | |
response.status = 200 | |
self.response_body = excel_builder.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Exports | |
class UserExcelExport < ApplicationExcelExport | |
BATCH_SIZE = 500 | |
private | |
def default_headers | |
{ | |
name: "Имя", | |
email: 'email', | |
demi_link: 'cсылка с автологином (на Demi пост)', | |
dron_link: 'cсылка с автологином (на пост про дроны)', | |
unsubscribe: 'отписка' | |
} | |
end | |
def map_data(data) | |
auto_demi_link = '' | |
auto_dron_link = '' | |
unsubscribe_link = '' | |
base_url = Rails.application.config.action_mailer.asset_host + '/l/' | |
user = User.find_by(smartcore_id: data.id) | |
if user.present? | |
AutoLoginLink.generate_link(user: user, path_to: '/articles/demi', activity_code: 'demi') if user.auto_login_links.find_by(activity_code: "demi", used: false).blank? | |
AutoLoginLink.generate_link(user: user, path_to: '/articles/drons', activity_code: 'dron') if user.auto_login_links.find_by(activity_code: "dron", used: false).blank? | |
auto_demi_link = user.auto_login_links.find_by(activity_code: "demi", used: false).slug | |
auto_dron_link = user.auto_login_links.find_by(activity_code: "dron", used: false).slug | |
# token = Digest::MD5.hexdigest(['5153dac4c1d6b45', data.email, '70f202b12972d09b9'].join('')) | |
# params = { email: data.email, token: token } | |
# unsubscribe_link = "#{base_url}/unsubscribe?#{params.to_query}" | |
end | |
demi_link = base_url + auto_demi_link | |
dron_link = base_url + auto_dron_link | |
{ | |
name: "#{data.first_name} #{data.last_name}", | |
email: data.email, | |
demi_link: demi_link, | |
dron_link: dron_link, | |
unsubscribe: unsubscribe_link | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment