plivo 4.11.0 → 4.15.1

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: bc30f1aeebcfbed23f4f8a989b417c7b8f2c1bd4
4
- data.tar.gz: 9676720fbbfb5d6a274f1ca6814f1ca23f8f71e2
3
+ metadata.gz: af8812c959e30b03f4ab8312e6d5c65aeaff4dd3
4
+ data.tar.gz: ed5f67dc23cf3e31a3247688e3969ff8611255f7
5
5
  SHA512:
6
- metadata.gz: a02efb737c56f688bd70f639c640a8c7de86b2acd692f8c5cc3fd1f9277b9d01d4e88d396c71db78ee4cd5d0eab311547ae5e889c3c6ca83606eac8d49fa639f
7
- data.tar.gz: 7df6df39629bc3151b7f7824c6c0206ef25d291f957e968e1350cc60097c5c27454d26f2a48bc7be17a9003c9525f65c709d10d4e027aa61f3a3775aeddf59a1
6
+ metadata.gz: 81b47688dfe92855000e1bb118f1a53ecee5a10744f323ccbb4aaf721073a7e9be06ed23b5a88d2bcdab6fc7c0169a66a45c74ff1725e01da81460c0ce8e1dcf
7
+ data.tar.gz: '09c20aecb34e44472269a8239c4f9f3ccc8dea27a8b44347aeccae1f7ae73dea7a346467fad9d3648400d11c2d8992f3ce3e1563354eb7f34faa800121ac5827'
@@ -1,6 +1,21 @@
1
1
  # Change Log
2
2
 
3
- ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.9.0) (2020-08-25)
3
+ ## [4.15.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.1) (2021-01-06)
4
+ - Fix Search Phone Numbers API using City Attribute.
5
+
6
+ ## [4.15.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.15.0) (2020-11-17)
7
+ - Add number_priority support for Powerpack API.
8
+
9
+ ## [4.14.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.14.0) (2020-10-30)
10
+ - Change lookup API endpoint and response.
11
+
12
+ ## [4.13.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.13.0) (2020-09-30)
13
+ - Add support for Lookup API
14
+
15
+ ## [4.12.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.12.0) (2020-09-24)
16
+ - Add "public_uri" optional param support for Application API.
17
+
18
+ ## [4.11.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.11.0) (2020-08-25)
4
19
  - Add Powerpack for mms
5
20
 
6
21
  ## [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.11.0'
11
+ gem 'plivo', '>= 4.15.1'
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
@@ -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.11.0'.freeze
2
+ VERSION = "4.15.1".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.11.0
4
+ version: 4.15.1
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-07 00:00:00.000000000 Z
11
+ date: 2021-01-06 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