cloud-waba-ruby-client 0.0.8 → 0.0.10

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: a3d125f451cbb03e1d00d4c15d93cb802da482df91e857bf20cadfd801bd474b
4
+ data.tar.gz: 55897f67d56ac2816c3142298a7d9d6eb019b43e456003e5793499e4c64eb57c
5
5
  SHA512:
6
- metadata.gz: cf7475b7e91ff0098fa85e5c8cbd187946bbfbcf06f59f82bf4b0b355a78864542c464489510172d4521b34b88f0406d37fe69ae8ca9688efc218ea4e95bc4bd
7
- data.tar.gz: b714356912b941a45adb19f69ada1d4e1c5765a039523ff74cfd059de164e6aa431fa0d12f96a0470967ff33a58de1d4c303e3dac7174c8ae2b7aa53bd5773d1
6
+ metadata.gz: 3d491775dd33e6dea8b68180fadef122d7a737dd9ed608b684e40c0a6c27b7b3118a1f9dbebac52ce60b0ad4a30028ae86ca6cd0cb9ef4dcd6a63f81878de4f3
7
+ data.tar.gz: a37edb100cfe734f21d4e6a98be23f5014e9b1d59f8c1ed3ef6621e73194043087b8dbcf752b9a5351ea7eb3fb0050abb9de3eafa9a295ff1af520e3d49dbb98
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.10'
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.10"
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"]
@@ -1,8 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pry'
5
-
6
4
  module API
7
5
  module Messages
8
6
  class Service
@@ -254,12 +252,12 @@ module API
254
252
  end
255
253
 
256
254
  sig do
257
- params(media_url: ::String).returns(::StringIO)
255
+ params(media_url: ::String).returns(::File)
258
256
  end
259
257
  def download_media(media_url:)
260
258
  client = ::CloudWaba::HttpClient.new(base_url: media_url, auth_token: @config.access_token)
261
259
  response = client.get
262
- StringIO.new(response.body)
260
+ build_file(response: response)
263
261
  end
264
262
 
265
263
  private
@@ -290,6 +288,53 @@ module API
290
288
 
291
289
  response
292
290
  end
291
+
292
+ sig { params(response: ::HTTP::Response).returns(::File) }
293
+ def build_file(response:)
294
+ file_content = response.body
295
+ content_disposition = response['Content-Disposition']
296
+
297
+ if content_disposition && content_disposition =~ /filename=(["'])?([^'"\s]+)/
298
+ filename = $2
299
+ else
300
+ # If Content-Disposition is not present or doesn't contain filename information,
301
+ # infer the extension from Content-Type
302
+ content_type = response['Content-Type']
303
+ filename += case content_type
304
+ when 'text/plain'
305
+ 'txt'
306
+ when 'application/pdf'
307
+ 'pdf'
308
+ when 'image/jpeg'
309
+ 'jpg'
310
+ when 'image/png'
311
+ 'png'
312
+ when 'image/webp'
313
+ 'webp'
314
+ when 'audio/aac'
315
+ 'aac'
316
+ when 'audio/mp4'
317
+ 'mp4'
318
+ when 'audio/mpeg'
319
+ 'mp3'
320
+ when 'audio/amr'
321
+ 'amr'
322
+ when 'audio/ogg'
323
+ 'ogg'
324
+ when 'video/mp4'
325
+ 'mp4'
326
+ when 'video/3gp'
327
+ '3pg'
328
+ end
329
+ end
330
+
331
+ file_path = "/tmp/#{filename || 'file.' + file_extension}"
332
+ File.open(file_path, 'wb') do |f|
333
+ f.write(file_content.to_s)
334
+ end
335
+
336
+ File.new(file_path)
337
+ end
293
338
  end
294
339
  end
295
340
  end
@@ -1,8 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- # require 'pry'
5
-
6
4
  module API
7
5
  module Templates
8
6
  class Service
@@ -1,8 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- # require 'pry'
5
-
6
4
  module CloudWaba
7
5
  module Models
8
6
  module Media
@@ -1,8 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- # require 'pry'
5
-
6
4
  module CloudWaba
7
5
  module Models
8
6
  module Messages
@@ -1,8 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- # require 'pry'
5
-
6
4
  module CloudWaba
7
5
  module Models
8
6
  module Templates
metadata CHANGED
@@ -1,14 +1,14 @@
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.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Bassell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv