plivo 4.16.0 → 4.58.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/unitTests.yml +32 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +225 -0
  5. data/Dockerfile +12 -0
  6. data/Gemfile +1 -0
  7. data/Makefile +18 -0
  8. data/README.md +389 -20
  9. data/docker-compose.yml +18 -0
  10. data/examples/tollfree_verification.rb +42 -0
  11. data/lib/plivo/base/resource.rb +30 -0
  12. data/lib/plivo/base/resource_interface.rb +18 -2
  13. data/lib/plivo/base.rb +3 -3
  14. data/lib/plivo/base_client.rb +9 -9
  15. data/lib/plivo/interactive.rb +139 -0
  16. data/lib/plivo/location.rb +22 -0
  17. data/lib/plivo/resources/brand.rb +98 -0
  18. data/lib/plivo/resources/call_feedback.rb +0 -1
  19. data/lib/plivo/resources/calls.rb +183 -29
  20. data/lib/plivo/resources/campaign.rb +168 -0
  21. data/lib/plivo/resources/messages.rb +392 -58
  22. data/lib/plivo/resources/multipartycalls.rb +637 -0
  23. data/lib/plivo/resources/numbers.rb +40 -7
  24. data/lib/plivo/resources/profile.rb +93 -0
  25. data/lib/plivo/resources/recordings.rb +29 -2
  26. data/lib/plivo/resources/token.rb +66 -0
  27. data/lib/plivo/resources/tollfree_verification.rb +178 -0
  28. data/lib/plivo/resources/verify_caller_id.rb +110 -0
  29. data/lib/plivo/resources/verify_session.rb +106 -0
  30. data/lib/plivo/resources.rb +8 -0
  31. data/lib/plivo/rest_client.rb +14 -1
  32. data/lib/plivo/template.rb +102 -0
  33. data/lib/plivo/utils.rb +112 -1
  34. data/lib/plivo/version.rb +1 -1
  35. data/lib/plivo/xml/cont.rb +13 -0
  36. data/lib/plivo/xml/dial.rb +1 -1
  37. data/lib/plivo/xml/element.rb +9 -2
  38. data/lib/plivo/xml/emphasis.rb +1 -1
  39. data/lib/plivo/xml/lang.rb +1 -1
  40. data/lib/plivo/xml/multipartycall.rb +216 -0
  41. data/lib/plivo/xml/p.rb +1 -1
  42. data/lib/plivo/xml/plivo_xml.rb +2 -2
  43. data/lib/plivo/xml/prosody.rb +1 -1
  44. data/lib/plivo/xml/response.rb +1 -1
  45. data/lib/plivo/xml/s.rb +1 -1
  46. data/lib/plivo/xml/speak.rb +1 -1
  47. data/lib/plivo/xml/stream.rb +27 -0
  48. data/lib/plivo/xml/w.rb +1 -1
  49. data/lib/plivo/xml.rb +3 -1
  50. data/plivo.gemspec +1 -2
  51. data/setup_sdk.sh +47 -0
  52. metadata +24 -19
  53. data/.travis.yml +0 -11
@@ -0,0 +1,106 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Session < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'Session'
7
+ @_identifier_string = 'session_uuid'
8
+ super
9
+ end
10
+ def to_s
11
+ {
12
+ api_id: @api_id,
13
+ session_uuid: @session_uuid,
14
+ app_uuid: @app_uuid,
15
+ alias: @alias,
16
+ recipient: @recipient,
17
+ channel: @channel,
18
+ status: @status,
19
+ count: @count,
20
+ requestor_ip: @requestor_ip,
21
+ destination_country_iso2: @destination_country_iso2,
22
+ destination_network: @destination_network,
23
+ attempt_details: @attempt_details,
24
+ charges: @charges,
25
+ created_at: @created_at,
26
+ updated_at: @updated_at
27
+ }.to_s
28
+ end
29
+ end
30
+
31
+ class SessionInterface < Base::ResourceInterface
32
+ def initialize(client, resource_list_json = nil)
33
+ @_name = 'Verify/Session'
34
+ @_resource_type = Session
35
+ @_identifier_string = 'session_uuid'
36
+ super
37
+ end
38
+
39
+ # @param [String] session_uuid
40
+ def get(session_uuid)
41
+ perform_get(session_uuid)
42
+ end
43
+
44
+ def create(app_uuid = nil, recipient = nil,channel = nil,url = nil, method = nil)
45
+ valid_param?(:app_uuid, app_uuid, [String, Symbol], false)
46
+ valid_param?(:recipient, recipient, [Integer, String, Symbol], true)
47
+ valid_param?(:channel, channel, [String, Symbol], false)
48
+ valid_param?(:url, url, [String], false)
49
+ valid_param?(:method, method, String, false, %w[POST GET])
50
+
51
+ params = {
52
+ app_uuid: app_uuid,
53
+ recipient: recipient,
54
+ channel: channel,
55
+ url: url,
56
+ method: method
57
+ }
58
+ perform_create(params)
59
+ end
60
+
61
+ def list(options = nil)
62
+ return perform_list if options.nil?
63
+ valid_param?(:options, options, Hash, true)
64
+ params = {}
65
+ params_expected = %i[
66
+ subaccount status session_time__gt session_time__gte
67
+ session_time__lt session_time__lte session_time country alias app_uuid recipient
68
+ ]
69
+
70
+ params_expected.each do |param|
71
+ if options.key?(param) &&
72
+ valid_param?(param, options[param], [String, Symbol], true)
73
+ params[param] = options[param]
74
+ end
75
+ end
76
+
77
+ %i[offset limit].each do |param|
78
+ if options.key?(param) &&
79
+ valid_param?(param, options[param], [Integer, Integer], true)
80
+ params[param] = options[param]
81
+ end
82
+ end
83
+
84
+ if options.key?(:limit) &&
85
+ (options[:limit] > 20 || options[:limit] <= 0)
86
+ raise_invalid_request('The maximum number of results that can be '\
87
+ "fetched is 20. limit can't be more than 20 or less than 1")
88
+ end
89
+
90
+ raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0
91
+
92
+ perform_list_without_object(params)
93
+ end
94
+
95
+ def validate(session_uuid = nil, otp = nil)
96
+ valid_param?(:session_uuid, session_uuid, [String, Symbol], true)
97
+ valid_param?(:otp, otp, [String], true)
98
+ id = session_uuid
99
+ params = {
100
+ otp: otp
101
+ }
102
+ perform_action_with_identifier(id, 'POST', params)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -7,6 +7,7 @@ require_relative 'resources/pricings'
7
7
  require_relative 'resources/numbers'
8
8
  require_relative 'resources/conferences'
9
9
  require_relative 'resources/calls'
10
+ require_relative 'resources/token'
10
11
  require_relative 'resources/endpoints'
11
12
  require_relative 'resources/addresses'
12
13
  require_relative 'resources/identities'
@@ -15,8 +16,15 @@ require_relative 'resources/nodes'
15
16
  require_relative 'resources/phlo_member'
16
17
  require_relative 'resources/call_feedback'
17
18
  require_relative 'resources/media'
19
+ require_relative 'resources/brand'
20
+ require_relative 'resources/campaign'
21
+ require_relative 'resources/profile'
18
22
  require_relative 'resources/lookup'
19
23
  require_relative 'resources/regulatory_compliance'
24
+ require_relative 'resources/multipartycalls'
25
+ require_relative 'resources/verify_session'
26
+ require_relative 'resources/tollfree_verification'
27
+ require_relative 'resources/verify_caller_id'
20
28
 
21
29
  module Plivo
22
30
  module Resources
@@ -8,14 +8,19 @@ module Plivo
8
8
  # Resources
9
9
  attr_reader :messages, :account, :subaccounts, :recordings
10
10
  attr_reader :pricings, :numbers, :calls, :conferences
11
- attr_reader :phone_numbers, :applications, :endpoints
11
+ attr_reader :token
12
+ attr_reader :phone_numbers, :applications, :endpoints, :multipartycalls
12
13
  attr_reader :addresses, :identities
13
14
  attr_reader :call_feedback
14
15
  attr_reader :powerpacks
15
16
  attr_reader :powerpacks, :media
16
17
  attr_reader :lookup
18
+ attr_reader :brand, :campaign, :profile
17
19
  attr_reader :end_users
18
20
  attr_reader :compliance_document_types, :compliance_documents, :compliance_requirements, :compliance_applications
21
+ attr_reader :verify_session
22
+ attr_reader :tollfree_verifications
23
+ attr_reader :verify_caller_id
19
24
 
20
25
  def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5)
21
26
  configure_base_uri
@@ -39,6 +44,9 @@ module Plivo
39
44
  @messages = Resources::MessagesInterface.new(self)
40
45
  @powerpacks = Resources::PowerpackInterface.new(self)
41
46
  @media = Resources::MediaInterface.new(self)
47
+ @brand = Resources::BrandInterface.new(self)
48
+ @campaign = Resources::CampaignInterface.new(self)
49
+ @profile = Resources::ProfileInterface.new(self)
42
50
  @subaccounts = Resources::SubaccountInterface.new(self)
43
51
  @recordings = Resources::RecordingInterface.new(self)
44
52
  @pricings = Resources::PricingInterface.new(self)
@@ -46,17 +54,22 @@ module Plivo
46
54
  @phone_numbers = Resources::PhoneNumberInterface.new(self)
47
55
  @conferences = Resources::ConferenceInterface.new(self)
48
56
  @calls = Resources::CallInterface.new(self)
57
+ @token = Resources::TokenInterface.new(self)
49
58
  @endpoints = Resources::EndpointInterface.new(self)
50
59
  @applications = Resources::ApplicationInterface.new(self)
51
60
  @addresses = Resources::AddressInterface.new(self)
52
61
  @identities = Resources::IdentityInterface.new(self)
53
62
  @call_feedback = Resources::CallFeedbackInterface.new(self)
63
+ @multipartycalls = Resources::MultiPartyCallInterface.new( self)
54
64
  @lookup = Resources::LookupInterface.new(self)
55
65
  @end_users = Resources::EndUsersInterface.new(self)
56
66
  @compliance_document_types = Resources::ComplianceDocumentTypesInterface.new(self)
57
67
  @compliance_documents = Resources::ComplianceDocumentsInterface.new(self)
58
68
  @compliance_requirements = Resources::ComplianceRequirementsInterface.new(self)
59
69
  @compliance_applications = Resources::ComplianceApplicationsInterface.new(self)
70
+ @verify_session = Resources::SessionInterface.new(self)
71
+ @tollfree_verifications = Resources::TollfreeVerificationsInterface.new(self)
72
+ @verify_caller_id = Resources::VerifyCallerIdInterface.new(self)
60
73
  end
61
74
  end
62
75
  end
@@ -0,0 +1,102 @@
1
+ require_relative "resources"
2
+ require_relative "base_client"
3
+ require_relative "base"
4
+ require_relative "location"
5
+ module Plivo
6
+ class Template
7
+ attr_accessor :name, :language, :components
8
+
9
+ def initialize(name: nil, language: nil, components: nil)
10
+ @name = name
11
+ @language = language
12
+ @components = components
13
+ end
14
+
15
+ def to_hash
16
+ {
17
+ name: @name,
18
+ language: @language,
19
+ components: @components&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
20
+ }.reject { |_, v| v.nil? }
21
+ end
22
+ end
23
+
24
+ class Component
25
+ attr_accessor :type, :sub_type, :index, :parameters
26
+
27
+ def initialize(type: nil, sub_type: nil, index: nil, parameters: nil)
28
+ @type = type
29
+ @sub_type = sub_type
30
+ @index = index
31
+ @parameters = parameters
32
+ end
33
+
34
+ def to_hash
35
+ {
36
+ type: @type,
37
+ sub_type: @sub_type,
38
+ index: @index,
39
+ parameters: @parameters&.map(&:to_hash)&.reject { |h| h.values.all?(&:nil?) }
40
+ }.reject { |_, v| v.nil? }
41
+ end
42
+ end
43
+
44
+ class Parameter
45
+ attr_accessor :type, :text, :media, :payload, :currency, :date_time, :location
46
+
47
+ def initialize(type: nil, text: nil, media: nil, payload: nil, currency: nil, date_time: nil, location: nil)
48
+ @type = type
49
+ @text = text
50
+ @media = media
51
+ @payload = payload
52
+ @currency = currency
53
+ @date_time = date_time
54
+ @location = location
55
+ end
56
+
57
+ def to_hash
58
+ {
59
+ type: @type,
60
+ text: @text,
61
+ media: @media,
62
+ payload: @payload,
63
+ currency: @currency&.to_hash,
64
+ date_time: @date_time&.to_hash,
65
+ location: @location&.to_hash
66
+ }.reject { |_, v| v.nil? }
67
+ end
68
+ end
69
+
70
+ class Currency
71
+ attr_accessor :fallback_value, :currency_code, :amount_1000
72
+
73
+ def initialize(fallback_value: nil, currency_code: nil, amount_1000: nil)
74
+ @fallback_value = fallback_value
75
+ @currency_code = currency_code
76
+ @amount_1000 = amount_1000
77
+ end
78
+
79
+ def to_hash
80
+ {
81
+ fallback_value: @fallback_value,
82
+ currency_code: @currency_code,
83
+ amount_1000: @amount_1000
84
+ }.reject { |_, v| v.nil? }
85
+ end
86
+ end
87
+
88
+ class DateTime
89
+ attr_accessor :fallback_value
90
+
91
+ def initialize(fallback_value: nil)
92
+ @fallback_value = fallback_value
93
+ end
94
+
95
+ def to_hash
96
+ {
97
+ fallback_value: @fallback_value
98
+ }.reject { |_, v| v.nil? }
99
+ end
100
+ end
101
+ end
102
+
data/lib/plivo/utils.rb CHANGED
@@ -67,6 +67,117 @@ module Plivo
67
67
  expected_value?(param_name, expected_values, param_value)
