plivo 4.9.1 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90c29ef8eb386d2fd0827d9992f71f5687732ff0
4
- data.tar.gz: 59b0f04856438b16248892b4f2ddbd9e79a442fe
3
+ metadata.gz: d641350610110aad6f806863f07423c6d00c25cc
4
+ data.tar.gz: 575c20c51371033efd51c06d9005bc465ea59502
5
5
  SHA512:
6
- metadata.gz: fb16f471f5d7e52b7a5c982c6a7ab534a1a18aaebc9458be1e1f523d429584dc19a964a58cd66b3ef243307ddc2af79792c9fc9ab28dde526111e9658e3432e3
7
- data.tar.gz: 332d920da3e1ee487a453af4b29051b16a58a6d3c33f4a54ccc58d9d46155cdac71f607412c0899ecf5f5cafb98cc6d8e251defc1a4f24110dc6741a79d865ef
6
+ metadata.gz: 837eec078ee00718c11d4c0ac9dd96a238d017289fb648aed9b9045373afe166f56be1eccea3d65b10d8c8276ba3a3e774682373ef4c9be6940a77dc566104db
7
+ data.tar.gz: 7762e64e47c88778486e5bb584aae0af7fc6ec8d1cdc1ad2025dfb9e778eb4a2d54ba0c9a57a896cf967d54ab46aac7c81b6a5364b1785708e040c894c8bc1da
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.14.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.14.0) (2020-10-30)
4
+ - Change lookup API endpoint and response.
5
+
6
+ ## [4.13.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.13.0) (2020-09-30)
7
+ - Add support for Lookup API
8
+
9
+ ## [4.12.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.12.0) (2020-09-24)
10
+ - Add "public_uri" optional param support for Application API.
11
+
12
+ ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.11.0) (2020-08-25)
13
+ - Add Powerpack for mms
14
+
15
+ ## [4.10.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.10.0) (2020-09-04)
16
+ - Add ConferenceUuid & CallState for Get Details of a Call API
17
+ - Upgrade faraday & faraday_middleware dependencies
18
+
3
19
  ## [4.9.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.9.1) (2020-08-19)
4
20
  - Internal changes in Phlo for MultiPartyCall component
5
21
 
data/README.md CHANGED
@@ -8,7 +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
- gem 'plivo', '>= 4.9.1'
11
+ gem 'plivo', '>= 4.14.0'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -105,6 +105,18 @@ call_made = client.calls.create(
105
105
  )
106
106
  ```
107
107
 
108
+ ### Lookup a number
109
+
110
+ ```ruby
111
+ require 'rubygems'
112
+ require 'plivo'
113
+
114
+ include Plivo
115
+
116
+ client = RestClient.new
117
+ resp = client.lookup.get('<number-here>')
118
+ ```
119
+
108
120
  ### Generate Plivo XML
109
121
 
110
122
  ```ruby
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "plivo"
3
+
4
+ include Plivo
5
+ include Plivo::Exceptions
6
+
7
+ AUTH_ID = ""
8
+ AUTH_TOKEN = ""
9
+
10
+ client = RestClient.new(AUTH_ID, AUTH_TOKEN)
11
+
12
+ # if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
13
+ # then initialize client as:
14
+ # client = RestClient.new
15
+
16
+ begin
17
+ resp = client.lookup.get(
18
+ "<insert-number-here>",
19
+ "carrier"
20
+ )
21
+ puts resp
22
+ rescue PlivoRESTError => e
23
+ puts "Exception: " + e.message
24
+ end
@@ -12,5 +12,6 @@ module Plivo
12
12
 
13
13
  CALLINSIGHTS_API_URL = 'https://stats.plivo.com'.freeze
14
14
  PHLO_API_URL = 'https://phlorunner.plivo.com'.freeze
15
+ LOOKUP_API_URL = 'https://lookup.plivo.com'.freeze
15
16
  end
16
17
  end
@@ -61,7 +61,12 @@ module Plivo
61
61
  else
62
62
  process_response(method, response.to_hash)
63
63
  end
64
-
64
+ elsif options[:is_lookup_request] == true
65
+ response = case method
66
+ when 'GET' then send_get(resource_path, data, timeout, is_lookup_request: options[:is_lookup_request])
67
+ else raise_invalid_request("#{method} not supported by Plivo, yet")
68
+ end
69
+ process_response(method, response.to_hash)
65
70
  else
66
71
  response = case method
67
72
  when 'GET' then send_get(resource_path, data, timeout)
@@ -191,6 +196,18 @@ module Plivo
191
196
  faraday.adapter Faraday.default_adapter
192
197
  end
193
198
 
