whatsapp_sdk 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e174b898e076d20337b2566c9467a0fc6ab2e8aa5d3f4185dd8bcec6a754d25f
4
- data.tar.gz: 2fbb40187adeb8006b345c6b37de12c575cd9f6d1625f5e1befff2caaa3c0568
3
+ metadata.gz: 50d31bd48fd780c01049dfb4057424ce55cc6bc5092a5b250900482044bd8622
4
+ data.tar.gz: 0a76d504966100b86add6394bd69af61863575c05d3c67db74eab934a199fb5a
5
5
  SHA512:
6
- metadata.gz: cd4aa67163bb7ebcab95865b583d779d209453b383df131d46ac7baddf6002f37276c627a332f4ac3f792549a2f4d4d9bed27486e9500042b850c17e4ba03dcd
7
- data.tar.gz: 1ed23faa24804aebf48733a24c8d42ada544f5895ff5323fc0cac172c0bf4becf51abf3e75eadb85f3d5ead98beb3c1cd0d18fc329e10fdc1ce0b4139a07c3c2
6
+ metadata.gz: 66dc2b2cad95e2b230203613be97fef11ea32bcaaba1f9a157a9e7d1336060690462a1e4b4202b31d9b4494158ea55a29b88e2b26b45ec16e67817054b653bc5
7
+ data.tar.gz: e9a7602a3f6f74a1ee043b21b4beee11160db4286eb28b4addbe5867c9b088bc796e612f62f8b1cd48200677b018f7b6c51c6bd99d456d9f3d2277d5479b55f6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v 0.6.2
2
+ Add Business Profiles API [#53](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/53)
3
+
4
+ # v 0.6.1
5
+ Add raw_response to response [#47](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/46)
6
+
1
7
  # v 0.6.0
2
8
  Fix issue on Linux when files are not sorted [#45](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/45)
3
9
 
data/Gemfile CHANGED
@@ -17,6 +17,7 @@ group(:test) do
17
17
  gem('rubocop', require: false)
18
18
  gem('rubocop-minitest', require: false)
19
19
  gem('rubocop-performance', require: false)
20
+ gem('webmock')
20
21
  end
21
22
 
22
23
  group(:development) do
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whatsapp_sdk (0.6.0)
5
- faraday (~> 2.3.0)
4
+ whatsapp_sdk (0.6.2)
5
+ faraday (>= 2.3.0)
6
6
  faraday-multipart (~> 1.0.4)
7
7
  oj (~> 3.13.13)
8
8
  sorbet
@@ -12,15 +12,20 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
+ addressable (2.8.1)
16
+ public_suffix (>= 2.0.2, < 6.0)
15
17
  ast (2.4.2)
16
18
  coderay (1.1.3)
19
+ crack (0.4.5)
20
+ rexml
17
21
  diff-lcs (1.5.0)
18
- faraday (2.3.0)
19
- faraday-net_http (~> 2.0)
22
+ faraday (2.5.2)
23
+ faraday-net_http (>= 2.0, < 3.1)
20
24
  ruby2_keywords (>= 0.0.4)
21
25
  faraday-multipart (1.0.4)
22
26
  multipart-post (~> 2)
23
- faraday-net_http (2.0.3)
27
+ faraday-net_http (3.0.0)
28
+ hashdiff (1.0.1)
24
29
  method_source (1.0.0)
25
30
  minitest (5.16.1)
26
31
  mocha (1.14.0)
@@ -35,6 +40,7 @@ GEM
35
40
  method_source (~> 1.0)
36
41
  pry-nav (1.0.0)
37
42
  pry (>= 0.9.10, < 0.15)
43
+ public_suffix (5.0.0)
38
44
  rainbow (3.1.1)
39
45
  rake (13.0.6)
40
46
  rbi (0.0.15)
@@ -66,6 +72,7 @@ GEM
66
72
  sorbet-static (= 0.5.10346)
67
73
  sorbet-runtime (0.5.10346)
68
74
  sorbet-static (0.5.10346-universal-darwin-21)
75
+ sorbet-static (0.5.10346-x86_64-linux)
69
76
  sorbet-static-and-runtime (0.5.10346)
70
77
  sorbet (= 0.5.10346)
71
78
  sorbet-runtime (= 0.5.10346)
@@ -88,6 +95,10 @@ GEM
88
95
  unparser (0.6.5)
89
96
  diff-lcs (~> 1.3)
90
97
  parser (>= 3.1.0)
98
+ webmock (3.18.1)
99
+ addressable (>= 2.8.0)
100
+ crack (>= 0.3.2)
101
+ hashdiff (>= 0.4.0, < 2.0.0)
91
102
  webrick (1.7.0)
92
103
  yard (0.9.28)
93
104
  webrick (~> 1.7.0)
@@ -98,6 +109,7 @@ GEM
98
109
 
99
110
  PLATFORMS
100
111
  x86_64-darwin-21
112
+ x86_64-linux
101
113
 
102
114
  DEPENDENCIES
103
115
  bundler (~> 2.3)
@@ -116,8 +128,9 @@ DEPENDENCIES
116
128
  sorbet-runtime
117
129
  spoom
118
130
  tapioca
131
+ webmock
119
132
  whatsapp_sdk!
120
133
  zeitwerk (>= 2.6.0)
121
134
 
122
135
  BUNDLED WITH
123
- 2.3.9
136
+ 2.3.22
data/README.md CHANGED
@@ -7,8 +7,11 @@ The SDK provides a set of operations and classes to use the Whatsapp API.
7
7
  Send stickers, messages, audio, videos, and locations or just ask for the phone numbers through this library in a few steps!
8
8
 
9
9
 
10
+ ## Demo
11
+
10
12
  https://user-images.githubusercontent.com/11672878/173238826-6fc0a6f8-d0ee-4eae-8947-7dfd3b8b3446.mov
11
13
 
14
+ **Check the [Ruby on Rails Whatsapp example repository](https://github.com/ignacio-chiazzo/ruby_on_rails_whatsapp_example)** that uses this library to send messages.
12
15
 
13
16
  ## Installation
14
17
 
data/example.rb CHANGED
@@ -11,7 +11,7 @@ gemfile(true) do
11
11
 
12
12
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
13
13
 
14
- gem "whatsapp_sdk"
14
+ gem "whatsapp_sdk", path: "."
15
15
  gem "pry"
16
16
  gem "pry-nav"
17
17
  end
@@ -22,11 +22,11 @@ require "pry-nav"
22
22
 
23
23
  ################# UPDATE CONSTANTS #################
24
24
 
25
- ACCESS_TOKEN = "<TODO replace>"
26
- SENDER_ID = "<TODO replace>"
27
- RECIPIENT_NUMBER = "<TODO replace>"
28
- BUSINESS_ID = "<TODO replace>"
29
- IMAGE_LINK = "<TODO replace>"
25
+ ACCESS_TOKEN = "EAAZAvvr0DZBs0BAFe8yjwJujpg5JZBX5DvzQ5Mv1oUBxuOefZAmi1TuRTkYmd9AqNqyTt2TtGict94yDWMmxb4fVQ3gZANjIb0IXXptezSad0xTHIZBpCNqZB8SBeBGL0eajPEjP1tZBwY3oyuOMwRU1ZAQuKMFkIV7Sw01AA3nX32plODm7LObsLp04C3aL7Pb1UF6OYKS0vPcqtFl21E9sf" # replace this with a valid access_token # TODO replace
26
+ SENDER_ID = 111591145018464
27
+ RECIPIENT_NUMBER = 13_437_772_910
28
+ BUSINESS_ID = 102261539298487
29
+ IMAGE_LINK = "https://ignaciochiazzo.com/static/4c403819b9750c8ad8b20a75308f2a8a/876d5/profile-pic.avif"
30
30
 
31
31
  ################# Initialize Client #################
32
32
  WhatsappSdk.configure do |config|
@@ -46,6 +46,9 @@ end
46
46
  medias_api = WhatsappSdk::Api::Medias.new
47
47
  messages_api = WhatsappSdk::Api::Messages.new
48
48
  phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
49
+ business_profile = WhatsappSdk::Api::BusinessProfile.new
50
+
51
+ binding.pry
49
52
 
50
53
  ############################## Phone Numbers API ##############################
51
54
  registered_number = phone_numbers_api.registered_number(SENDER_ID)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ require_relative "request"
5
+ require_relative "response"
6
+
7
+ module WhatsappSdk
8
+ module Api
9
+ class BusinessProfile < Request
10
+ DEFAULT_FIELDS = 'about,address,description,email,profile_picture_url,websites,vertical'.freeze
11
+
12
+ # Get the details of business profile.
13
+ #
14
+ # @param phone_number_id [Integer] Phone Number Id.
15
+ # @return [WhatsappSdk::Api::Response] Response object.
16
+ sig { params(phone_number_id: Integer).returns(WhatsappSdk::Api::Response) }
17
+ def details(phone_number_id)
18
+ response = send_request(
19
+ http_method: "get",
20
+ endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=#{DEFAULT_FIELDS}"
21
+ )
22
+
23
+ WhatsappSdk::Api::Response.new(
24
+ response: response,
25
+ data_class_type: WhatsappSdk::Api::Responses::BusinessProfileDataResponse
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,7 @@
2
2
  # typed: strict
3
3
 
4
4
  require "faraday"
5
+ require "faraday/multipart"
5
6
  require "oj"
6
7
 
7
8
  module WhatsappSdk
@@ -19,13 +20,20 @@ module WhatsappSdk
19
20
 
20
21
  sig do
21
22
  params(
22
- endpoint: String, full_url: T.nilable(String), http_method: String, params: T::Hash[T.untyped, T.untyped]
23
- ).returns(T::Hash[T.untyped, T.untyped])
23
+ endpoint: String,
24
+ full_url: T.nilable(String),
25
+ http_method: String,
26
+ params: T::Hash[T.untyped, T.untyped],
27
+ headers: T::Hash[T.untyped, T.untyped]
28
+ ).returns(T.nilable(T::Hash[T.untyped, T.untyped]))
24
29
  end
25
- def send_request(endpoint: "", full_url: nil, http_method: "post", params: {})
30
+ def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, headers: {})
26
31
  url = full_url || API_CLIENT
27
32
 
28
- response = T.unsafe(faraday(url)).public_send(http_method, endpoint, params)
33
+ faraday_request = T.unsafe(faraday(url))
34
+
35
+ response = faraday_request.public_send(http_method, endpoint, request_params(params, headers), headers)
36
+
29
37
  Oj.load(response.body)
30
38
  end
31
39
 
@@ -47,6 +55,18 @@ module WhatsappSdk
47
55
 
48
56
  private
49
57
 
58
+ sig do
59
+ params(
60
+ params: T::Hash[T.untyped, T.untyped],
61
+ headers: T::Hash[T.untyped, T.untyped]
62
+ ).returns(T.any(T::Hash[T.untyped, T.untyped], String))
63
+ end
64
+ def request_params(params, headers)
65
+ return params.to_json if params.is_a?(Hash) && headers['Content-Type'] == 'application/json'
66
+
67
+ params
68
+ end
69
+
50
70
  sig { params(url: String).returns(Faraday::Connection) }
51
71
  def faraday(url)
52
72
  ::Faraday.new(url) do |client|
@@ -9,6 +9,8 @@ module WhatsappSdk
9
9
  class Messages < Request
10
10
  extend T::Sig
11
11
 
12
+ DEFAULT_HEADERS = T.let({ 'Content-Type' => 'application/json' }, Hash)
13
+
12
14
  class MissingArgumentError < StandardError
13
15
  extend T::Sig
14
16
 
@@ -40,7 +42,8 @@ module WhatsappSdk
40
42
 
41
43
  response = send_request(
42
44
  endpoint: endpoint(sender_id),
43
- params: params
45
+ params: params,
46
+ headers: DEFAULT_HEADERS
44
47
  )
45
48
 
46
49
  WhatsappSdk::Api::Response.new(
@@ -80,7 +83,8 @@ module WhatsappSdk
80
83
 
81
84
  response = send_request(
82
85
  endpoint: endpoint(sender_id),
83
- params: params
86
+ params: params,
87
+ headers: DEFAULT_HEADERS
84
88
  )
85
89
 
86
90
  WhatsappSdk::Api::Response.new(
@@ -120,7 +124,8 @@ module WhatsappSdk
120
124
 
121
125
  response = send_request(
122
126
  endpoint: endpoint(sender_id),
123
- params: params
127
+ params: params,
128
+ headers: DEFAULT_HEADERS
124
129
  )
125
130
 
126
131
  WhatsappSdk::Api::Response.new(
@@ -154,7 +159,8 @@ module WhatsappSdk
154
159
 
155
160
  response = send_request(
156
161
  endpoint: endpoint(sender_id),
157
- params: params
162
+ params: params,
163
+ headers: DEFAULT_HEADERS
158
164
  )
159
165
 
160
166
  WhatsappSdk::Api::Response.new(
@@ -194,7 +200,8 @@ module WhatsappSdk
194
200
 
195
201
  response = send_request(
196
202
  endpoint: endpoint(sender_id),
197
- params: params
203
+ params: params,
204
+ headers: DEFAULT_HEADERS
198
205
  )
199
206
 
200
207
  WhatsappSdk::Api::Response.new(
@@ -234,7 +241,8 @@ module WhatsappSdk
234
241
 
235
242
  response = send_request(
236
243
  endpoint: endpoint(sender_id),
237
- params: params
244
+ params: params,
245
+ headers: DEFAULT_HEADERS
238
246
  )
239
247
 
240
248
  WhatsappSdk::Api::Response.new(
@@ -268,7 +276,8 @@ module WhatsappSdk
268
276
 
269
277
  response = send_request(
270
278
  endpoint: endpoint(sender_id),
271
- params: params
279
+ params: params,
280
+ headers: DEFAULT_HEADERS
272
281
  )
273
282
 
274
283
  WhatsappSdk::Api::Response.new(
@@ -302,7 +311,8 @@ module WhatsappSdk
302
311
 
303
312
  response = send_request(
304
313
  endpoint: endpoint(sender_id),
305
- params: params
314
+ params: params,
315
+ headers: DEFAULT_HEADERS
306
316
  )
307
317
 
308
318
  WhatsappSdk::Api::Response.new(
@@ -338,7 +348,8 @@ module WhatsappSdk
338
348
 
339
349
  response = send_request(
340
350
  endpoint: endpoint(sender_id),
341
- params: params
351
+ params: params,
352
+ headers: DEFAULT_HEADERS
342
353
  )
343
354
 
344
355
  WhatsappSdk::Api::Response.new(
@@ -385,7 +396,8 @@ module WhatsappSdk
385
396
 
386
397
  response = send_request(
387
398
  endpoint: endpoint(sender_id),
388
- params: params
399
+ params: params,
400
+ headers: DEFAULT_HEADERS
389
401
  )
390
402
 
391
403
  WhatsappSdk::Api::Response.new(
@@ -14,9 +14,9 @@ module WhatsappSdk
14
14
  @client.download_file(url, path_to_file_name)
15
15
  end
16
16
 
17
- def send_request(endpoint: nil, full_url: nil, http_method: "post", params: {})
17
+ def send_request(endpoint: nil, full_url: nil, http_method: "post", params: {}, headers: {})
18
18
  @client.send_request(
19
- http_method: http_method, full_url: full_url, endpoint: endpoint, params: params
19
+ http_method: http_method, full_url: full_url, endpoint: endpoint, params: params, headers: headers
20
20
  )
21
21
  end
22
22
  end
@@ -6,6 +6,7 @@ require_relative "responses/phone_number_data_response"
6
6
  require_relative "responses/phone_numbers_data_response"
7
7
  require_relative "responses/read_message_data_response"
8
8
  require_relative "responses/message_error_response"
9
+ require_relative "responses/business_profile_data_response"
9
10
 
10
11
  module WhatsappSdk
11
12
  module Api
@@ -18,6 +19,9 @@ module WhatsappSdk
18
19
  sig { returns(T.nilable(WhatsappSdk::Api::Responses::DataResponse)) }
19
20
  attr_accessor :data
20
21
 
22
+ sig { returns(T::Hash[T.untyped, T.untyped]) }
23
+ attr_accessor :raw_response
24
+
21
25
  sig do
22
26
  params(
23
27
  response: T::Hash[T.untyped, T.untyped],
@@ -26,6 +30,7 @@ module WhatsappSdk
26
30
  ).void
27
31
  end
28
32
  def initialize(response:, data_class_type:, error_class_type: Responses::MessageErrorResponse)
33
+ @raw_response = response
29
34
  @data = data_class_type.build_from_response(response: response)
30
35
  @error = error_class_type.build_from_response(response: response)
31
36
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ require_relative "data_response"
5
+
6
+ module WhatsappSdk
7
+ module Api
8
+ module Responses
9
+ class BusinessProfileDataResponse < DataResponse
10
+ sig { returns(String) }
11
+ attr_accessor :about
12
+
13
+ sig { returns(String) }
14
+ attr_accessor :address
15
+
16
+ sig { returns(String) }
17
+ attr_accessor :description
18
+
19
+ sig { returns(String) }
20
+ attr_accessor :email
21
+
22
+ sig { returns(String) }
23
+ attr_accessor :messaging_product
24
+
25
+ sig { returns(String) }
26
+ attr_accessor :profile_picture_url
27
+
28
+ sig { params(response: T::Hash[T.untyped, T.untyped]).void }
29
+ def initialize(response)
30
+ @about = T.let(response["data"][0]["about"], T.nilable(String))
31
+ @address = T.let(response["data"][0]["address"], T.nilable(String))
32
+ @description = T.let(response["data"][0]["description"], T.nilable(String))
33
+ @email = T.let(response["data"][0]["email"], T.nilable(String))
34
+ @messaging_product = T.let(response["data"][0]["messaging_product"], T.nilable(String))
35
+ @profile_picture_url = T.let(response["data"][0]["profile_picture_url"], T.nilable(String))
36
+ super(response)
37
+ end
38
+
39
+ sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(BusinessProfileDataResponse)) }
40
+ def self.build_from_response(response:)
41
+ return nil if response['error']
42
+
43
+ new(response)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,5 +2,5 @@
2
2
  # typed: strict
3
3
 
4
4
  module WhatsappSdk
5
- VERSION = "0.6.0"
5
+ VERSION = "0.6.2"
6
6
  end
data/whatsapp_sdk.gemspec CHANGED
@@ -11,9 +11,9 @@ Gem::Specification.new do |spec|
11
11
  spec.version = WhatsappSdk::VERSION
12
12
  spec.authors = ["ignacio-chiazzo"]
13
13
  spec.email = ["ignaciochiazzo@gmail.com"]
14
- spec.summary = "Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API"
14
+ spec.summary = "Use the Ruby Whatsapp SDK to communicate with Whatsapp API using the Cloud API"
15
15
  spec.description = <<-DESCRIPTION
16
- Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
16
+ Use the Ruby Whatsapp SDK to communicate with Whatsapp API using the Cloud API.
17
17
  Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
18
18
  DESCRIPTION
19
19
  spec.homepage = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk"
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
46
46
  spec.add_dependency('sorbet')
47
47
  spec.add_dependency('sorbet-runtime')
48
48
 
49
- spec.add_dependency("faraday", "~> 2.3.0")
49
+ spec.add_dependency("faraday", ">= 2.3.0")
50
50
  spec.add_dependency("faraday-multipart", "~> 1.0.4")
51
51
  spec.add_dependency("oj", "~> 3.13.13")
52
52
  spec.add_dependency("zeitwerk", "~> 2.6.0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatsapp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ignacio-chiazzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2022-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: faraday
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 2.3.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.3.0
97
97
  - !ruby/object:Gem::Dependency
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.6.0
139
139
  description: |2
140
- Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
140
+ Use the Ruby Whatsapp SDK to communicate with Whatsapp API using the Cloud API.
141
141
  Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
142
142
  email:
143
143
  - ignaciochiazzo@gmail.com
@@ -166,12 +166,14 @@ files:
166
166
  - bin/tapioca
167
167
  - example.rb
168
168
  - lib/whatsapp_sdk.rb
169
+ - lib/whatsapp_sdk/api/business_profile.rb
169
170
  - lib/whatsapp_sdk/api/client.rb
170
171
  - lib/whatsapp_sdk/api/medias.rb
171
172
  - lib/whatsapp_sdk/api/messages.rb
172
173
  - lib/whatsapp_sdk/api/phone_numbers.rb
173
174
  - lib/whatsapp_sdk/api/request.rb
174
175
  - lib/whatsapp_sdk/api/response.rb
176
+ - lib/whatsapp_sdk/api/responses/business_profile_data_response.rb
175
177
  - lib/whatsapp_sdk/api/responses/data_response.rb
176
178
  - lib/whatsapp_sdk/api/responses/error_response.rb
177
179
  - lib/whatsapp_sdk/api/responses/media_data_response.rb
@@ -246,6 +248,6 @@ requirements: []
246
248
  rubygems_version: 3.3.3
247
249
  signing_key:
248
250
  specification_version: 4
249
- summary: Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud
251
+ summary: Use the Ruby Whatsapp SDK to communicate with Whatsapp API using the Cloud
250
252
  API
251
253
  test_files: []