plivo 0.3.19 → 4.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/AUTHORS.md +4 -0
  6. data/CHANGELOG.md +158 -0
  7. data/Gemfile +10 -0
  8. data/Jenkinsfile +7 -0
  9. data/LICENSE.txt +19 -0
  10. data/README.md +155 -24
  11. data/Rakefile +9 -0
  12. data/ci/config.yml +7 -0
  13. data/examples/conference_bridge.rb +108 -0
  14. data/examples/jwt.rb +32 -0
  15. data/examples/lookup.rb +24 -0
  16. data/examples/multi_party_call.rb +295 -0
  17. data/examples/phlos.rb +55 -0
  18. data/examples/regulatory_compliance.rb +167 -0
  19. data/lib/plivo/base/resource.rb +148 -0
  20. data/lib/plivo/base/resource_interface.rb +108 -0
  21. data/lib/plivo/base/response.rb +38 -0
  22. data/lib/plivo/base.rb +17 -0
  23. data/lib/plivo/base_client.rb +393 -0
  24. data/lib/plivo/exceptions.rb +50 -0
  25. data/lib/plivo/jwt.rb +120 -0
  26. data/lib/plivo/phlo_client.rb +29 -0
  27. data/lib/plivo/resources/accounts.rb +181 -0
  28. data/lib/plivo/resources/addresses.rb +302 -0
  29. data/lib/plivo/resources/applications.rb +258 -0
  30. data/lib/plivo/resources/call_feedback.rb +55 -0
  31. data/lib/plivo/resources/calls.rb +559 -0
  32. data/lib/plivo/resources/conferences.rb +367 -0
  33. data/lib/plivo/resources/endpoints.rb +132 -0
  34. data/lib/plivo/resources/identities.rb +319 -0
  35. data/lib/plivo/resources/lookup.rb +88 -0
  36. data/lib/plivo/resources/media.rb +97 -0
  37. data/lib/plivo/resources/messages.rb +215 -0
  38. data/lib/plivo/resources/multipartycalls.rb +554 -0
  39. data/lib/plivo/resources/nodes.rb +83 -0
  40. data/lib/plivo/resources/numbers.rb +319 -0
  41. data/lib/plivo/resources/phlo_member.rb +64 -0
  42. data/lib/plivo/resources/phlos.rb +55 -0
  43. data/lib/plivo/resources/powerpacks.rb +717 -0
  44. data/lib/plivo/resources/pricings.rb +43 -0
  45. data/lib/plivo/resources/recordings.rb +116 -0
  46. data/lib/plivo/resources/regulatory_compliance.rb +610 -0
  47. data/lib/plivo/resources.rb +25 -0
  48. data/lib/plivo/rest_client.rb +63 -0
  49. data/lib/plivo/utils.rb +294 -0
  50. data/lib/plivo/version.rb +3 -0
  51. data/lib/plivo/xml/break.rb +31 -0
  52. data/lib/plivo/xml/conference.rb +20 -0
  53. data/lib/plivo/xml/cont.rb +13 -0
  54. data/lib/plivo/xml/dial.rb +16 -0
  55. data/lib/plivo/xml/dtmf.rb +13 -0
  56. data/lib/plivo/xml/element.rb +106 -0
  57. data/lib/plivo/xml/emphasis.rb +17 -0
  58. data/lib/plivo/xml/get_digits.rb +15 -0
  59. data/lib/plivo/xml/get_input.rb +16 -0
  60. data/lib/plivo/xml/hangup.rb +12 -0
  61. data/lib/plivo/xml/lang.rb +29 -0
  62. data/lib/plivo/xml/message.rb +13 -0
  63. data/lib/plivo/xml/multipartycall.rb +188 -0
  64. data/lib/plivo/xml/number.rb +13 -0
  65. data/lib/plivo/xml/p.rb +12 -0
  66. data/lib/plivo/xml/phoneme.rb +20 -0
  67. data/lib/plivo/xml/play.rb +13 -0
  68. data/lib/plivo/xml/plivo_xml.rb +19 -0
  69. data/lib/plivo/xml/pre_answer.rb +12 -0
  70. data/lib/plivo/xml/prosody.rb +28 -0
  71. data/lib/plivo/xml/record.rb +17 -0
  72. data/lib/plivo/xml/redirect.rb +13 -0
  73. data/lib/plivo/xml/response.rb +21 -0
  74. data/lib/plivo/xml/s.rb +12 -0
  75. data/lib/plivo/xml/say_as.rb +24 -0
  76. data/lib/plivo/xml/speak.rb +28 -0
  77. data/lib/plivo/xml/sub.rb +16 -0
  78. data/lib/plivo/xml/user.rb +13 -0
  79. data/lib/plivo/xml/w.rb +17 -0
  80. data/lib/plivo/xml/wait.rb +12 -0
  81. data/lib/plivo/xml.rb +39 -0
  82. data/lib/plivo.rb +12 -815
  83. data/plivo.gemspec +44 -0
  84. metadata +181 -41
  85. data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,319 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+
5
+ class PhoneNumber < Base::Resource
6
+ def initialize(client, options = nil)
7
+ @_name = 'PhoneNumber'
8
+ @_identifier_string = 'number'
9
+ super
10
+ end
11
+
12
+ def buy(app_id = nil, verification_info = nil)
13
+ params = {}
14
+ params[:app_id] = app_id unless app_id.nil?
15
+ params[:verification_info] = verification_info unless verification_info.nil?
16
+ perform_action(nil, 'POST', params, true)
17
+ end
18
+
19
+ def to_s
20
+ {
21
+ country: @country,
22
+ lata: @lata,
23
+ monthly_rental_rate: @monthly_rental_rate,
24
+ number: @number,
25
+ type: @type,
26
+ prefix: @prefix,
27
+ rate_center: @rate_center,
28
+ region: @region,
29
+ resource_uri: @resource_uri,
30
+ restriction: @restriction,
31
+ restriction_text: @restriction_text,
32
+ setup_rate: @setup_rate,
33
+ sms_enabled: @sms_enabled,
34
+ sms_rate: @sms_rate,
35
+ voice_enabled: @voice_enabled,
36
+ voice_rate: @voice_rate
37
+ }.to_s
38
+ end
39
+ end
40
+
41
+ class PhoneNumberInterface < Base::ResourceInterface
42
+ def initialize(client, resource_list_json = nil)
43
+ @_name = 'PhoneNumber'
44
+ @_resource_type = PhoneNumber
45
+ @_identifier_string = 'number'
46
+ super
47
+ end
48
+
49
+ # @param [String] country_iso The ISO code A2 of the country ( BE for Belgium, DE for Germany, GB for United Kingdom, US for United States etc ). See the Wikipedia site for a list of ISOs for different countries.
50
+ # @param [Hash] options
51
+ # @option options [String] :type The type of number you are looking for. The possible number types are fixed, mobile and tollfree. Defaults to any if this field is not specified. type also accepts the value any, which will search for all 3 number types.
52
+ # @option options [String] :pattern Represents the pattern of the number to be searched. Adding a pattern will search for numbers which start with the country code + pattern. For eg. a pattern of 415 and a country_iso: US will search for numbers starting with 1415.
53
+ # @option options [String] :region This filter is only applicable when the type is fixed. If the type is not provided, it is assumed to be fixed. Region based filtering can be performed with the following terms:
54
+ # - Exact names of the region: You could use region=Frankfurt if you were looking for a number in Frankfurt. Performed if the search term is three or more characters in length.
55
+ # @option options [String] :services Filters out phone numbers according to the services you want from that number. The following values are valid:
56
+ # - voice - If this option is selected, it ensures that the results have voice enabled numbers. These numbers may or may not be SMS enabled.
57
+ # - voice,sms - If this option is selected, it ensures that the results have both voice and sms enabled on the same number.
58
+ # - sms - If this option is selected, it ensures that the results have sms enabled numbers. These numbers may or may not be voice enabled.
59
+ # - By default, numbers that have either voice or sms or both enabled are returned.
60
+ # @option options [String] :lata Numbers can be searched using Local Access and Transport Area {http://en.wikipedia.org/wiki/Local_access_and_transport_area}. This filter is applicable only for country_iso US and CA.
61
+ # @option options [String] :rate_center Numbers can be searched using Rate Center {http://en.wikipedia.org/wiki/Telephone_exchange}. This filter is application only for country_iso US and CA.
62
+ # @option options [String] :city Filter phone number based on the city name. This filter is only applicable when the type is Local
63
+ # @option options [Boolean] :eligible If set to true, lists only those numbers that you are eligible to buy at the moment. To list all numbers, ignore this option.
64
+ # @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
65
+ # @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.
66
+ def search(country_iso, options = nil)
67
+ valid_param?(:country_iso, country_iso, [String, Symbol], true)
68
+ unless country_iso.length == 2
69
+ raise_invalid_request('country_iso should be of length 2')
70
+ end
71
+ params = { country_iso: country_iso }
72
+
73
+ return perform_list(params) if options.nil?
74
+
75
+ %i[type pattern region services lata rate_center city].each do |param|
76
+ if options.key?(param) &&
77
+ valid_param?(param, options[param], [String, Symbol], true)
78
+ params[param] = options[param]
79
+ end
80
+ end
81
+
82
+ %i[offset limit].each do |param|
83
+ if options.key?(param) && valid_param?(param, options[param],
84
+ [Integer, Integer], true)
85
+ params[param] = options[param]
86
+ end
87
+ end
88
+
89
+ %i[eligible].each do |param|
90
+ if options.key?(param) && valid_param?(param, options[param],
91
+ nil, true, [true, false])
92
+ params[param] = options[param]
93
+ end
94
+ end
95
+
96
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
97
+ raise_invalid_request('The maximum number of results that can be '\
98
+ "fetched is 20. limit can't be more than 20 or less than 1")
99
+ end
100
+
101
+ if options.key?(:offset) && options[:offset] < 0
102
+ raise_invalid_request("Offset can't be negative")
103
+ end
104
+
105
+ perform_list(params)
106
+ end
107
+
108
+ def each(country_iso)
109
+ offset = 0
110
+ loop do
111
+ phone_number_list = search(country_iso, offset: offset)
112
+ phone_number_list[:objects].each { |phone_number| yield phone_number }
113
+ offset += 20
114
+ return unless number_list.length == 20
115
+ end
116
+ end
117
+
118
+ def buy(number, app_id = nil, verification_info = nil)
119
+ valid_param?(:number, number, [Integer, String, Symbol], true)
120
+ PhoneNumber.new(@_client,
121
+ resource_id: number).buy(app_id, verification_info)
122
+ end
123
+ end
124
+
125
+ class Number < Base::Resource
126
+ def initialize(client, options = nil)
127
+ @_name = 'Number'
128
+ @_identifier_string = 'number'
129
+ super
130
+ end
131
+
132
+ def update(options = nil)
133
+ valid_param?(:options, options, Hash, true)
134
+
135
+ params = {}
136
+
137
+ if options.key?(:subaccount) &&
138
+ valid_subaccount?(options[:subaccount], true)
139
+ params[:subaccount] = options[:subaccount]
140
+ end
141
+
142
+ %i[alias app_id].each do |param|
143
+ if options.key?(param) &&
144
+ valid_param?(param, options[param], [String, Symbol], true)
145
+ params[param] = options[param]
146
+ end
147
+ end
148
+
149
+ %i[verification_info].each do |param|
150
+ if options.key?(param) &&
151
+ valid_param?(param, options[param], Hash, true)
152
+ params[param] = options[param]
153
+ end
154
+ end
155
+
156
+ perform_update(params)
157
+ end
158
+
159
+ def delete
160
+ perform_delete
161
+ end
162
+
163
+ def to_s
164
+ {
165
+ api_id: @api_id,
166
+ added_on: @added_on,
167
+ alias: @alias,
168
+ application: @application,
169
+ carrier: @carrier,
170
+ monthly_rental_rate: @monthly_rental_rate,
171
+ number: @number,
172
+ number_type: @number_type,
173
+ region: @region,
174
+ resource_uri: @resource_uri,
175
+ sms_enabled: @sms_enabled,
176
+ sms_rate: @sms_rate,
177
+ sub_account: @sub_account,
178
+ voice_enabled: @voice_enabled,
179
+ voice_rate: @voice_rate
180
+ }.to_s
181
+ end
182
+ end
183
+
184
+ class NumberInterface < Base::ResourceInterface
185
+ def initialize(client, resource_list_json = nil)
186
+ @_name = 'Number'
187
+ @_resource_type = Number
188
+ @_identifier_string = 'number'
189
+ super
190
+ end
191
+
192
+ # @param [String] number
193
+ def get(number)
194
+ perform_get(number)
195
+ end
196
+
197
+ # @param [Hash] options
198
+ # @option options [String] :type The type of number you are filtering. You can filter by local and tollfree numbers. Defaults to a local number.
199
+ # @option options [String|Int] :number_startswith Used to specify the beginning of the number. For example, if the number '24' is specified, the API will fetch only those numbers beginning with '24'.
200
+ # @option options [String] :subaccount Requires the auth_id of the subaccount as input. If this parameter is included in the request, all numbers of the particular subaccount are displayed.
201
+ # @option options [String] :alias This is a name given to the number. The API will fetch only those numbers with the alias specified.
202
+ # @option options [String] :services Filters out phone numbers according to the services you want from that number. The following values are valid:
203
+ # - voice - Returns a list of numbers that provide 'voice' services. Additionally, if the numbers offer both 'voice' and 'sms', they are also listed. Note - This option does not exclusively list those services that provide both voice and sms .
204
+ # - voice,sms - Returns a list of numbers that provide both 'voice' and 'sms' services.
205
+ # - sms - Returns a list of numbers that provide only 'sms' services.
206
+ # @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
207
+ # @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.
208
+ def list(options = nil)
209
+ return perform_list if options.nil?
210
+
211
+ valid_param?(:options, options, Hash, true)
212
+
213
+ params = {}
214
+
215
+ %i[number_startswith subaccount alias].each do |param|
216
+ if options.key?(param) &&
217
+ valid_param?(param, options[param], [String, Symbol], true)
218
+ params[param] = options[param]
219
+ end
220
+ end
221
+
222
+ if options.key?(:services) &&
223
+ valid_param?(:services, options[:services], [String, Symbol],
224
+ true, %w[sms voice voice,sms])
225
+ params[:services] = options[:services]
226
+ end
227
+
228
+ if options.key?(:type) &&
229
+ valid_param?(:type, options[:type], [String, Symbol],
230
+ true, %w[local tollfree])
231
+ params[:type] = options[:type]
232
+ end
233
+
234
+ %i[offset limit].each do |param|
235
+ if options.key?(param) && valid_param?(param, options[param],
236
+ [Integer, Integer], true)
237
+ params[param] = options[param]
238
+ end
239
+ end
240
+
241
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
242
+ raise_invalid_request('The maximum number of results that can be '\
243
+ "fetched is 20. limit can't be more than 20 or less than 1")
244
+ end
245
+
246
+ if options.key?(:offset) && options[:offset] < 0
247
+ raise_invalid_request("Offset can't be negative")
248
+ end
249
+
250
+ perform_list(params)
251
+ end
252
+
253
+ def each
254
+ offset = 0
255
+ loop do
256
+ number_list = list(offset: offset)
257
+ number_list[:objects].each { |number| yield number }
258
+ offset += 20
259
+ return unless number_list.length == 20
260
+ end
261
+ end
262
+
263
+ # @param [Array] numbers An array of numbers that need to be added for the carrier. Make sure that you configure the numbers to point to the sip server @sbc.plivo.com. Eg: If the number you own from your carrier is 18554675486 then the sip address it needs to point to is 18554675486@sbc.plivo.com
264
+ # @param [String] carrier The carrier_id of the IncomingCarrier that the number is associated with. For more information, check our IncomingCarrier API {https://www.plivo.com/docs/api/incomingcarrier/}
265
+ # @param [String] region This is the region that is associated with the Number. You can use it to organize numbers based on the area they are from.
266
+ # @param [Hash] options
267
+ # @option options [String] :number_type This field does not impact the way Plivo uses this number. It is primarily adding more information about your number. You may use this field to categorize between local and tollfree numbers. Default is local.
268
+ # @option options [String] :app_id The application id of the application that is to be linked.
269
+ # @option options [String] :subaccount The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder.
270
+ def add_number(numbers, carrier, region, options = nil)
271
+ valid_param?(:carrier, carrier, [String, Symbol], true)
272
+ valid_param?(:region, region, [String, Symbol], true)
273
+ valid_param?(:numbers, numbers, Array, true)
274
+ numbers.each do |number|
275
+ valid_param?(:number, number, [Integer, String, Symbol], true)
276
+ end
277
+
278
+ params = {
279
+ numbers: numbers.join(','),
280
+ carrier: carrier,
281
+ region: region
282
+ }
283
+
284
+ return perform_post(params) if options.nil?
285
+
286
+ if options.key?(:subaccount) &&
287
+ valid_subaccount?(options[:subaccount], true)
288
+ params[:subaccount] = options[:subaccount]
289
+ end
290
+
291
+ %i[number_type app_id].each do |param|
292
+ if options.key?(param) &&
293
+ valid_param?(param, options[param], [String, Symbol], true)
294
+ params[param] = options[param]
295
+ end
296
+ end
297
+
298
+ perform_post(params)
299
+ end
300
+
301
+ # @param [String] number
302
+ # @param [Hash] options
303
+ # @option options [String] :alias The textual name given to the number.
304
+ # @option options [String] :app_id The application id of the application that is to be linked.
305
+ # @option options [String] :subaccount The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder.
306
+ def update(number, options = nil)
307
+ valid_param?(:number, number, [String, Symbol], true)
308
+ Number.new(@_client,
309
+ resource_id: number).update(options)
310
+ end
311
+
312
+ # @param [String] number
313
+ def delete(number)
314
+ valid_param?(:number, number, [String, Symbol], true)
315
+ Number.new(@_client, resource_id: number).delete
316
+ end
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,64 @@
1
+ module Plivo
2
+ module Resources
3
+ class PhloMember < Base::Resource
4
+ def initialize(client, options)
5
+ @_name = 'member'
6
+ @_identifier_string = 'member_address'
7
+ super
8
+ configure_resource_uri
9
+ end
10
+
11
+ def to_s
12
+ {
13
+ api_id: @api_id,
14
+ node_id: @node_id,
15
+ phlo_id: @phlo_id,
16
+ node_type: @node_type,
17
+ member_address: @member_address,
18
+ created_on: @created_on
19
+ }.to_s
20
+ end
21
+
22
+ def hold
23
+ perform_update({action: 'hold'})
24
+ end
25
+
26
+ def unhold
27
+ perform_update({action: 'unhold'})
28
+ end
29
+
30
+ def voicemail_drop
31
+ perform_update({action: 'voicemail_drop'})
32
+ end
33
+
34
+ def resume_call
35
+ perform_update({action: 'resume_call'})
36
+ end
37
+
38
+ def hangup
39
+ perform_update({action: 'hangup'})
40
+ end
41
+
42
+ # def remove
43
+ # perform_delete
44
+ # end
45
+
46
+ def mute
47
+ perform_update({action: 'mute'})
48
+ end
49
+
50
+ def unmute
51
+ perform_update({action: 'unmute'})
52
+ end
53
+
54
+ def abort_transfer
55
+ perform_update({action: 'abort_transfer'})
56
+ end
57
+
58
+ private
59
+ def configure_resource_uri
60
+ @_resource_uri = ['', 'v1', 'phlo', @phlo_id, @node_type, @node_id, 'members', @id, ''].join('/')
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,55 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+
5
+ class Phlo < Base::Resource
6
+
7
+ def initialize(client, options = nil)
8
+ @_name = 'phlo'
9
+ @_identifier_string = 'phlo_id'
10
+ super
11
+ end
12
+
13
+ def to_s
14
+ {
15
+ api_id: @api_id,
16
+ phlo_id: @phlo_id,
17
+ name: @name,
18
+ created_on: @created_on,
19
+ phlo_run_id: @phlo_run_id
20
+ }.to_s
21
+ end
22
+
23
+ def multi_party_call(node_id)
24
+ nodeInterface = NodeInterface.new(@_client, {_phlo_id: @id})
25
+ nodeInterface.getNode(node_id, 'multi_party_call')
26
+ end
27
+
28
+ # def conference_bridge(node_id)
29
+ # nodeInterface = NodeInterface.new(@_client, {_phlo_id: @id})
30
+ # nodeInterface.getNode(node_id, 'conference_bridge')
31
+ # end
32
+
33
+ def run(params=nil)
34
+ @_resource_uri = ['', 'v1', 'account', @_client.auth_id, @_name, @id, ''].join('/')
35
+ perform_run(params)
36
+ end
37
+ end
38
+
39
+
40
+ class PhloInterface < Base::ResourceInterface
41
+
42
+ def initialize(client, resource_list_json = nil)
43
+ @_name = 'phlo'
44
+ @_resource_type = Phlo
45
+ super
46
+ end
47
+
48
+ def get(phlo_id)
49
+ perform_get(phlo_id)
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end