199
+ @lookup_conn = Faraday.new(@lookup_base_uri) do |faraday|
200
+ faraday.headers = @headers
201
+
202
+ # DANGER: Basic auth should always come after headers, else
203
+ # The headers will replace the basic_auth
204
+
205
+ faraday.basic_auth(auth_id, auth_token)
206
+
207
+ faraday.proxy=@proxy_hash if @proxy_hash
208
+ faraday.response :json, content_type: /\bjson$/
209
+ faraday.adapter Faraday.default_adapter
210
+ end
194
211
  end
195
212
 
196
213
  def send_get(resource_path, data, timeout, options = nil)
@@ -210,6 +227,11 @@ module Plivo
210
227
  req.url resource_path, data
211
228
  req.options.timeout = timeout if timeout
212
229
  end
230
+ elsif options[:is_lookup_request] == true
231
+ response = @lookup_conn.get do |req|
232
+ req.url resource_path, data
233
+ req.options.timeout = timeout if timeout
234
+ end
213
235
  end
214
236
  else
215
237
  response = @conn.get do |req|
@@ -15,6 +15,7 @@ require_relative 'resources/nodes'
15
15
  require_relative 'resources/phlo_member'
16
16
  require_relative 'resources/call_feedback'
17
17
  require_relative 'resources/media'
18
+ require_relative 'resources/lookup'
18
19
 
19
20
  module Plivo
20
21
  module Resources
@@ -24,6 +24,7 @@ module Plivo
24
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
25
  # @option options [String] :subaccount - Id of the subaccount, in case only subaccount applications are needed.
26
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.
27
28
  # @return [Application] Application
28
29
  def update(options = nil)
29
30
  return perform_update({}) if options.nil?
@@ -48,7 +49,7 @@ module Plivo
48
49
  end
49
50
  end
50
51
 
51
- %i[default_number_app default_endpoint_app log_incoming_messages].each do |param|
52
+ %i[default_number_app default_endpoint_app log_incoming_messages public_uri].each do |param|
52
53
  if options.key?(param) &&
53
54
  valid_param?(param, options[param], [TrueClass, FalseClass], true)
54
55
  params[param] = options[param]
@@ -134,6 +135,7 @@ module Plivo
134
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.
135
136
  # @option options [String] :subaccount - Id of the subaccount, in case only subaccount applications are needed.
136
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.
137
139
  # @return [Application] Application
138
140
  def create(app_name, options = nil)
139
141
  valid_param?(:app_name, app_name, [String, Symbol], true)
@@ -161,7 +163,7 @@ module Plivo
161
163
  end
162
164
  end
163
165
 
164
- %i[default_number_app default_endpoint_app log_incoming_messages].each do |param|
166
+ %i[default_number_app default_endpoint_app log_incoming_messages public_uri].each do |param|
165
167
  if options.key?(param) &&
166
168
  valid_param?(param, options[param], [TrueClass, FalseClass], true)
167
169
  params[param] = options[param]
@@ -212,7 +212,9 @@ module Plivo
212
212
  call_direction: @call_direction,
213
213
  call_duration: @call_duration,
214
214
  call_status: @call_status,
215
+ call_state: @call_state,
215
216
  call_uuid: @call_uuid,
217
+ conference_uuid: @conference_uuid,
216
218
  end_time: @end_time,
217
219
  from_number: @from_number,
218
220
  initiation_time: @initiation_time,
@@ -399,7 +401,7 @@ module Plivo
399
401
  # - To filter out those numbers that contain a particular number sequence, use to_number={ sequence}
400
402
  # - To filter out a number that matches an exact number, use to_number={ exact_number}
401
403
  def list_live(options = nil)
402
-
404
+
403
405
  if options.nil?
404
406
  options = {}
405
407
  else
