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,258 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Application < Base::Resource
5
+
6
+
7
+ def initialize(client, options = nil)
8
+ @_name = 'Application'
9
+ @_identifier_string = 'app_id'
10
+ super
11
+ @_is_voice_request = true
12
+ end
13
+
14
+ # @param [Hash] options
15
+ # @option options [String] :answer_url - The URL invoked by Plivo when a call executes this application.
16
+ # @option options [String] :answer_method - The method used to call the answer_url. Defaults to POST.
17
+ # @option options [String] :hangup_url - The URL that will be notified by Plivo when the call hangs up. Defaults to answer_url.
18
+ # @option options [String] :hangup_method - The method used to call the hangup_url. Defaults to POST.
19
+ # @option options [String] :fallback_answer_url - Invoked by Plivo only if answer_url is unavailable or the XML response is invalid. Should contain a XML response.
20
+ # @option options [String] :fallback_method - The method used to call the fallback_answer_url. Defaults to POST.
21
+ # @option options [String] :message_url - The URL that will be notified by Plivo when an inbound message is received. Defaults not set.
22
+ # @option options [String] :message_method - The method used to call the message_url. Defaults to POST.
23
+ # @option options [Boolean] :default_number_app - If set to true, this parameter ensures that newly created numbers, which don't have an app_id, point to this application.
24
+ # @option options [Boolean] :default_endpoint_app - If set to true, this parameter ensures that newly created endpoints, which don't have an app_id, point to this application.
25
+ # @option options [String] :subaccount - Id of the subaccount, in case only subaccount applications are needed.
26
+ # @option options [Boolean] :log_incoming_messages - If set to true, this parameter ensures that incoming messages are logged.
27
+ # @option options [Boolean] :public_uri - If set to true, this parameter enables public_uri.
28
+ # @return [Application] Application
29
+ def update(options = nil)
30
+ return perform_update({}) if options.nil?
31
+
32
+ valid_param?(:options, options, Hash, true)
33
+
34
+ params = {}
35
+
36
+ %i[answer_url hangup_url fallback_answer_url message_url subaccount]
37
+ .each do |param|
38
+ if options.key?(param) &&
39
+ valid_param?(param, options[param], [String, Symbol], true)
40
+ params[param] = options[param]
41
+ end
42
+ end
43
+
44
+ %i[answer_method hangup_method fallback_method message_method]
45
+ .each do |param|
46
+ if options.key?(param) &&
47
+ valid_param?(param, options[param], [String, Symbol], true, %w[GET POST])
48
+ params[param] = options[param]
49
+ end
50
+ end
51
+
52
+ %i[default_number_app default_endpoint_app log_incoming_messages public_uri].each do |param|
53
+ if options.key?(param) &&
54
+ valid_param?(param, options[param], [TrueClass, FalseClass], true)
55
+ params[param] = options[param]
56
+ end
57
+ end
58
+
59
+ perform_update(params)
60
+ end
61
+
62
+ # @param [Hash] options
63
+ # @option options [Boolean] :cascade - delete associated endpoints
64
+ # @option options [String] :new_endpoint_application - Link associated endpoints to this app
65
+ def delete(options = nil)
66
+ return perform_delete if options.nil?
67
+ params = {}
68
+
69
+ if options.key?(:cascade) && valid_param?(:cascade, options[:cascade], [TrueClass, FalseClass], false, [true, false])
70
+ params[:cascade] = options[:cascade]
71
+ end
72
+
73
+ if options.key?(:new_endpoint_application) && valid_param?(:new_endpoint_application, options[:new_endpoint_application], [String, Symbol])
74
+ params[:new_endpoint_application] = options[:new_endpoint_application]
75
+ end
76
+
77
+ perform_delete(params)
78
+ end
79
+
80
+ def to_s
81
+ {
82
+ answer_method: @answer_method,
83
+ answer_url: @answer_url,
84
+ app_id: @app_id,
85
+ api_id: @api_id,
86
+ app_name: @app_name,
87
+ default_app: @default_app,
88
+ default_endpoint_app: @default_endpoint_app,
89
+ enabled: @enabled,
90
+ fallback_answer_url: @fallback_answer_url,
91
+ fallback_method: @fallback_method,
92
+ hangup_method: @hangup_method,
93
+ hangup_url: @hangup_url,
94
+ message_method: @message_method,
95
+ message_url: @message_url,
96
+ public_uri: @public_uri,
97
+ resource_uri: @resource_uri,
98
+ sip_uri: @sip_uri,
99
+ sub_account: @sub_account,
100
+ log_incoming_messages: @log_incoming_messages
101
+ }.to_s
102
+ end
103
+ end
104
+
105
+ # @!method get
106
+ # @!method create
107
+ # @!method list
108
+ class ApplicationInterface < Base::ResourceInterface
109
+ def initialize(client, resource_list_json = nil)
110
+ @_name = 'Application'
111
+ @_resource_type = Application
112
+ @_identifier_string = 'app_id'
113
+ super
114
+ @_is_voice_request = true
115
+ end
116
+
117
+ # @param [String] app_id
118
+ # @return [Application] Application
119
+ def get(app_id)
120
+ valid_param?(:app_id, app_id, [String, Symbol], true)
121
+ perform_get(app_id)
122
+ end
123
+
124
+ # @param [String] app_name
125
+ # @param [Hash] options
126
+ # @option options [String] :answer_url - The URL invoked by Plivo when a call executes this application.
127
+ # @option options [String] :answer_method - The method used to call the answer_url. Defaults to POST.
128
+ # @option options [String] :hangup_url - The URL that will be notified by Plivo when the call hangs up. Defaults to answer_url.
129
+ # @option options [String] :hangup_method - The method used to call the hangup_url. Defaults to POST.
130
+ # @option options [String] :fallback_answer_url - Invoked by Plivo only if answer_url is unavailable or the XML response is invalid. Should contain a XML response.
131
+ # @option options [String] :fallback_method - The method used to call the fallback_answer_url. Defaults to POST.
132
+ # @option options [String] :message_url - The URL that will be notified by Plivo when an inbound message is received. Defaults not set.
133
+ # @option options [String] :message_method - The method used to call the message_url. Defaults to POST.
134
+ # @option options [Boolean] :default_number_app - If set to true, this parameter ensures that newly created numbers, which don't have an app_id, point to this application.
135
+ # @option options [Boolean] :default_endpoint_app - If set to true, this parameter ensures that newly created endpoints, which don't have an app_id, point to this application.
136
+ # @option options [String] :subaccount - Id of the subaccount, in case only subaccount applications are needed.
137
+ # @option options [Boolean] :log_incoming_messages - If set to true, this parameter ensures that incoming messages are logged.
138
+ # @option options [Boolean] :public_uri - If set to true, this parameter enables public_uri.
139
+ # @return [Application] Application
140
+ def create(app_name, options = nil)
141
+ valid_param?(:app_name, app_name, [String, Symbol], true)
142
+ valid_param?(:options, options, Hash, true) unless options.nil?
143
+
144
+ params = {
145
+ app_name: app_name
146
+ }
147
+
148
+ return perform_create(params) if options.nil?
149
+
150
+ %i[answer_url hangup_url fallback_answer_url message_url subaccount]
151
+ .each do |param|
152
+ if options.key?(param) &&
153
+ valid_param?(param, options[param], [String, Symbol], true)
154
+ params[param] = options[param]
155
+ end
156
+ end
157
+
158
+ %i[answer_method hangup_method fallback_method message_method]
159
+ .each do |param|
160
+ if options.key?(param) &&
161
+ valid_param?(param, options[param], [String, Symbol], true, %w[GET POST])
162
+ params[param] = options[param]
163
+ end
164
+ end
165
+
166
+ %i[default_number_app default_endpoint_app log_incoming_messages public_uri].each do |param|
167
+ if options.key?(param) &&
168
+ valid_param?(param, options[param], [TrueClass, FalseClass], true)
169
+ params[param] = options[param]
170
+ end
171
+ end
172
+
173
+ perform_create(params)
174
+ end
175
+
176
+ ##
177
+ # Lists all applications
178
+ # @param [Hash] options
179
+ # @option options [String] :subaccount
180
+ # @option options [Int] :offset
181
+ # @option options [Int] :limit
182
+ # @return [Hash]
183
+ def list(options = nil)
184
+ return perform_list if options.nil?
185
+
186
+ params = {}
187
+
188
+ if options.key?(:subaccount) &&
189
+ valid_param?(:subaccount, options[:subaccount], [String, Symbol], true)
190
+ params[:subaccount] = options[:subaccount]
191
+ end
192
+
193
+ %i[offset limit].each do |param|
194
+ if options.key?(param) && valid_param?(param, options[param],
195
+ [Integer, Integer], true)
196
+ params[param] = options[param]
197
+ end
198
+ end
199
+
200
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
201
+ raise_invalid_request('The maximum number of results that can be '\
202
+ "fetched is 20. limit can't be more than 20 or less than 1")
203
+ end
204
+
205
+ if options.key?(:offset) && options[:offset] < 0
206
+ raise_invalid_request("Offset can't be negative")
207
+ end
208
+
209
+ perform_list(params)
210
+ end
211
+
212
+ def each
213
+ offset = 0
214
+ loop do
215
+ app_list = list(offset: offset)
216
+ app_list[:objects].each { |app| yield app }
217
+ offset += 20
218
+ return unless app_list.length == 20
219
+ end
220
+ end
221
+
222
+ ##
223
+ # Modify an application
224
+ # @param [String] app_id
225
+ # @param [Hash] options
226
+ # @option options [String] :answer_url - The URL invoked by Plivo when a call executes this application.
227
+ # @option options [String] :answer_method - The method used to call the answer_url. Defaults to POST.
228
+ # @option options [String] :hangup_url - The URL that will be notified by Plivo when the call hangs up. Defaults to answer_url.
229
+ # @option options [String] :hangup_method - The method used to call the hangup_url. Defaults to POST.
230
+ # @option options [String] :fallback_answer_url - Invoked by Plivo only if answer_url is unavailable or the XML response is invalid. Should contain a XML response.
231
+ # @option options [String] :fallback_method - The method used to call the fallback_answer_url. Defaults to POST.
232
+ # @option options [String] :message_url - The URL that will be notified by Plivo when an inbound message is received. Defaults not set.
233
+ # @option options [String] :message_method - The method used to call the message_url. Defaults to POST.
234
+ # @option options [Boolean] :default_number_app - If set to true, this parameter ensures that newly created numbers, which don't have an app_id, point to this application.
235
+ # @option options [Boolean] :default_endpoint_app - If set to true, this parameter ensures that newly created endpoints, which don't have an app_id, point to this application.
236
+ # @option options [String] :subaccount - Id of the subaccount, in case only subaccount applications are needed.
237
+ # @option options [Boolean] :log_incoming_messages - If set to true, this parameter ensures that incoming messages are logged.
238
+ # @return [Application] Application
239
+ def update(app_id, options = nil)
240
+ valid_param?(:app_id, app_id, [String, Symbol], true)
241
+ Application.new(@_client,
242
+ resource_id: app_id).update(options)
243
+ end
244
+
245
+ ##
246
+ # Delete an application
247
+ # @param [String] app_id
248
+ # @param [Hash] options
249
+ # @option options [Boolean] :cascade - delete associated endpoints
250
+ # @option options [String] :new_endpoint_application - Link associated endpoints to this app
251
+ def delete(app_id, options = nil)
252
+ valid_param?(:app_id, app_id, [String, Symbol], true)
253
+ Application.new(@_client,
254
+ resource_id: app_id).delete(options)
255
+ end
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,55 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Plivo
6
+ module Resources
7
+ include Plivo::Utils
8
+ class CallFeedback < Base::Resource
9
+ def initialize(client, options = nil)
10
+ @_name = 'Call'
11
+ super
12
+ end
13
+ end
14
+
15
+ class CallFeedbackInterface < Base::ResourceInterface
16
+ FEEDBACK_API_PATH = "v1/Call/%s/Feedback/"
17
+ def initialize(client, resource_list_json = nil)
18
+ @_name = 'Call'
19
+ @_resource_type = CallFeedback
20
+ super
21
+ end
22
+
23
+ def create(call_uuid, rating, issues = [], notes = "")
24
+
25
+ valid_param?(:call_uuid, call_uuid, String, true)
26
+ valid_param?(:rating, rating, [Integer, Float], true)
27
+
28
+ if call_uuid == ""
29
+ raise_invalid_request("call_uuid cannot be empty")
30
+ end
31
+
32
+ if rating < 1 or rating > 5
33
+ raise_invalid_request("Rating has to be a float between 1 - 5")
34
+ end
35
+
36
+ params = {
37
+ rating: rating,
38
+ }
39
+
40
+ if issues.length() > 0
41
+ params['issues'] = issues
42
+ end
43
+
44
+ if notes.length > 0
45
+ params['notes'] = notes
46
+ end
47
+
48
+ params['is_callinsights_request'] = true
49
+ params['request_url'] = FEEDBACK_API_PATH % call_uuid
50
+
51
+ return perform_post(params)
52
+ end
53
+ end
54
+ end
55
+ end