Created
September 17, 2014 03:16
-
-
Save IlyaDonskikh/4b379f87d53359f4e0c9 to your computer and use it in GitHub Desktop.
Iskra_sync
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
def sync_1c | |
if !Rails.env.test? | |
client = Savon.client(wsdl: Iskra::Application::ADDRESS_1C, env_namespace: :soap, namespace_identifier: :m, convert_request_keys_to: :camelcase) | |
@user = case type | |
when 'DeleteSeminarParticipantRequest', 'DeleteSeminarParticipant', 'AddSeminarParticipant' then self.person_id | |
else | |
user_id.nil? ? '' : self.user_id | |
end | |
@resource_id = case type | |
when 'AddTicketDocumentOrder', 'AddTicketQuestion', 'AddTicketDemoOrder' then self.ticket_id | |
when 'AddSeminarParticipantRequest', 'DeleteSeminarParticipantRequest', 'AddSeminarParticipant', 'DeleteSeminarParticipant', 'ApprovedSeminarRequest', 'DisapprovedSeminarRequest', 'DeleteSeminar' then self.seminar_id | |
when 'DeleteExamination' then self.examination_id | |
when 'AddCompetition', 'DeleteCompetition' then self.competition_id | |
end | |
if ['AddSeminarParticipantRequest', 'DeleteSeminarParticipantRequest', 'AddSeminarParticipant', 'DeleteSeminarParticipant', 'ApprovedSeminarRequest', 'DisapprovedSeminarRequest', 'DeleteSeminar', 'DeleteExamination', 'AddCompetition', 'DeleteCompetition'].include?(type) | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: @user, | |
resource_id: @resource_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id | |
} | |
} | |
) | |
elsif type == 'AddSeminar' | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: '', | |
resource_id: self.seminar.id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'Title', | |
value: self.seminar.title | |
}, | |
'Property' => { | |
name: 'StartDate', | |
value: self.seminar.start_date.strftime('%Y-%m-%dT%H:%M:%S') | |
} | |
} | |
} | |
) | |
elsif type == "NewQuestionnaire" ## Start examination sync | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: self.questionnaire.user_id, | |
resource_id: self.questionnaire_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'ExaminationId', | |
value: self.examination.id | |
} | |
} | |
} | |
) | |
elsif type == "CompleteQuestionnaire" | |
user_questionnaires = self.examination.questionnaires.where(user_id: self.questionnaire.user_id) | |
number_attempts = user_questionnaires.size | |
point_list = [] | |
user_questionnaires.each do |qu| | |
point_list << qu.success_questions_ids.size | |
end | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: self.questionnaire.user_id, | |
resource_id: self.questionnaire_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'ExaminationId', | |
value: self.examination.id | |
}, | |
'Property' => { | |
name: 'NumberAttempts', | |
value: number_attempts.to_s + ' | ' + point_list.to_s | |
} | |
} | |
} | |
) | |
elsif type == "SelectExaminationGift" | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: self.questionnaire.user_id, | |
resource_id: self.questionnaire_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'ExaminationId', | |
value: self.examination.id | |
}, | |
'Property ' => { | |
name: 'GiftId', | |
value: questionnaire.gift_id.to_s | |
}, | |
'Property ' => { | |
name: 'GiftName', | |
value: questionnaire.gift.name | |
} | |
} | |
} | |
) | |
elsif type == "AddCompetitionItem" | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: self.user_id, | |
resource_id: self.competition_item_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'CompetitionId', | |
value: self.competition_id | |
} | |
} | |
} | |
) | |
elsif type == "DeleteCompetitionItem" | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: person_id, | |
resource_id: self.competition_item_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'CompetitionId', | |
value: self.competition_id | |
} | |
} | |
} | |
) | |
elsif ['AddTicketDocumentOrder', 'AddTicketQuestion', 'AddTicketDemoOrder'].include?(type) | |
client.call(:add_action, | |
message: { | |
action: { | |
user_id: @user, | |
resource_id: @resource_id, | |
kind: self.type, | |
date: self.created_at.strftime('%Y-%m-%dT%H:%M:%S'), | |
activity_id: id, | |
property: { | |
name: 'Subject', | |
value: self.ticket.subject | |
}, | |
'Property' => { | |
name: 'Content', | |
value: self.ticket.content | |
} | |
} | |
} | |
) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment