plivo 4.49.0 → 4.51.0

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
  SHA1:
3
- metadata.gz: ed30e13d70b2483bb821add7ba7cb7207be1096d
4
- data.tar.gz: 155092cdb1a1983dab872b2810ee6a0ad497daed
3
+ metadata.gz: e9064c62f724b62e2aeea109723c81030fe138ef
4
+ data.tar.gz: 8a0348e73d6792c79034d23cb1e7e90748304183
5
5
  SHA512:
6
- metadata.gz: bb91ca43cb84672006c71ceb1aab588db855bae029840f7e353a9d768359cf354b4641075cd1212cfbbc95bd140f22290aca7f4b9f277500b8ba13ace6a1606e
7
- data.tar.gz: 83e334ec371050c18eed54a74e8658d265fd04eeb60b6d37a8c56c18b508fa4c99fcada29d5d420efecea7e5dce3490212b8074746c7da49141a9e46962f9602
6
+ metadata.gz: 7f2331bc3b7eb435076f747b19e54a30662051b534baff258c5dbaba40baf6ae659f1d7abd073c5529e3fad97ec4aca3018896bd63aa7d7003759171a75fc798
7
+ data.tar.gz: cae52fb1615526472e629ca5455c12f4b38b06f9d8332f709487e1f5f2e3e213005981a9fd4a4b57a5285e6c4c3065614c7f5bf4b5e94f29ca9996f202d096a5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
1
  # Change Log
2
+
3
+ ## [4.51.0](https://github.com/plivo/plivo-ruby/tree/v4.51.0) (2023-10-16)
4
+ **Introducing campaign_source & import partner camapign API**
5
+ - New field campaign_source introduced
6
+ - Import partner campaign API added
7
+
8
+ ## [4.50.0](https://github.com/plivo/plivo-ruby/tree/v4.50.0) (2023-10-13)
9
+ **Feature - WhatsApp message support**
10
+ - Added new params `template` and new message_type `whatsapp` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message)
11
+ - Added new `message_state` (`read`), `message_type`(`whatsapp`), `conversation_id`, `conversation_origin`, `conversation_expiration_timestamp` in [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages) and [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message) response
12
+
2
13
  ## [4.49.0](https://github.com/plivo/plivo-ruby/tree/v4.49.0) (2023-09-13)
3
14
  **Removing the faraday_middleware dependency and upgrade to farady latest version
4
15
 
data/README.md CHANGED
@@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'plivo', '>= 4.49.0'
12
+ gem 'plivo', '>= 4.51.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -36,8 +36,9 @@ module Plivo
36
36
  ##
37
37
  # List all Campaign
38
38
  # @param [Hash] options
39
- # @option options [String] :brand
39
+ # @option options [String] :brand_id
40
40
  # @option options [Status] :usecase
41
+ # @option options [String] :campaign_source
41
42
  # @option options [Status] :limit
42
43
  # @option options [Status] :offset
43
44
  # @return [Hash]
@@ -45,7 +46,7 @@ module Plivo
45
46
  return perform_list_without_object if options.nil?
46
47
 
47
48
  params = {}
48
- %i[usecase brand limit offset].each do |param|
49
+ %i[usecase brand_id campaign_source limit offset].each do |param|
49
50
  if options.key?(param) && valid_param?(param, options[param],
50
51
  [String, Integer], true)
51
52
  params[param] = options[param]
@@ -96,6 +97,19 @@ module Plivo
96
97
  perform_action_with_identifier(action, 'POST', options)
97
98
  end
98
99
  ##
100
+
101
+ #import campaign
102
+ def import(options=nil)
103
+ valid_param?(:options, options, Hash, true)
104
+ if not options[:campaign_id]
105
+ raise_invalid_request("campaign_id must be provided")
106
+ end
107
+ if not options[:campaign_alias]
108
+ raise_invalid_request("campaign_alias must be provided")
109
+ end
110
+ action = 'Import'
111
+ perform_action_with_identifier(action, 'POST', options)
112
+ end
99
113
  # campaign number link
100
114
  #
101
115
  def number_link(options=nil)
@@ -42,7 +42,10 @@ module Plivo
42
42
  dlt_template_category: @dlt_template_category,
