jobs/sample_job.rb in remi-0.2.27 vs jobs/sample_job.rb in remi-0.2.28
- old
+ new
@@ -1,22 +1,21 @@
# This is an example Remi job that was auto-generated by Remi.
-
require_relative 'all_jobs_shared'
+require 'remi/data_subject/salesforce'
class SampleJob
include AllJobsShared
- using Remi::Refinements::Daru
define_source :existing_contacts, Remi::DataSource::Salesforce,
object: :Contact,
credentials: params[:salesforce_credentials],
api: :bulk,
fields: {
:Id => {},
:External_ID__c => {},
:IsActive => { type: :boolean },
- :CreatedDate => { type: :date, format: '%Y-%m-%d %H:%M:%S' }
+ :CreatedDate => { type: :date, in_format: '%Y-%m-%d %H:%M:%S' }
},
query: <<-EOQ
SELECT
Id,
External_ID__c
@@ -48,12 +47,12 @@
:mailing_address_line_1 => {},
:mailing_address_line_2 => {},
:mailing_city => {},
:mailing_state => {},
:mailing_postal_code => {},
- :birthdate => { type: :date, format: '%m/%d/%Y'},
- :applied_date => { type: :date, format: '%m/%d/%Y'}
+ :birthdate => { type: :date, in_format: '%m/%d/%Y'},
+ :applied_date => { type: :date, in_format: '%m/%d/%Y'}
}
define_target :all_contacts, Remi::DataTarget::DataFrame
define_target :contact_updates, Remi::DataTarget::Salesforce,
@@ -81,23 +80,23 @@
# Exclude all source records with an invalid program name
all_contacts.df = sample_file.df.dup
Remi::SourceToTargetMap.apply(all_contacts.df) do
map source(:program) .target(:Major__c)
- .transform(Remi::Transform[:lookup][params[:program_name_lookup]])
+ .transform(Remi::Transform::Lookup.new(params[:program_name_lookup]))
end
all_contacts.df = all_contacts.df.where(all_contacts.df[:Major__c].not_eq(nil))
student_id_to_sf_id = existing_contacts.df.map_rows { |row| [row[:External_ID__c], row[:Id]] }.to_h
# Map fields that are common to both creates and updates
Remi::SourceToTargetMap.apply(all_contacts.df) do
# Prefixes source id record and then looks up existing salesforce Id
map source(:student_id) .target(:External_ID__c, :Id)
- .transform(Remi::Transform[:prefix]['SAMP'])
- .transform(->(v) { [v, Remi::Transform[:lookup][student_id_to_sf_id].call(v)] })
+ .transform(Remi::Transform::Prefix.new('SAMP'))
+ .transform(->(v) { [v, Remi::Transform::Lookup.new(student_id_to_sf_id).call(v)] })
end
end
define_transform :map_creates, sources: :all_contacts, targets: :contact_creates do
@@ -106,39 +105,39 @@
Remi::SourceToTargetMap.apply(work_contact_creates) do
map source(:school_id) .target(:School_ID__c)
map source(:school_name) .target(:School_Name__c)
map source(:first_name) .target(:FirstName)
- .transform(Remi::Transform[:ifblank].('Not Provided'))
+ .transform(Remi::Transform::IfBlank.new('Not Provided'))
map source(:last_name) .target(:LastName)
- .transform(Remi::Transform[:ifblank].('Not Provided'))
+ .transform(Remi::Transform::IfBlank.new('Not Provided'))
map source(:mailing_city) .target(:MailingCity)
map source(:mailing_state) .target(:MailingState)
map source(:mailing_postal_code) .target(:MailingPostalCode)
map source(:birthdate) .target(:Birthdate)
- .transform(Remi::Transform[:format_date][from_fmt: sample_file.fields[:birthdate][:format]])
+ .transform(Remi::Transform::FormatDate.new(in_format: sample_file.fields[:birthdate][:in_format]))
map source(:applied_date) .target(:Applied_Date__c)
- .transform(Remi::Transform[:ifblank].(Date.today.strftime(sample_file.fields[:applied_date][:format])))
- .transform(Remi::Transform[:format_date].(from_fmt: sample_file.fields[:applied_date][:format]))
+ .transform(Remi::Transform::IfBlank.new(Date.today.strftime(sample_file.fields[:applied_date][:in_format])))
+ .transform(Remi::Transform::FormatDate.new(in_format: sample_file.fields[:applied_date][:in_format]))
map source(:mailing_address_line_1, :mailing_address_line_2) .target(:MailingStreet)
.transform(->(line_1, line_2) {
- Remi::Transform[:ifblank].(nil).call(line_1).nil? ? [] : [line_1, line_2]
+ Remi::Transform::IfBlank.new(nil).call(line_1).nil? ? [] : [line_1, line_2]
})
- .transform(Remi::Transform[:concatenate].(', '))
+ .transform(Remi::Transform::Concatenate.new(', '))
map source(:school_id, :school_name) .target(:School__c)
.transform(->(id, name) {[
- Remi::Transform[:ifblank]["Unknown"].call(id),
- Remi::Transform[:ifblank]["Unknown"].call(name)
+ Remi::Transform::IfBlank.new("Unknown").call(id),
+ Remi::Transform::IfBlank.new("Unknown").call(name)
]})
- .transform(Remi::Transform[:concatenate].('-'))
+ .transform(Remi::Transform::Concatenate.new('-'))
map source(:current_email) .target(:Email)
- .transform(Remi::Transform[:replace].(/,/, '.'))
- .transform(Remi::Transform[:validate_email].call)
+ .transform(Remi::Transform::Replace.new(/,/, '.'))
+ .transform(Remi::Transform::ValidateEmail.new)
end
contact_creates.df = work_contact_creates[
:External_ID__c,
:School_ID__c,