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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3bc4d08be977a4a8d16701fc5cb5b037aea2004628888b18d39733c30cb258a
4
- data.tar.gz: 6f84106e2196f1e369c51016b6d87ce3c4594c7ba68d35f50d8ae6dcf7bbdab5
3
+ metadata.gz: b230e684b97870c823f72c80fb62537fd8747b3b09cdcc2656ac958994fa5bb8
4
+ data.tar.gz: 288112086f8f272d98be848bee4a31cc6ed57894323400e9f04148eef1054f1a
5
5
  SHA512:
6
- metadata.gz: cf7475b7e91ff0098fa85e5c8cbd187946bbfbcf06f59f82bf4b0b355a78864542c464489510172d4521b34b88f0406d37fe69ae8ca9688efc218ea4e95bc4bd
7
- data.tar.gz: b714356912b941a45adb19f69ada1d4e1c5765a039523ff74cfd059de164e6aa431fa0d12f96a0470967ff33a58de1d4c303e3dac7174c8ae2b7aa53bd5773d1
6
+ metadata.gz: 0fd38b89b710a3f6e8967930359f5ccb9a9f94c2c631ba08b418fcd81bf4f01a0d87cc64ea2cdd67897fcf6434abf824b5daf45000562dee50a37623dbd54283
7
+ data.tar.gz: e0ad2f7de7a924715a9b457d36029e0f3ded0966998b41bb4ee8e1bcbf4ca602567adf63f3bd2949bb7bceaed190cff822e089f72a4351cf09e0726f6cf3f672
data/README.md CHANGED
@@ -7,7 +7,7 @@ Ruby wrapper for [Cloud WhatsApp Business API](https://developers.facebook.com/d
7
7
  Add following line to your Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'cloud-waba-ruby-client', '~> 0.0.8'
10
+ gem 'cloud-waba-ruby-client', '~> 0.0.9'
11
11
  ```
12
12
 
13
13
  then run
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cloud-waba-ruby-client"
3
- s.version = "0.0.8"
3
+ s.version = "0.0.9"
4
4
  s.summary = "Cloud Waba Client for Ruby."
5
5
  s.description = "A simple API wrapper for Cloud Whatsapp Business API"
6
6
  s.authors = ["Ahmed Bassell"]
@@ -254,12 +254,12 @@ module API
254
254
  end
255
255
 
256
256
  sig do
257
- params(media_url: ::String).returns(::StringIO)
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
- StringIO.new(response.body)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-waba-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Bassell