cloud-waba-ruby-client 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/cloud-waba-ruby-client.gemspec +1 -1
- data/lib/api/messages/service.rb +49 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b230e684b97870c823f72c80fb62537fd8747b3b09cdcc2656ac958994fa5bb8
|
4
|
+
data.tar.gz: 288112086f8f272d98be848bee4a31cc6ed57894323400e9f04148eef1054f1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd38b89b710a3f6e8967930359f5ccb9a9f94c2c631ba08b418fcd81bf4f01a0d87cc64ea2cdd67897fcf6434abf824b5daf45000562dee50a37623dbd54283
|
7
|
+
data.tar.gz: e0ad2f7de7a924715a9b457d36029e0f3ded0966998b41bb4ee8e1bcbf4ca602567adf63f3bd2949bb7bceaed190cff822e089f72a4351cf09e0726f6cf3f672
|
data/README.md
CHANGED
data/lib/api/messages/service.rb
CHANGED
@@ -254,12 +254,12 @@ module API
|
|
254
254
|
end
|
255
255
|
|
256
256
|
sig do
|
257
|
-
params(media_url: ::String).returns(::
|
257
|
+
params(media_url: ::String).returns(::File)
|
258
258
|
end
|
259
259
|
def download_media(media_url:)
|
260
260
|
client = ::CloudWaba::HttpClient.new(base_url: media_url, auth_token: @config.access_token)
|
261
261
|
response = client.get
|
262
|
-
|
262
|
+
build_file(response: response)
|
263
263
|
end
|
264
264
|
|
265
265
|
private
|
@@ -290,6 +290,53 @@ module API
|
|
290
290
|
|
291
291
|
response
|
292
292
|
end
|
293
|
+
|
294
|
+
sig { params(response: ::HTTP::Response).returns(::File) }
|
295
|
+
def build_file(response:)
|
296
|
+
file_content = response.body
|
297
|
+
content_disposition = response['Content-Disposition']
|
298
|
+
|
299
|
+
if content_disposition && content_disposition =~ /filename=(["'])?([^'"\s]+)/
|
300
|
+
filename = $2
|
301
|
+
else
|
302
|
+
# If Content-Disposition is not present or doesn't contain filename information,
|
303
|
+
# infer the extension from Content-Type
|
304
|
+
content_type = response['Content-Type']
|
305
|
+
filename += case content_type
|
306
|
+
when 'text/plain'
|
307
|
+
'txt'
|
308
|
+
when 'application/pdf'
|
309
|
+
'pdf'
|
310
|
+
when 'image/jpeg'
|
311
|
+
'jpg'
|
312
|
+
when 'image/png'
|
313
|
+
'png'
|
314
|
+
when 'image/webp'
|
315
|
+
'webp'
|
316
|
+
when 'audio/aac'
|
317
|
+
'aac'
|
318
|
+
when 'audio/mp4'
|
319
|
+
'mp4'
|
320
|
+
when 'audio/mpeg'
|
321
|
+
'mp3'
|
322
|
+
when 'audio/amr'
|
323
|
+
'amr'
|
324
|
+
when 'audio/ogg'
|
325
|
+
'ogg'
|
326
|
+
when 'video/mp4'
|
327
|
+
'mp4'
|
328
|
+
when 'video/3gp'
|
329
|
+
'3pg'
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
file_path = "/tmp/#{filename || 'file.' + file_extension}"
|
334
|
+
File.open(file_path, 'wb') do |f|
|
335
|
+
f.write(file_content.to_s)
|
336
|
+
end
|
337
|
+
|
338
|
+
File.new(file_path)
|
339
|
+
end
|
293
340
|
end
|
294
341
|
end
|
295
342
|
end
|