@@ -0,0 +1,88 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+
5
+ class LookupBaseResource
6
+ def initialize(fields = nil)
7
+ valid_param?(:fields, fields, Hash, false)
8
+ fields.each do |k, v|
9
+ instance_variable_set("@#{k}", v)
10
+ self.class.send(:attr_reader, k)
11
+ end
12
+ end
13
+
14
+ def to_s
15
+ hash = {}
16
+ instance_variables.each { |var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
17
+ hash.to_s
18
+ end
19
+ end
20
+
21
+ class Country < LookupBaseResource
22
+ end
23
+
24
+ class NumberFormat < LookupBaseResource
25
+ end
26
+
27
+ class Carrier < LookupBaseResource
28
+ end
29
+
30
+ # Not subclassing from Base::Resource because it cannot set nested
31
+ # attributes. Named the class 'LookupResponse' because the name
32
+ # 'Number' is already taken.
33
+ class LookupResponse < LookupBaseResource
34
+ def initialize(client, options = nil)
35
+ # there is no use for client here
36
+ valid_param?(:options, options, Hash, false)
37
+ parse_and_set(options[:resource_json]) if options.key?(:resource_json)
38
+ end
39
+
40
+ def parse_and_set(resp)
41
+ return unless resp
42
+ valid_param?(:resp, resp, Hash, true)
43
+
44
+ resp.each do |k, v|
45
+ case k
46
+ when "country"
47
+ instance_variable_set("@#{k}", Country.new(v))
48
+ when "format"
49
+ instance_variable_set("@#{k}", NumberFormat.new(v))
50
+ when "carrier"
51
+ instance_variable_set("@#{k}", Carrier.new(v))
52
+ else
53
+ instance_variable_set("@#{k}", v)
54
+ end
55
+ self.class.send(:attr_reader, k)
56
+ end
57
+ end
58
+ end
59
+
60
+ class LookupInterface < Base::ResourceInterface
61
+ def initialize(client, resource_list_json = nil)
62
+ @_resource_type = LookupResponse
63
+ @_identifier_string = "phone_number"
64
+ super
65
+ # Override _resource_uri only after calling super
66
+ @_resource_uri = "/v1/Number/"
67
+ end
68
+
69
+ ##
70
+ # Lookup a number
71
+ # @param [String] number
72
+ # @return [LookupResponse] LookupResponse
73
+ def get(number, type = "carrier")
74
+ valid_param?(:number, number, [String, Symbol], true)
75
+ perform_get(number, { "type" => type })
76
+ end
77
+
78
+ private
79
+
80
+ # overridden to ensure 'Account' and extra shash isn't added to URL path
81
+ def perform_get(identifier, params = nil)
82
+ valid_param?(:identifier, identifier, [String, Symbol], true)
83
+ response_json = @_client.send_request(@_resource_uri + identifier.to_s, "GET", params, nil, false, is_voice_request: @_is_voice_request, is_lookup_request: true)
84
+ @_resource_type.new(@_client, resource_json: response_json)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -85,6 +85,10 @@ module Plivo
85
85
  valid_param?(:type, options[:type], String, true)
86
86
  params[:type] = options[:type]
87
87
  end
88
+ if options.key?(:service) &&
89
+ valid_param?(:service, options[:service], String, true)
90
+ params[:service] = options[:service]
91
+ end
88
92
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
89
93
  'GET', params, true)
90
94
  end
@@ -136,22 +140,45 @@ module Plivo
136
140
  valid_param?(:type, options[:type], String, true)
137
141
  params[:type] = options[:type]
138
142
  end
143
+ if options.key?(:service) &&
144
+ valid_param?(:service, options[:service], String, true)
145
+ params[:service] = options[:service]
146
+ end
139
147
  response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
140
148
  'GET', param, true)
141
149
  meta = response['meta']
142
150
  return meta['total_count']
143
151
  end
144
152
 
145
- def find_number(number)
153
+ def find_number(number, options = nil)
146
154
  number_pool_uuid = getnumberpool_uuid(uuid)
147
- perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
155
+ if options.nil?
156
+ return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
148
157
  'GET')
158
+ end
159
+ params = {}
160
+ if options.key?(:service) &&
161
+ valid_param?(:service, options[:service], String, true)
162
+ params[:service] = options[:service]
163
+ end
164
+ perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
165
+ 'GET', params)
149
166
  end
150
167
 
151
- def add_number(number)
168
+ def add_number(number, options = nil)
152
169
  number_pool_uuid = getnumberpool_uuid(uuid)
153
- perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
170
+ if options.nil?
171
+ return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
154
172
  'POST')
173
+ return
174
+ end
175
+ params = {}
176
+ if options.key?(:service) &&
177
+ valid_param?(:service, options[:service], String, true)
178
+ params[:service] = options[:service]
179
+ end
180
+ perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
181
+ 'POST', params)
155
182
  end
156
183
 
157
184
  def add_tollfree(tollfree)
@@ -242,6 +269,10 @@ module Plivo
242
269
  number_pool_uuid = getnumberpool_uuid(uuid)
243
270
  params = {}
244
271
  params[:rent] = true
272
+ if options.key?(:service) &&
273
+ valid_param?(:service, options[:service], String, true)
274
+ params[:service] = options[:service]
275
+ end
245
276
  if options.key?(:number)
246
277
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + options[:number].to_s ,
247
278
  'POST', params)
@@ -360,6 +391,10 @@ module Plivo
360
391
  valid_param?(:type, options[:type], String, true)
361
392
  params[:type] = options[:type]
362
393
  end
394
+ if options.key?(:service) &&
395
+ valid_param?(:service, options[:service], String, true)
396
+ params[:service] = options[:service]
397
+ end
363
398
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
364
399
  'GET', params, true)
365
400
  end
@@ -401,20 +436,42 @@ module Plivo
401
436
  valid_param?(:type, options[:type], String, true)
