plivo 4.10.0 → 4.15.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: c368bc21255a5a1cef319179fbf0bf066375b1f6
4
- data.tar.gz: 929a607f7200f8060263b697680dcb610471632d
3
+ metadata.gz: 114dedbc98499312df91e0cdccf82b0965c633a6
4
+ data.tar.gz: f3e82a94f10e2bfff18d2057d67f639e114e01be
5
5
  SHA512:
6
- metadata.gz: 718383feb89c897a7a3d0d91094ab09d4885b9d0054b05983b63d507678bcf152247fcfbe04ef69ecbcf8c6f3c59807240cf32a3616991c6175f35643ef0c2d8
7
- data.tar.gz: 6f8b7b343a0b26f7b59259d8eea063ec1e15a41c2283316342d204a4f341cc5757e38a8f50ba78daa6515ab38972731f976a8779ab537b1e9db2ab7826f1eb48
6
+ metadata.gz: 22cc46f89d219c32bf3e5f59378b03d383c1737909eed8ef711f0b3e181c3e9e29ee3a1e3b75e146516ac1ac41e4241fe64aaad0c058ebce42982817ad6a151b
7
+ data.tar.gz: bfd4e2fc9fe8fc548239e34a9d86c319caa45f07df3002b329f1b7210cafd7342bfbc6c5dcbbde0dc01fc9c235b1f6bc053c087a12c486522ecfca9b9d19917a
@@ -1,5 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.15.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.0) (2020-11-17)
4
+ - Add number_priority support for Powerpack API.
5
+
6
+ ## [4.14.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.14.0) (2020-10-30)
7
+ - Change lookup API endpoint and response.
8
+
9
+ ## [4.13.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.13.0) (2020-09-30)
10
+ - Add support for Lookup API
11
+
12
+ ## [4.12.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.12.0) (2020-09-24)
13
+ - Add "public_uri" optional param support for Application API.
14
+
15
+ ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.11.0) (2020-08-25)
16
+ - Add Powerpack for mms
17
+
3
18
  ## [4.10.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.10.0) (2020-09-04)
4
19
  - Add ConferenceUuid & CallState for Get Details of a Call API
5
20
  - Upgrade faraday & faraday_middleware dependencies
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.10.0'
11
+ gem 'plivo', '>= 4.15.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]
@@ -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
@@ -47,6 +47,9 @@ module Plivo
47
47
  if options.key?(:name)
48
48
  params[:name] = options[:name]
49
49
  end
50
+ if options.key?(:number_priority)
51
+ params[:number_priority] = options[:number_priority]
52
+ end
50
53
  perform_action_apiresponse('', 'POST', params)
51
54
  end
52
55
 
@@ -85,6 +88,10 @@ module Plivo
85
88
  valid_param?(:type, options[:type], String, true)
86
89
  params[:type] = options[:type]
87
90
  end
91
+ if options.key?(:service) &&
92
+ valid_param?(:service, options[:service], String, true)
93
+ params[:service] = options[:service]
94
+ end
88
95
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
89
96
  'GET', params, true)
90
97
  end
@@ -136,22 +143,45 @@ module Plivo
136
143
  valid_param?(:type, options[:type], String, true)
137
144
  params[:type] = options[:type]
138
145
  end
146
+ if options.key?(:service) &&
147
+ valid_param?(:service, options[:service], String, true)
148
+ params[:service] = options[:service]
149
+ end
139
150
  response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
140
151
  'GET', param, true)
141
152
  meta = response['meta']
142
153
  return meta['total_count']
143
154
  end
144
155
 
145
- def find_number(number)
156
+ def find_number(number, options = nil)
146
157
  number_pool_uuid = getnumberpool_uuid(uuid)
147
- perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
158
+ if options.nil?
159
+ return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
148
160
  'GET')
161
+ end
162
+ params = {}
163
+ if options.key?(:service) &&
164
+ valid_param?(:service, options[:service], String, true)
165
+ params[:service] = options[:service]
166
+ end
167
+ perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
168
+ 'GET', params)
149
169
  end
150
170
 
151
- def add_number(number)
171
+ def add_number(number, options = nil)
152
172
  number_pool_uuid = getnumberpool_uuid(uuid)