68
68
  end
69
69
 
70
+ def valid_multiple_destination_nos?(param_name, param_value, options = nil)
71
+ if param_value.split(options[:delimiter]).size > 1 && options[:role].downcase != 'agent'
72
+ raise_invalid_request("Multiple #{param_name} values given for role #{options[:role]}")
73
+ elsif param_value.split(options[:delimiter]).size >= options[:agent_limit]
74
+ raise_invalid_request("No of #{param_name} values provided should be lesser than #{options[:agent_limit]}")
75
+ else
76
+ return true
77
+ end
78
+ end
79
+
80
+ def valid_multiple_destination_integers?(param_name, param_value)
81
+ if (param_value.is_a? String)
82
+ values = param_value.split("<")
83
+ for i in values
84
+ unless (Integer(i) rescue false)
85
+ raise_invalid_request("#{param_name} Destination Value must be integer")
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def valid_url?(param_name, param_value, mandatory = false)
92
+ if mandatory && param_value.nil?
93
+ raise_invalid_request("#{param_name} is a required parameter")
94
+ end
95
+
96
+ return true if param_value.nil?
97
+ return raise_invalid_request("#{param_name}: Expected a String but received #{param_value.class} instead") unless expected_type?(param_name, String, param_value)
98
+
99
+ if param_value =~ /^(http[s]?:\/\/([a-zA-Z]|[0-9]|[\$\-\_\@\.\&\+\/\#]|[\!\*\(\)\,]|(%[0-9a-fA-F][0-9a-fA-F]))+|nil)$/ix
100
+ return true
101
+ else
102
+ return raise_invalid_request("Invalid URL : Doesn't satisfy the URL format")
103
+ end
104
+ end
105
+
106
+ def valid_range?(param_name, param_value, mandatory = false, lower_bound = nil, upper_bound = nil)
107
+ if mandatory && param_value.nil?
108
+ raise_invalid_request("#{param_name} is a required parameter")
109
+ end
110
+
111
+ return true if param_value.nil?
112
+
113
+ return raise_invalid_request("#{param_name}: Expected an Integer but received #{param_value.class} instead") unless expected_type?(param_name, Integer, param_value)
114
+ if lower_bound && upper_bound
115
+ return raise_invalid_request("#{param_name} ranges between #{lower_bound} and #{upper_bound}") if param_value < lower_bound or param_value > upper_bound
116
+
117
+ return true if param_value >= lower_bound and param_value <= upper_bound
118
+ elsif lower_bound
119
+ return raise_invalid_request("#{param_name} should be greater than #{lower_bound}") if param_value < lower_bound
120
+
121
+ return true if param_value >= lower_bound
122
+ elsif upper_bound
123
+ return raise_invalid_request("#{param_name} should be lesser than #{upper_bound}") if param_value > upper_bound
124
+
125
+ return true if param_value <= upper_bound
126
+ else
127
+ return raise_invalid_request("Any one or both of lower and upper bound should be provided")
128
+ end
129
+ end
130
+
131
+ def multi_valid_param?(param_name, param_value, expected_types = nil, mandatory = false, expected_values = nil, make_down_case = false, seperator = ',')
132
+ if mandatory && param_value.nil?
133
+ raise_invalid_request("#{param_name} is a required parameter")
134
+ end
135
+
136
+ return true if param_value.nil?
137
+
138
+ if make_down_case
139
+ param_value = param_value.downcase
140
+ else
141
+ param_value = param_value.uppercase
142
+ end
143
+
144
+ for val in param_value.split(seperator)
145
+ return expected_type?(param_name, expected_types, val.strip) unless expected_values
146
+ expected_value?(param_name, expected_values, val.strip)
147
+ end
148
+ end
149
+
150
+ def valid_date_format?(param_name, param_value, mandatory = false)
151
+ if mandatory && param_value.nil?
152
+ raise_invalid_request("#{param_name} is a required parameter")
153
+ end
154
+
155
+ return true if param_value.nil?
156
+
157
+ if param_value =~ /^(\d{4}\-\d{2}\-\d{2}\ \d{2}\:\d{2}(\:\d{2}(\.\d{1,6})?)?)$/ix
158
+ return true
159
+ else
160
+ return raise_invalid_request("Invalid Date Format")
161
+ end
162
+ end
163
+
164
+ def is_one_among_string_url?(param_name, param_value, mandatory = false, expected_values= nil)
165
+ if mandatory && param_value.nil?
166
+ raise_invalid_request("#{param_name} is a required parameter")
167
+ end
168
+
169
+ return true if param_value.nil?
170
+ return raise_invalid_request("#{param_name}: Expected a String but received #{param_value.class} instead") unless expected_type?(param_name, String, param_value)
171
+
172
+ if expected_values.include? param_value.downcase or expected_values.include? param_value.upcase
173
+ return true
174
+ elsif valid_url?(param_name, param_value)
175
+ return true
176
+ else
177
+ raise_invalid_request("#{param_name} neither a valid URL nor in the expected values")
178
+ end
179
+ end
180
+
70
181
  def expected_type?(param_name, expected_types, param_value)
71
182
  return true if expected_types.nil?
72
183
  param_value_class = param_value.class
@@ -116,7 +227,7 @@ module Plivo
116
227
  uri += "?"
117
228
  end
118
229
  if parsed_uri.query.to_s.length > 0
119
- parsed_uri_query = URI.decode(parsed_uri.query)
230
+ parsed_uri_query = URI.decode_www_form_component(parsed_uri.query)
120
231
  if method == "GET"
121
232
  queryParamMap = getMapFromQueryString?(parsed_uri_query)
122
233
  params.keys.sort.each { |key|
data/lib/plivo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = "4.16.0".freeze
2
+ VERSION = "4.58.0".freeze
3
3
  end
@@ -0,0 +1,13 @@
1
+ module Plivo
2
+ module XML
3
+ class Cont < Element
4
+ @nestables = []
5
+ @valid_attributes = []
6
+
7
+ def initialize(body)
8
+ super(body)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -3,7 +3,7 @@ module Plivo
3
3
  class Dial < Element
4
4
  @nestables = %w[Number User]
5
5
  @valid_attributes = %w[action method timeout hangupOnStar
6
- timeLimit callerId callerName confirmSound
6
+ timeLimit callerId callerName confirmSound confirmTimeout
7
7
  dialMusic confirmKey redirect
8
8
  callbackUrl callbackMethod digitsMatch digitsMatchBLeg
9
9
  sipHeaders]
@@ -80,8 +80,15 @@ module Plivo
80
80
  def add(element)
81
81
  raise PlivoXMLError, 'invalid element' unless element
82
82
  if @nestables.include?(element.name)
83
- @node.elements << element.node
84
- element
83
+ if element.name == "Cont"
84
+ @node.elements << element.node
85
+ element
86
+ temp = REXML::Text.new element.node.text
87
+ @node.elements['Cont'] = temp
88
+ else
89
+ @node.elements << element.node
90
+ element
91
+ end
85
92
  else
86
93
  raise PlivoXMLError, "#{element.name} not nestable in #{@name}"
87
94
  end
@@ -1,7 +1,7 @@
1
1
  module Plivo
2
2
  module XML
3
3
  class Emphasis < Element
4
- @nestables = %w(Break Emphasis Lang Phoneme Prosody SayAs Sub W)
4
+ @nestables = %w(Break Cont Emphasis Lang Phoneme Prosody SayAs Sub W)
5
5
  @valid_attributes = %w(level)
6
6
 
7
7
  VALID_LEVEL_ATTRIBUTE_VALUE=%w(strong moderate reduced)
@@ -1,7 +1,7 @@
1
1
  module Plivo
2
2
  module XML
3
3
  class Lang < Element
4
- @nestables = %w(Break Emphasis Lang P Phoneme Prosody S SayAs Sub W)
4
+ @nestables = %w(Break Cont Emphasis Lang P Phoneme Prosody S SayAs Sub W)
5
5
  @valid_attributes = %w(xmllang)
6
6
 
7
7
  VALID_LANG_ATTRIBUTE_VALUES = [