43
43
  destination_network: @destination_network,
44
44
  carrier_fees_rate: @carrier_fees_rate,
45
- carrier_fees: @carrier_fees
45
+ carrier_fees: @carrier_fees,
46
+ conversation_id: @conversation_id,
47
+ conversation_origin: @conversation_origin,
48
+ conversation_expiration_timestamp: @conversation_expiration_timestamp
46
49
  }.to_s
47
50
  end
48
51
  end
@@ -64,7 +67,7 @@ module Plivo
64
67
  # @param [Array] dst
65
68
  # @param [String] text
66
69
  # @param [Hash] options
67
- # @option options [String] :type The type of message. Should be `sms` or `mms`. Defaults to `sms`.
70
+ # @option options [String] :type The type of message. Should be `sms` or `mms` or `whatsapp`. Defaults to `sms`.
68
71
  # @option options [String] :url The URL to which with the status of the message is sent. The following parameters are sent to the URL:
69
72
  # - To - Phone number of the recipient
70
73
  # - From - Phone number of the sender
@@ -87,13 +90,14 @@ module Plivo
87
90
  # @option options [String] :dlt_entity_id This is the DLT entity id passed in the message request.
88
91
  # @option options [String] :dlt_template_id This is the DLT template id passed in the message request.
89
92
  # @option options [String] :dlt_template_category This is the DLT template category passed in the message request.
93
+ # @option options [Hash] :template This is the template used in the whatsapp message request. It can handle both JSON and String.
90
94
 
91
95
  def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil)
92
96
  #All params in One HASH
93
97
  value = src
94
98
  if(value.is_a?(Hash))
95
99
  valid_param?(:src, value[:src], [Integer, String, Symbol], false)
96
- valid_param?(:text, value[:text], [String, Symbol], true)
100
+ valid_param?(:text, value[:text], [String, Symbol], false)
97
101
  valid_param?(:dst, value[:dst], [String, Array], true)
98
102
  valid_param?(:powerpack_uuid, value[:powerpack_uuid], [String, Symbol], false)
99
103
 
@@ -128,7 +132,7 @@ module Plivo
128
132
  end
129
133
 
130
134
  #Handling optional params in One HASH
131
- if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms])
135
+ if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms whatsapp])
132
136
  params[:type] = value[:type]
133
137
  end
134
138
 
@@ -182,10 +186,44 @@ module Plivo
182
186
  params[:dlt_template_category] = value[:dlt_template_category]
183
187
  end
184
188
 
189
+ # handling whatsapp cases
190
+ if value.key?(:template) && value.key?(:type) && (value[:type] != "whatsapp")
191
+ raise InvalidRequestError, 'template parameter is only applicable when type is whatsapp'
192
+ end
193
+
194
+ if value.is_a?(Hash) && !value[:template].nil?
195
+ if value.key?(:template)
196
+ if value[:template].is_a?(String)
197
+ begin
198
+ json_template = JSON.parse(value[:template])
199
+ params[:template] = json_template
200
+ rescue JSON::ParserError => e
201
+ raise InvalidRequestError, 'failed to parse template as JSON'
202
+ end
203
+ elsif value[:template].is_a?(Hash)
204
+ params[:template] = value[:template]
205
+ elsif value[:template].is_a?(Plivo::Template)
206
+ params[:template] = value[:template].to_hash
207
+ else
208
+ raise InvalidRequestError, 'invalid template format'
209
+ end
210
+ end
211
+ end
212
+
213
+ if !params[:template].nil? && value[:template].is_a?(String)
214
+ if params.dig(:template, "name").to_s.empty? || params.dig(:template, "language").to_s.empty?
215
+ raise InvalidRequestError, 'template name and language must not be null or empty'
216
+ end
217
+ else
218
+ if !params[:template].nil? && (params.dig(:template, :name).to_s.empty? || params.dig(:template, :language).to_s.empty?)
219
+ raise InvalidRequestError, 'template name and language must not be null or empty'
220
+ end
221
+ end
222
+
185
223
  #legacy code compatibility
186
224
  else
187
225
  valid_param?(:src, src, [Integer, String, Symbol], false)
188
- valid_param?(:text, text, [String, Symbol], true)
226
+ valid_param?(:text, text, [String, Symbol], false)
189
227
  valid_param?(:dst, dst, [String, Array], true)
