plivo 4.17.1 → 4.21.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: 7e0cf782f59b0fdc5751760de942c004c486b88e
4
- data.tar.gz: '059f69a1d0dbba6f854a5d36f9dae7b84f18acaf'
3
+ metadata.gz: d4221884a48c30837e399b3cccf82a2b316b1c8b
4
+ data.tar.gz: 439b0e03c1e2208bc8c00670decba683c9c4a8d9
5
5
  SHA512:
6
- metadata.gz: 2cf38bfcd9981dba0492dbd15fbb7698140a6ff65a58498887289de19d04cac4885fc5468b84e24f3ad80d1232c62af9b80e07def7b64845d0ed92a0592df5f4
7
- data.tar.gz: abbcd68c9a8b41abd9a7f5dcad3d0bfdf22dc72ab49f87ade0138dd954d71c95bd1a990f829c90e1c14b1d6c728bb2071eb4b9090833bfe12e7c628233b58872
6
+ metadata.gz: d349d186ca2bd0b10e6b38b29bb1d44f431e9e00fc97643e72f82c78ff154f1850df29a030bc6fcad71cf7e9e74831d0049b94a2eb5eb3c091fe833d364e461e
7
+ data.tar.gz: f2cc7bdb7e9aafa70a7954c20f6344a25833e565ad8db8d3bff362de546bb46139a886757b3290e4c3f5ca2ecb8e6726aedc3ebbf81dbd4563d0fed70758b656
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.21.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.21.0) (2021-10-11)
4
+ **Features - Messaging**
5
+ - This version includes advancements to the Messaging Interface that deals with the [Send SMS/MMS](https://www.plivo.com/docs/sms/api/message#send-a-message) interface, Creating a standard structure for `request/input` arguments to make implementation easier and incorporating support for the older interface.
6
+
7
+ Example for [send SMS](https://github.com/plivo/plivo-ruby#send-a-message)
8
+
9
+ ## [4.20.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.20.0) (2021-08-04)
10
+ - Added continue speak XML element support.
11
+
12
+ ## [4.19.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.19.0) (2021-07-19)
13
+ - Add support for Voice MultiPartyCall APIs (includes retry) and XML, validate voice UTs
14
+
15
+ ## [4.18.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.18.0) (2021-07-13)
16
+ - Power pack ID has been included to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message).
17
+ - Support for filtering messages by Power pack ID has been added to the [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages).
18
+
3
19
  ## [4.17.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.17.1) (2021-06-18)
4
20
  - **WARNING**: Remove total_count field from meta data for list MDR response
5
21
 
data/README.md CHANGED
@@ -8,9 +8,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
-
12
- gem 'plivo', '>= 4.17.1'
13
-
11
+ gem 'plivo', '>= 4.21.0'
14
12
  ```
15
13
 
16
14
  And then execute:
@@ -41,7 +39,7 @@ client = RestClient.new;
41
39
  Alternatively, you can specifiy the authentication credentials while initializing the `RestClient`.
42
40
 
43
41
  ```ruby
44
- client = RestClient.new('your_auth_id', 'your_auth_token');
42
+ client = RestClient.new('<auth_id>', '<auth_token>');
45
43
  ```
46
44
 
47
45
  ### The basics
@@ -78,17 +76,15 @@ end
78
76
  ### Send a message
79
77
 
80
78
  ```ruby
81
- require 'rubygems'
82
- require 'plivo'
83
-
79
+ require "plivo"
84
80
  include Plivo
85
81
 
86
82
  client = RestClient.new
87
- message_created = client.messages.create(
88
- 'your_source_number',
89
- %w[your_destination_number_1 your_destination_number_2],
90
- 'Hello, world!'
91
- )
83
+ response = client.messages.create(
84
+ src: '+14156667778',
85
+ dst: '+14156667777',
86
+ text: 'Hello, this is a sample text'
87
+ )
92
88
  ```
93
89
 
94
90
  ### Make a call
@@ -101,8 +97,8 @@ include Plivo
101
97
 
102
98
  client = RestClient.new
103
99
  call_made = client.calls.create(
104
- 'your_source_number',
105
- ['your_destination_number'],
100
+ '+14156667778',
101
+ ['+14156667777'],
106
102
  'https://answer.url'
107
103
  )
108
104
  ```
@@ -151,10 +147,7 @@ require 'plivo'
151
147
 
152
148
  include Plivo
153
149
 
154
- AUTH_ID = 'AUTH_ID'
155
- AUTH_TOKEN = 'AUTH_TOKEN'
156
-
157
- client = Phlo.new(AUTH_ID, AUTH_TOKEN)
150
+ client = Phlo.new('<auth_id>', '<auth_token>')
158
151
 
159
152
  # if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
160
153
  # then initialize client as:
@@ -164,8 +157,8 @@ client = Phlo.new(AUTH_ID, AUTH_TOKEN)
164
157
  begin
165
158
  #parameters set in PHLO - params
166
159
  params = {
167
- from: '9999999999',
168
- to: '0000000000'
160
+ from: '+14156667778',
161
+ to: '+14156667777'
169
162
  }
170
163
  response = phlo.run(params)
171
164
  puts response
@@ -175,7 +168,7 @@ begin
175
168
  ```
176
169
 
177
170
  ### More examples
178
- Refer to the [Ruby API Reference](https://api-reference.plivo.com/latest/ruby/introduction/overview) for more examples. Also refer to the [guide to setting up dev environment](https://developers.plivo.com/getting-started/setting-up-dev-environment/) on [Plivo Developers Portal](https://developers.plivo.com) to setup a Sinatra server & use it to test out your integration in under 5 minutes.
171
+ More examples are available [here](https://github.com/plivo/plivo-examples-ruby). Also refer to the [guides for configuring the Rails server to run various scenarios](https://www.plivo.com/docs/sms/quickstart/ruby-rails/) & use it to test out your integration in under 5 minutes.
179
172
 
180
173
  ## Reporting issues
181
174
  Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-ruby/issues).
@@ -114,5 +114,35 @@ module Plivo
114
114
  Response.new(response_json, @_identifier_string)
115
115
  end
116
116
  end
117
+
118
+ class SecondaryResource < Resource
119
+ attr_reader :secondary_id
120
+ def initialize(client, options = nil)
121
+ super
122
+ configure_secondary_options(options) if options
123
+ configure_secondary_resource_uri
124
+ end
125
+
126
+ def configure_secondary_options(options)
127
+ valid_param?(:options, options, Hash, false)
128
+ @secondary_id = options[:member_id] if options.key?(:member_id)
129
+ secondary_parse_and_set(options[:resource_json]) if options.key?(:resource_json)
130
+ end
131
+
132
+ def secondary_parse_and_set(resource_json)
133
+ return unless resource_json
134
+
135
+ valid_param?(:resource_json, resource_json, Hash, true)
136
+ return unless @_secondary_identifier_string && (resource_json.key? @_secondary_identifier_string)
137
+ @secondary_id = resource_json[@_secondary_identifier_string]
138
+ end
139
+
140
+ def configure_secondary_resource_uri
141
+ to_join = @secondary_id ? [@_client.auth_id, @_name, @id, @_secondary_name, @secondary_id] : [@_client.auth_id, @_name, @id]
142
+ to_join = ['', 'v1', 'Account'] << to_join
143
+ to_join << ''
144
+ @_resource_uri = to_join.join('/')
145
+ end
146
+ end
117
147
  end
118
148
  end
@@ -33,7 +33,7 @@ module Plivo
33
33
  raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
34
34
  'couldn\'t be deleted'
35
35
  end
36
- elsif !([200, 201, 202, 207].include? response[:status])
36
+ elsif !([200, 201, 202, 204, 207].include? response[:status])
37
37
  raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}"
38
38
  end
39
39
  @@voice_retry_count = 0
@@ -266,6 +266,7 @@ module Plivo
266
266
  req.url resource_path
267
267
  req.options.timeout = timeout if timeout
268
268
  req.body = data
269
+ puts req
269
270
  end
270
271
  else
271
272
  if !data.nil? && (data.has_key? 'is_callinsights_request')
@@ -29,6 +29,7 @@ module Plivo
29
29
  to_number: @to_number,
30
30
  total_amount: @total_amount,
31
31
  total_rate: @total_rate,
32
+ powerpack_id: @powerpack_id,
32
33
  units: @units
33
34
  }.to_s
34
35
  end
@@ -68,72 +69,160 @@ module Plivo
68
69
  # @option options [String] :method The method used to call the url. Defaults to POST.
69
70
  # @option options [String] :log If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
70
71
  # @option options [String] :trackable set to false
71
- #@option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
72
- #@option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
73
-
74
- def create(src, dst, text = nil, options = nil, powerpack_uuid = nil)
75
- valid_param?(:src, src, [Integer, String, Symbol], false)
76
- valid_param?(:text, text, [String, Symbol], false)
77
- valid_param?(:dst, dst, Array, true)
78
- valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
79
- dst.each do |dst_num|
80
- valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
81
- end
72
+ # @option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
73
+ # @option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
74
+
75
+ def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil)
76
+ #All params in One HASH
77
+ value = src
78
+ if(value.is_a?(Hash))
79
+ valid_param?(:src, value[:src], [Integer, String, Symbol], false)
80
+ valid_param?(:text, value[:text], [String, Symbol], true)
81
+ valid_param?(:dst, value[:dst], [String, Array], true)
82
+ valid_param?(:powerpack_uuid, value[:powerpack_uuid], [String, Symbol], false)
82
83
 
83
- if dst.include? src
84
- raise InvalidRequestError, 'src and dst cannot be same'
85
- end
84
+ if (value[:dst] == value[:src])
85
+ raise InvalidRequestError, 'src and dst cannot be same'
86
+ end
86
87
 
87
- if src.nil? && powerpack_uuid.nil?
88
- raise InvalidRequestError, 'src and powerpack uuid both cannot be nil'
89
- end
88
+ if value.key?(:value).nil? && value.key(:powerpack_uuid).nil?
89
+ raise InvalidRequestError, 'value and powerpack uuid both cannot be nil'
90
+ end
90
91
 
91
- if !src.nil? && !powerpack_uuid.nil?
92
- raise InvalidRequestError, 'src and powerpack uuid both cannot be present'
93
- end
92
+ if !value.key?(:value).nil? && !value.key(:powerpack_uuid).nil?
93
+ raise InvalidRequestError, 'value and powerpack uuid both cannot be present'
94
+ end
94
95
 
95
- params = {
96
- src: src,
97
- dst: dst.join('<'),
98
- text: text,
99
- powerpack_uuid: powerpack_uuid
100
- }
96
+ if !value.key?(:dst).nil? && !value.key(:powerpack_uuid).nil?
97
+ raise InvalidRequestError, 'dst is a required parameter'
98
+ end
101
99
 
102
- return perform_create(params) if options.nil?
103
- valid_param?(:options, options, Hash, true)
100
+ params = {
101
+ src: value[:src],
102
+ dst: value[:dst],
103
+ text: value[:text],
104
+ powerpack_uuid: value[:powerpack_uuid]
105
+ }
104
106
 
105
- if options.key?(:type) &&
106
- valid_param?(:type, options[:type], String, true, ['sms', 'mms'])
107
- params[:type] = options[:type]
108
- end
107
+ #Handling optional params in One HASH
108
+ if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms])
109
+ params[:type] = value[:type]
110
+ end
111
+
112
+ if value.key?(:url) && valid_param?(:url, value[:url], String, true)
113
+ params[:url] = value[:url]
114
+ if value.key?(:method) &&
115
+ valid_param?(:method, value[:method], String, true, %w[POST GET])
116
+ params[:method] = value[:method]
117
+ else
118
+ params[:method] = 'POST'
119
+ end
120
+ end
121
+
122
+ if value.key?(:log) &&
123
+ valid_param?(:log, value[:log], [TrueClass, FalseClass], true)
124
+ params[:log] = value[:log]
125
+ end
126
+
127
+ if value.key?(:trackable) &&
128
+ valid_param?(:trackable, value[:trackable], [TrueClass, FalseClass], true)
129
+ params[:trackable] = value[:trackable]
130
+ end
131
+
132
+ if value.key?(:media_urls) &&
133
+ valid_param?(:media_urls, value[:media_urls], Array, true)
134
+ params[:media_urls] = value[:media_urls]
135
+ end
136
+
137
+ if value.key?(:media_ids) &&
138
+ valid_param?(:media_ids, value[:media_ids], Array, true)
139
+ params[:media_ids] = value[:media_ids]
140
+ end
141
+
142
+ #legacy code compatibility
143
+ else
144
+ valid_param?(:src, src, [Integer, String, Symbol], false)
145
+ valid_param?(:text, text, [String, Symbol], true)
146
+ valid_param?(:dst, dst, [String, Array], true)
147
+ valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
148
+ dst.each do |dst_num|
149
+ valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
150
+ end
151
+
152
+ if dst.include? src
153
+ raise InvalidRequestError, 'src and dst cannot be same'
154
+ end
109
155
 
110
- if options.key?(:url) && valid_param?(:url, options[:url], String, true)
111
- params[:url] = options[:url]
112
- if options.key?(:method) &&
113
- valid_param?(:method, options[:method], String, true, %w[POST GET])
114
- params[:method] = options[:method]
156
+ if src.nil? && powerpack_uuid.nil?
157
+ raise InvalidRequestError, 'src and powerpack uuid both cannot be nil'
158
+ end
159
+
160
+ if !src.nil? && !powerpack_uuid.nil?
161
+ raise InvalidRequestError, 'src and powerpack uuid both cannot be present'
162
+ end
163
+
164
+ params = {
165
+ src: src,
166
+ text: text,
167
+ powerpack_uuid: powerpack_uuid
168
+ }
169
+
170
+ if (dst.is_a?(Array))
171
+ dst.each do |dst_num|
172
+ valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
173
+ params[:dst] = dst.join('<')
174
+ end
115
175
  else
116
- params[:method] = 'POST'
176
+ params[:dst] = dst
117
177
  end
118
- end
119
178
 
120
- if options.key?(:log) &&
121
- valid_param?(:log, options[:log], [TrueClass, FalseClass], true)
122
- params[:log] = options[:log]
123
- end
179
+ return perform_create(params) if options.nil?
180
+ valid_param?(:options, options, Hash, true)
124
181
 
125
- if options.key?(:trackable) &&
126
- valid_param?(:trackable, options[:trackable], [TrueClass, FalseClass], true)
127
- params[:trackable] = options[:trackable]
128
- end
182
+ if options.key?(:type) &&
183
+ valid_param?(:type, options[:type], String, true, %w[sms mms])
184
+ params[:type] = options[:type]
185
+ end
129
186
 
130
- if options.key?(:media_urls) &&
131
- valid_param?(:media_urls, options[:media_urls], Array, true)
132
- params[:media_urls] = options[:media_urls]
133
- end
134
- if options.key?(:media_ids) &&
135
- valid_param?(:media_ids, options[:media_ids], Array, true)
136
- params[:media_ids] = options[:media_ids]
187
+ if options.key?(:url) && valid_param?(:url, options[:url], String, true)
188
+ params[:url] = options[:url]
189
+ if options.key?(:method) &&
190
+ valid_param?(:method, options[:method], String, true, %w[POST GET])
191
+ params[:method] = options[:method]
192
+ else
193
+ params[:method] = 'POST'
194
+ end
195
+ end
196
+
197
+ if options.key?(:media_urls) &&
198
+ valid_param?(:media_urls, options[:media_urls], Array, true)
199
+ params[:media_urls] = options[:media_urls]
200
+ end
201
+
202
+ if options.key?(:media_ids) &&
203
+ valid_param?(:media_ids, options[:media_ids], Array, true)
204
+ params[:media_ids] = options[:media_ids]
205
+ end
206
+
207
+ if options.key?(:log) &&
208
+ valid_param?(:log, options[:log], [TrueClass, FalseClass], true)
209
+ params[:log] = options[:log]
210
+ end
211
+
212
+ if options.key?(:media_urls) &&
213
+ valid_param?(:media_urls, options[:media_urls], Array, true)
214
+ params[:media_urls] = options[:media_urls]
215
+ end
216
+
217
+ if options.key?(:media_ids) &&
218
+ valid_param?(:media_ids, options[:media_ids], Array, true)
219
+ params[:media_ids] = options[:media_ids]
220
+ end
221
+
222
+ if options.key?(:trackable) &&
223
+ valid_param?(:trackable, options[:trackable], [TrueClass, FalseClass], true)
224
+ params[:trackable] = options[:trackable]
225
+ end
137
226
  end
138
227
  perform_create(params)
139
228
  end
@@ -152,8 +241,9 @@ module Plivo
152
241
  # @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
153
242
  # @option options [Int] :offset Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
154
243
  # @option options [String] :error_code Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
155
- #@option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
156
- #@option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
244
+ # @option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
245
+ # @option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
246
+ # @option options [String] :powerpack_id Filter the results by powerpack id
157
247
  def list(options = nil)
158
248
  return perform_list if options.nil?
159
249
  valid_param?(:options, options, Hash, true)
@@ -161,7 +251,7 @@ module Plivo
161
251
  params = {}
162
252
  params_expected = %i[
163
253
  subaccount message_time message_time__gt message_time__gte
164
- message_time__lt message_time__lte error_code
254
+ message_time__lt message_time__lte error_code powerpack_id
165
255
  ]
166
256
  params_expected.each do |param|
167
257
  if options.key?(param) &&