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,33 +70,41 @@ 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))
|
||||||
|
elsif file_type == :location
|
||||||
|
params.merge!(location_params(attachment))
|
||||||
|
elsif file_type == :fallback
|
||||||
|
params.merge!(fallback_params(attachment))
|
||||||
|
end
|
||||||
|
|
||||||
|
params
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_type_params(attachment)
|
||||||
{
|
{
|
||||||
external_url: attachment['payload']['url'],
|
external_url: attachment['payload']['url'],
|
||||||
remote_file_url: attachment['payload']['url']
|
remote_file_url: attachment['payload']['url']
|
||||||
})
|
}
|
||||||
elsif file_type == :location
|
end
|
||||||
|
|
||||||
|
def location_params(attachment)
|
||||||
lat, long = attachment['payload']['coordinates']['lat'], attachment['payload']['coordinates']['long']
|
lat, long = attachment['payload']['coordinates']['lat'], attachment['payload']['coordinates']['long']
|
||||||
params.merge!(
|
|
||||||
{
|
{
|
||||||
external_url: attachment['url'],
|
external_url: attachment['url'],
|
||||||
coordinates_lat: lat,
|
coordinates_lat: lat,
|
||||||
coordinates_long: long,
|
coordinates_long: long,
|
||||||
fallback_title: attachment['title']
|
fallback_title: attachment['title']
|
||||||
})
|
}
|
||||||
elsif file_type == :fallback
|
end
|
||||||
params.merge!(
|
|
||||||
|
def fallback_params(attachment)
|
||||||
{
|
{
|
||||||
fallback_title: attachment['title'],
|
fallback_title: attachment['title'],
|
||||||
external_url: attachment['url']
|
external_url: attachment['url']
|
||||||
})
|
}
|
||||||
end
|
|
||||||
params
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def conversation_params
|
def conversation_params
|
||||||
|
|
Loading…
Reference in a new issue