153
- perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
173
+ if options.nil?
174
+ return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
154
175
  'POST')
176
+ return
177
+ end
178
+ params = {}
179
+ if options.key?(:service) &&
180
+ valid_param?(:service, options[:service], String, true)
181
+ params[:service] = options[:service]
182
+ end
183
+ perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
184
+ 'POST', params)
155
185
  end
156
186
 
157
187
  def add_tollfree(tollfree)
@@ -242,6 +272,10 @@ module Plivo
242
272
  number_pool_uuid = getnumberpool_uuid(uuid)
243
273
  params = {}
244
274
  params[:rent] = true
275
+ if options.key?(:service) &&
276
+ valid_param?(:service, options[:service], String, true)
277
+ params[:service] = options[:service]
278
+ end
245
279
  if options.key?(:number)
246
280
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + options[:number].to_s ,
247
281
  'POST', params)
@@ -295,7 +329,8 @@ module Plivo
295
329
  local_connect: @local_connect,
296
330
  uuid: @uuid,
297
331
  number_pool:@number_pool,
298
- created_on:@created_on
332
+ created_on:@created_on,
333
+ number_priority:@number_priority
299
334
  }.to_s
300
335
  end
301
336
  end
@@ -360,6 +395,10 @@ module Plivo
360
395
  valid_param?(:type, options[:type], String, true)
361
396
  params[:type] = options[:type]
362
397
  end
398
+ if options.key?(:service) &&
399
+ valid_param?(:service, options[:service], String, true)
400
+ params[:service] = options[:service]
401
+ end
363
402
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
364
403
  'GET', params, true)
365
404
  end
@@ -401,20 +440,42 @@ module Plivo
401
440
  valid_param?(:type, options[:type], String, true)
402
441
  params[:type] = options[:type]
403
442
  end
443
+ if options.key?(:service) &&
444
+ valid_param?(:service, options[:service], String, true)
445
+ params[:service] = options[:service]
446
+ end
404
447
  response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
405
448
  'GET', params, true)
406
449
  meta = response['meta']
407
450
  return meta['total_count']
408
451
  end
409
452
 
410
- def find(number)
411
- perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
453
+ def find(number, options = nil)
454
+ if options.nil?
455
+ return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
412
456
  'GET')
457
+ end
458
+ params = {}
459
+ if options.key?(:service) &&
460
+ valid_param?(:service, options[:service], String, true)
461
+ params[:service] = options[:service]
462
+ end
463
+ perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
464
+ 'GET', params)
413
465
  end
414
466
 
415
- def add(number)
416
- perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
467
+ def add(number, options = nil)
468
+ if options.nil?
469
+ return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
417
470
  'POST')
471
+ end
472
+ params = {}
473
+ if options.key?(:service) &&
474
+ valid_param?(:service, options[:service], String, true)
475
+ params[:service] = options[:service]
476
+ end
477
+ perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
478
+ 'POST', params)
418
479
  end
419
480
 
420
481
  def remove(number, unrent= false)
@@ -425,6 +486,10 @@ module Plivo
425
486
  def buy_add_number(options = nil)
426
487
  params = {}
427
488
  params[:rent] = true
489
+ if options.key?(:service) &&
490
+ valid_param?(:service, options[:service], String, true)
491
+ params[:service] = options[:service]
492
+ end
428
493
  if options.key?(:number)
429
494
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_id + '/Number/' + options[:number].to_s ,
430
495
  'POST', params)
@@ -601,6 +666,12 @@ module Plivo
601
666
  valid_param?(:local_connect, options[:local_connect], [TrueClass, FalseClass], true)
602
667
  params[:local_connect] = options[:local_connect]
603
668
  end
669
+
670
+ if options.key?(:number_priority) &&
671
+ valid_param?(:number_priority, options[:number_priority], Array, true)
672
+ params[:number_priority] = options[:number_priority]
673
+ end
674
+
604
675
  perform_create(params)
605
676
  end
606
677
 
@@ -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.10.0'.freeze
2
+ VERSION = "4.15.0".freeze
3
3
  end
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.10.0
4
+ version: 4.15.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-09-04 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -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