Refactor for attachment_params method (#108)
This commit is contained in:
parent
ca63bba63f
commit
bbbc14448b
1 changed files with 30 additions and 22 deletions
|
@ -70,35 +70,43 @@ Assumptions
|
||||||
|
|
||||||
def attachment_params(attachment)
|
def attachment_params(attachment)
|
||||||
file_type = attachment['type'].to_sym
|
file_type = attachment['type'].to_sym
|
||||||
params = {
|
params = { file_type: file_type, account_id: @message.account_id }
|
||||||
file_type: file_type,
|
|
||||||
account_id: @message.account_id
|
|
||||||
}
|
|
||||||
if [:image, :file, :audio, :video].include? file_type
|
if [:image, :file, :audio, :video].include? file_type
|
||||||
params.merge!(
|
params.merge!(file_type_params(attachment))
|
||||||
{
|
|
||||||
external_url: attachment['payload']['url'],
|
|
||||||
remote_file_url: attachment['payload']['url']
|
|
||||||
})
|
|
||||||
elsif file_type == :location
|
elsif file_type == :location
|
||||||
lat, long = attachment['payload']['coordinates']['lat'], attachment['payload']['coordinates']['long']
|
params.merge!(location_params(attachment))
|
||||||
params.merge!(
|
|
||||||
{
|
|
||||||
external_url: attachment['url'],
|
|
||||||
coordinates_lat: lat,
|
|
||||||
coordinates_long: long,
|
|
||||||
fallback_title: attachment['title']
|
|
||||||
})
|
|
||||||
elsif file_type == :fallback
|
elsif file_type == :fallback
|
||||||
params.merge!(
|
params.merge!(fallback_params(attachment))
|
||||||
{
|
|
||||||
fallback_title: attachment['title'],
|
|
||||||
external_url: attachment['url']
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
params
|
params
|
||||||
end
|
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
|
def conversation_params
|
||||||
{
|
{
|
||||||
account_id: @inbox.account_id,
|
account_id: @inbox.account_id,
|
||||||
|
|
Loading…
Reference in a new issue