Refactor for attachment_params method (#108)

This commit is contained in:
Ender Ahmet Yurt 2019-10-05 12:15:32 +03:00 committed by Pranav Raj S
parent ca63bba63f
commit bbbc14448b

View file

@ -70,35 +70,43 @@ Assumptions
def attachment_params(attachment)
file_type = attachment['type'].to_sym
params = {
file_type: file_type,
account_id: @message.account_id
}
params = { file_type: file_type, account_id: @message.account_id }
if [:image, :file, :audio, :video].include? file_type
params.merge!(
{
external_url: attachment['payload']['url'],
remote_file_url: attachment['payload']['url']
})
params.merge!(file_type_params(attachment))
elsif file_type == :location
lat, long = attachment['payload']['coordinates']['lat'], attachment['payload']['coordinates']['long']
params.merge!(
{
external_url: attachment['url'],
coordinates_lat: lat,
coordinates_long: long,
fallback_title: attachment['title']
})
params.merge!(location_params(attachment))
elsif file_type == :fallback
params.merge!(
{
fallback_title: attachment['title'],
external_url: attachment['url']
})
params.merge!(fallback_params(attachment))
end
params
end
def file_type_params(attachment)
{
external_url: attachment['payload']['url'],
remote_file_url: attachment['payload']['url']
}
end
def location_params(attachment)
lat, long = attachment['payload']['coordinates']['lat'], attachment['payload']['coordinates']['long']
{
external_url: attachment['url'],
coordinates_lat: lat,
coordinates_long: long,
fallback_title: attachment['title']
}
end
def fallback_params(attachment)
{
fallback_title: attachment['title'],
external_url: attachment['url']
}
end
def conversation_params
{
account_id: @inbox.account_id,