190
228
  valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
191
229
  dst.each do |dst_num|
@@ -223,7 +261,7 @@ module Plivo
223
261
  valid_param?(:options, options, Hash, true)
224
262
 
225
263
  if options.key?(:type) &&
226
- valid_param?(:type, options[:type], String, true, %w[sms mms])
264
+ valid_param?(:type, options[:type], String, true, %w[sms mms whatsapp])
227
265
  params[:type] = options[:type]
228
266
  end
229
267
 
@@ -286,6 +324,41 @@ module Plivo
286
324
  valid_param?(:dlt_template_category, options[:dlt_template_category], String, true)
287
325
  params[:dlt_template_category] = options[:dlt_template_category]
288
326
  end
327
+
328
+ # handling whatsapp cases
329
+ if options.key?(:template) && options.key?(:type) && (options[:type] != "whatsapp")
330
+ raise InvalidRequestError, 'template parameter is only applicable when type is whatsapp'
331
+ end
332
+
333
+ if options.is_a?(Hash) && !options[:template].nil?
334
+ if options.key?(:template)
335
+ if options[:template].is_a?(String)
336
+ begin
337
+ json_template = JSON.parse(options[:template])
338
+ params[:template] = json_template
339
+ rescue JSON::ParserError => e
340
+ raise InvalidRequestError, 'failed to parse template as JSON'
341
+ end
342
+ elsif options[:template].is_a?(Hash)
343
+ params[:template] = options[:template]
344
+ elsif options[:template].is_a?(Plivo::Template)
345
+ params[:template] = options[:template].to_hash
346
+ else
347
+ raise InvalidRequestError, 'invalid template format'
348
+ end
349
+ end
350
+ end
351
+
352
+ if !options[:template].nil? && options[:template].is_a?(String)
353
+ if options.dig(:template, "name").to_s.empty? || options.dig(:template, "language").to_s.empty?
354
+ raise InvalidRequestError, 'template name and language must not be null or empty'
355
+ end
356
+ else
357
+ if !options[:template].nil? && (options.dig(:template, :name).to_s.empty? || options.dig(:template, :language).to_s.empty?)
358
+ raise InvalidRequestError, 'template name and language must not be null or empty'
359
+ end
360
+ end
361
+
289
362
  end
290
363
  perform_create(params)
291
364
  end
@@ -293,6 +366,7 @@ module Plivo
293
366
  # @param [Hash] options
294
367
  # @option options [String] :subaccount The id of the subaccount, if message details of the subaccount is needed.
295
368
  # @option options [String] :message_direction Filter the results by message direction. The valid inputs are inbound and outbound.
369
+ # @option options [String] :message_type Filter the results by message type. The valid inputs are sms mms and whatsapp.
296
370
  # @option options [String] :message_time Filter out messages according to the time of completion. The filter can be used in the following five forms:
297
371
  # - message_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use message_time=2012-03-21 11:47[:30]
298
372
  # - message_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use message_time\__gt=2012-03-21 11:47
@@ -310,6 +384,8 @@ module Plivo
310
384
  # @option options [string]: tendlc_campaign_id - exact tendlc campaign id search
311
385
  # @option options [string]:destination_country_iso2 - valid 2 character country_iso2
312
386
  # @option options [string] : tendlc_registration_status - registered or unregistered enum allowed
387
+ # @option options [string] : conversation_id - The id of the conversation for whatsapp messages
388
+ # @option options [string] : conversartion_origin - The type of the conversation for whatsapp messages
313
389
  def list(options = nil)
314
390
  return perform_list if options.nil?
315
391
  valid_param?(:options, options, Hash, true)
@@ -318,6 +394,7 @@ module Plivo
318
394
  params_expected = %i[
319
395
  subaccount message_time message_time__gt message_time__gte
320
396
  message_time__lt message_time__lte error_code powerpack_id tendlc_campaign_id tendlc_registration_status destination_country_iso2
397
+ message_type conversation_id conversartion_origin
321
398
  ]
322
399
  params_expected.each do |param|
323
400
  if options.key?(param) &&
@@ -341,11 +418,17 @@ module Plivo
341
418
 