402
437
  params[:type] = options[:type]
403
438
  end
439
+ if options.key?(:service) &&
440
+ valid_param?(:service, options[:service], String, true)
441
+ params[:service] = options[:service]
442
+ end
404
443
  response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
405
444
  'GET', params, true)
406
445
  meta = response['meta']
407
446
  return meta['total_count']
408
447
  end
409
448
 
410
- def find(number)
411
- perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
449
+ def find(number, options = nil)
450
+ if options.nil?
451
+ return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
412
452
  'GET')
453
+ end
454
+ params = {}
455
+ if options.key?(:service) &&
456
+ valid_param?(:service, options[:service], String, true)
457
+ params[:service] = options[:service]
458
+ end
459
+ perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
460
+ 'GET', params)
413
461
  end
414
462
 
415
- def add(number)
416
- perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
463
+ def add(number, options = nil)
464
+ if options.nil?
465
+ return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
417
466
  'POST')
467
+ end
468
+ params = {}
469
+ if options.key?(:service) &&
470
+ valid_param?(:service, options[:service], String, true)
471
+ params[:service] = options[:service]
472
+ end
473
+ perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
474
+ 'POST', params)
418
475
  end
419
476
 
420
477
  def remove(number, unrent= false)
@@ -425,6 +482,10 @@ module Plivo
425
482
  def buy_add_number(options = nil)
426
483
  params = {}
427
484
  params[:rent] = true
485
+ if options.key?(:service) &&
486
+ valid_param?(:service, options[:service], String, true)
487
+ params[:service] = options[:service]
488
+ end
428
489
  if options.key?(:number)
429
490
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_id + '/Number/' + options[:number].to_s ,
430
491
  'POST', params)
@@ -1,6 +1,6 @@
1
- require_relative 'resources'
2
- require_relative 'base_client'
3
- require_relative 'base'
1
+ require_relative "resources"
2
+ require_relative "base_client"
3
+ require_relative "base"
4
4
 
5
5
  module Plivo
6
6
  class RestClient < BaseClient
@@ -13,8 +13,9 @@ module Plivo
13
13
  attr_reader :call_feedback
14
14
  attr_reader :powerpacks
15
15
  attr_reader :powerpacks, :media
16
+ attr_reader :lookup
16
17
 
17
- def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
18
+ def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5)
18
19
  configure_base_uri
19
20
  super
20
21
  configure_interfaces
@@ -28,6 +29,7 @@ module Plivo
28
29
  @voice_base_uri_fallback_1 = Base::API_VOICE_FALLBACK_1
29
30
  @voice_base_uri_fallback_2 = Base::API_VOICE_FALLBACK_2
30
31
  @callinsights_base_uri = Base::CALLINSIGHTS_API_URL
32
+ @lookup_base_uri = Base::LOOKUP_API_URL
31
33
  end
32
34
 
33
35
  def configure_interfaces
@@ -47,6 +49,7 @@ module Plivo
47
49
  @addresses = Resources::AddressInterface.new(self)
48
50
  @identities = Resources::IdentityInterface.new(self)
49
51
  @call_feedback = Resources::CallFeedbackInterface.new(self)
52
+ @lookup = Resources::LookupInterface.new(self)
50
53
  end
51
54
  end
52
55
  end
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = '4.9.1'.freeze
2
+ VERSION = "4.14.0".freeze
3
3
  end
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.required_ruby_version = '>= 2.0.0'
33
33
 
34
- spec.add_dependency 'faraday', '~> 0.9'
35
- spec.add_dependency 'faraday_middleware', '~> 0.12.2'
34
+ spec.add_dependency 'faraday', '~> 1.0.1'
35
+ spec.add_dependency 'faraday_middleware', '~> 1.0.0'
36
36
  spec.add_dependency 'htmlentities'
37
37
  spec.add_dependency 'jwt'
38
38
 
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.9.1
4
+ version: 4.14.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: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: 1.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.9'
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.12.2
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.12.2
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: htmlentities
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +165,7 @@ files:
165
165
  - ci/config.yml
166
166
  - examples/conference_bridge.rb
167
167
  - examples/jwt.rb
168
+ - examples/lookup.rb
168
169
  - examples/multi_party_call.rb
169
170
  - examples/phlos.rb
170
171
  - lib/plivo.rb
@@ -185,6 +186,7 @@ files:
185
186
  - lib/plivo/resources/conferences.rb
186
187
  - lib/plivo/resources/endpoints.rb
187
188
  - lib/plivo/resources/identities.rb
189
+ - lib/plivo/resources/lookup.rb
188
190
  - lib/plivo/resources/media.rb
189
191
  - lib/plivo/resources/messages.rb
190
192
  - lib/plivo/resources/nodes.rb