plivo 4.12.0 → 4.15.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8d277a7f0560d74af250eccbc0074d2dbeceb36
4
- data.tar.gz: daf6f39606b2e0e9d53b0a3327d6ddec90185ff1
3
+ metadata.gz: 9623fb2c4baf69935048acfa538cb061326de346
4
+ data.tar.gz: 30629da34bc63fed7092e9c264c34cd41a496870
5
5
  SHA512:
6
- metadata.gz: aa164e6d25507612e12614bb132c3efdb2f720ab2e64d5d2e98199c7e693d07b6526f4e0dcd93ec029a13c8c8f50973f55dd183ad19f42594890aa8207c2403b
7
- data.tar.gz: 74d62909b35e233477f90bc61ac9d55047943402be911125eabd06d9e32878c27f3321399144808ba4b18c46f1cfd55e9691fa865fef3c41d8e99b4ad5758116
6
+ metadata.gz: 69b585a499ec727dbc3f615d654b429f39a3f699028994de89cb79298b333e0a2d54501697644f579f4266fadc7bc0bb4fd4a43d50f021722e2defda30d8f979
7
+ data.tar.gz: 843e1f620186e4c8e6153f8a2cac6793c666e49479382622e9d24fa2452801fe99c7240480b2b04495e45d939d4731f11910607617e0b1eee815f73ebf5fd43f
@@ -1,9 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.15.2](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.2) (2021-01-27)
4
+ - Fix Call API resource - Set answer_method as Optional param.
5
+
6
+ ## [4.15.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.1) (2021-01-06)
7
+ - Fix Search Phone Numbers API using City Attribute.
8
+
9
+ ## [4.15.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.0) (2020-11-17)
10
+ - Add number_priority support for Powerpack API.
11
+
12
+ ## [4.14.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.14.0) (2020-10-30)
13
+ - Change lookup API endpoint and response.
14
+
15
+ ## [4.13.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.13.0) (2020-09-30)
16
+ - Add support for Lookup API
17
+
3
18
  ## [4.12.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.12.0) (2020-09-24)
4
19
  - Add "public_uri" optional param support for Application API.
5
20
 
6
- ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.9.0) (2020-08-25)
21
+ ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.11.0) (2020-08-25)
7
22
  - Add Powerpack for mms
8
23
 
9
24
  ## [4.10.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.10.0) (2020-09-04)
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.12.0'
11
+ gem 'plivo', '>= 4.15.2'
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
@@ -252,7 +252,6 @@ module Plivo
252
252
  # @param [String] from
253
253
  # @param [Array] to
254
254
  # @param [String] answer_url
255
- # @param [String] answer_method
256
255
  # @param [Hash] options
257
256
  # @option options [String] :answer_method - The method used to call the answer_url. Defaults to POST.
258
257
  # @option options [String] :ring_url - The URL that is notified by Plivo when the call is ringing. Defaults not set.
@@ -275,21 +274,19 @@ module Plivo
275
274
  # @option options [String] :parent_call_uuid - The call_uuid of the first leg in an ongoing conference call. It is recommended to use this parameter in scenarios where a member who is already present in the conference intends to add new members by initiating outbound API calls. This minimizes the delay in adding a new memeber to the conference.
276
275
  # @option options [Boolean] :error_parent_not_found - if set to true and the parent_call_uuid cannot be found, the API request would return an error. If set to false, the outbound call API request will be executed even if the parent_call_uuid is not found. Defaults to false.
277
276
  # @return [Call] Call
278
- def create(from, to, answer_url, answer_method = 'POST', options = nil)
277
+ def create(from, to, answer_url, options = nil)
279
278
  valid_param?(:from, from, [String, Symbol, Integer], true)
280
279
  valid_param?(:to, to, Array, true)
281
280
  to.each do |to_num|
282
281
  valid_param?(:to_num, to_num, [Integer, String, Symbol], true)
283
282
  end
284
283
  valid_param?(:answer_url, answer_url, [String, Symbol], true)
285
- valid_param?(:answer_method, answer_method, [String, Symbol],
286
- true, %w[GET POST])
284
+
287
285
 
288
286
  params = {
289
287
  from: from,
290
288
  to: to.join('<'),
291
289
  answer_url: answer_url,
292
- answer_method: answer_method
293
290
  }
294
291
 
295
292
  return perform_create(params, false) if options.nil?
@@ -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
@@ -59,6 +59,7 @@ module Plivo
59
59
  # - By default, numbers that have either voice or sms or both enabled are returned.
60
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
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
62
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.
63
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.
64
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.
@@ -71,7 +72,7 @@ module Plivo
71
72
 
72
73
  return perform_list(params) if options.nil?
73
74
 
74
- %i[type pattern region services lata rate_center].each do |param|
75
+ %i[type pattern region services lata rate_center city].each do |param|
75
76
  if options.key?(param) &&
76
77
  valid_param?(param, options[param], [String, Symbol], true)
77
78
  params[param] = options[param]
@@ -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
 
@@ -326,7 +329,8 @@ module Plivo
326
329
  local_connect: @local_connect,
327
330
  uuid: @uuid,
328
331
  number_pool:@number_pool,
329
- created_on:@created_on
332
+ created_on:@created_on,
333
+ number_priority:@number_priority
330
334
  }.to_s
331
335
  end
332
336
  end
@@ -662,6 +666,12 @@ module Plivo
662
666
  valid_param?(:local_connect, options[:local_connect], [TrueClass, FalseClass], true)
663
667
  params[:local_connect] = options[:local_connect]
664
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
+
665
675
  perform_create(params)
666
676
  end
667
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.12.0'.freeze
2
+ VERSION = "4.15.2".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.12.0
4
+ version: 4.15.2
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-24 00:00:00.000000000 Z
11
+ date: 2021-01-27 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