342
419
  if options.key?(:message_state) &&
343
420
  valid_param?(:message_state, options[:message_state],
344
- [String, Symbol], true, %w[queued sent failed delivered
421
+ [String, Symbol], true, %w[queued sent failed delivered read
345
422
  undelivered rejected])
346
423
  params[:message_state] = options[:message_state]
347
424
  end
348
425
 
426
+ if options.key?(:message_type) &&
427
+ valid_param?(:message_type, options[:message_type],
428
+ [String, Symbol], true, %w[sms mms whatsapp])
429
+ params[:message_type] = options[:message_type]
430
+ end
431
+
349
432
  if options.key?(:limit) &&
350
433
  (options[:limit] > 20 || options[:limit] <= 0)
351
434
  raise_invalid_request('The maximum number of results that can be '\
@@ -0,0 +1,97 @@
1
+ require_relative "resources"
2
+ require_relative "base_client"
3
+ require_relative "base"
4
+ module Plivo
5
+ class Template
6
+ attr_accessor :name, :language, :components
7
+
8
+ def initialize(name: nil, language: nil, components: nil)
9
+ @name = name
10
+ @language = language
11
+ @components = components
12
+ end
13
+
14
+ def to_hash
15
+ {
16
+ name: @name,
17
+ language: @language,
18
+ components: @components&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
19
+ }.reject { |_, v| v.nil? }
20
+ end
21
+ end
22
+
23
+ class Component
24
+ attr_accessor :type, :sub_type, :index, :parameters
25
+
26
+ def initialize(type: nil, sub_type: nil, index: nil, parameters: nil)
27
+ @type = type
28
+ @sub_type = sub_type
29
+ @index = index
30
+ @parameters = parameters
31
+ end
32
+
33
+ def to_hash
34
+ {
35
+ type: @type,
36
+ sub_type: @sub_type,
37
+ index: @index,
38
+ parameters: @parameters&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
39
+ }.reject { |_, v| v.nil? }
40
+ end
41
+ end
42
+
43
+ class Parameter
44
+ attr_accessor :type, :text, :media, :currency, :date_time
45
+
46
+ def initialize(type: nil, text: nil, media: nil, currency: nil, date_time: nil)
47
+ @type = type
48
+ @text = text
49
+ @media = media
50
+ @currency = currency
51
+ @date_time = date_time
52
+ end
53
+
54
+ def to_hash
55
+ {
56
+ type: @type,
57
+ text: @text,
58
+ media: @media,
59
+ currency: @currency&.to_hash,
60
+ date_time: @date_time&.to_hash
61
+ }.reject { |_, v| v.nil? }
62
+ end
63
+ end
64
+
65
+ class Currency
66
+ attr_accessor :fallback_value, :currency_code, :amount_1000
67
+
68
+ def initialize(fallback_value: nil, currency_code: nil, amount_1000: nil)
69
+ @fallback_value = fallback_value
70
+ @currency_code = currency_code
71
+ @amount_1000 = amount_1000
72
+ end
73
+
74
+ def to_hash
75
+ {
76
+ fallback_value: @fallback_value,
77
+ currency_code: @currency_code,
78
+ amount_1000: @amount_1000
79
+ }.reject { |_, v| v.nil? }
80
+ end
81
+ end
82
+
83
+ class DateTime
84
+ attr_accessor :fallback_value
85
+
86
+ def initialize(fallback_value: nil)
87
+ @fallback_value = fallback_value
88
+ end
89
+
90
+ def to_hash
91
+ {
92
+ fallback_value: @fallback_value
93
+ }.reject { |_, v| v.nil? }
94
+ end
95
+ end
96
+ end
97
+
data/lib/plivo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = "4.49.0".freeze
2
+ VERSION = "4.51.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.49.0
4
+ version: 4.51.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Plivo SDKs Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-15 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -193,6 +193,7 @@ files:
193
193
  - lib/plivo/resources/regulatory_compliance.rb
194
194
  - lib/plivo/resources/token.rb
195
195
  - lib/plivo/rest_client.rb
196
+ - lib/plivo/template.rb
196
197
  - lib/plivo/utils.rb
197
198
  - lib/plivo/version.rb
198
199
  - lib/plivo/xml.rb