plivo 0.3.19 → 4.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/AUTHORS.md +4 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +19 -0
- data/README.md +105 -24
- data/Rakefile +7 -0
- data/lib/plivo.rb +9 -815
- data/lib/plivo/base.rb +9 -0
- data/lib/plivo/base/resource.rb +85 -0
- data/lib/plivo/base/resource_interface.rb +93 -0
- data/lib/plivo/base/response.rb +29 -0
- data/lib/plivo/exceptions.rb +50 -0
- data/lib/plivo/resources.rb +14 -0
- data/lib/plivo/resources/accounts.rb +174 -0
- data/lib/plivo/resources/applications.rb +233 -0
- data/lib/plivo/resources/calls.rb +492 -0
- data/lib/plivo/resources/conferences.rb +371 -0
- data/lib/plivo/resources/endpoints.rb +130 -0
- data/lib/plivo/resources/messages.rb +178 -0
- data/lib/plivo/resources/numbers.rb +302 -0
- data/lib/plivo/resources/pricings.rb +43 -0
- data/lib/plivo/resources/recordings.rb +114 -0
- data/lib/plivo/rest_client.rb +199 -0
- data/lib/plivo/utils.rb +107 -0
- data/lib/plivo/version.rb +3 -0
- data/lib/plivo/xml.rb +27 -0
- data/lib/plivo/xml/conference.rb +20 -0
- data/lib/plivo/xml/dial.rb +16 -0
- data/lib/plivo/xml/dtmf.rb +13 -0
- data/lib/plivo/xml/element.rb +83 -0
- data/lib/plivo/xml/get_digits.rb +15 -0
- data/lib/plivo/xml/hangup.rb +12 -0
- data/lib/plivo/xml/message.rb +13 -0
- data/lib/plivo/xml/number.rb +13 -0
- data/lib/plivo/xml/play.rb +13 -0
- data/lib/plivo/xml/plivo_xml.rb +19 -0
- data/lib/plivo/xml/pre_answer.rb +12 -0
- data/lib/plivo/xml/record.rb +17 -0
- data/lib/plivo/xml/redirect.rb +13 -0
- data/lib/plivo/xml/response.rb +21 -0
- data/lib/plivo/xml/speak.rb +17 -0
- data/lib/plivo/xml/user.rb +13 -0
- data/lib/plivo/xml/wait.rb +12 -0
- data/plivo.gemspec +44 -0
- metadata +134 -45
- data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,178 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
class Message < Base::Resource
|
5
|
+
def initialize(client, options = nil)
|
6
|
+
@_name = 'Message'
|
7
|
+
@_identifier_string = 'message_uuid'
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
{
|
13
|
+
api_id: @api_id,
|
14
|
+
error_code: @error_code,
|
15
|
+
from_number: @from_number,
|
16
|
+
message_direction: @message_direction,
|
17
|
+
message_state: @message_state,
|
18
|
+
message_time: @message_time,
|
19
|
+
message_type: @message_type,
|
20
|
+
message_uuid: @message_uuid,
|
21
|
+
resource_uri: @resource_uri,
|
22
|
+
to_number: @to_number,
|
23
|
+
total_amount: @total_amount,
|
24
|
+
total_rate: @total_rate,
|
25
|
+
units: @units
|
26
|
+
}.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MessagesInterface < Base::ResourceInterface
|
31
|
+
def initialize(client, resource_list_json = nil)
|
32
|
+
@_name = 'Message'
|
33
|
+
@_resource_type = Message
|
34
|
+
@_identifier_string = 'message_uuid'
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [String] message_uuid
|
39
|
+
def get(message_uuid)
|
40
|
+
perform_get(message_uuid)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [String] src
|
44
|
+
# @param [Array] dst
|
45
|
+
# @param [String] text
|
46
|
+
# @param [Hash] options
|
47
|
+
# @option options [String] :type The type of message. Should be `sms` for a text message. Defaults to `sms`.
|
48
|
+
# @option options [String] :url The URL to which with the status of the message is sent. The following parameters are sent to the URL:
|
49
|
+
# - To - Phone number of the recipient
|
50
|
+
# - From - Phone number of the sender
|
51
|
+
# - Status - Status of the message including "queued", "sent", "failed", "delivered", "undelivered" or "rejected"
|
52
|
+
# - MessageUUID - The unique ID for the message
|
53
|
+
# - ParentMessageUUID - ID of the parent message (see notes about long SMS below)
|
54
|
+
# - PartInfo - Specifies the sequence of the message (useful for long messages split into multiple text messages; see notes about long SMS below)
|
55
|
+
# - TotalRate - Total rate per sms
|
56
|
+
# - TotalAmount - Total cost of sending the sms (TotalRate * Units)
|
57
|
+
# - Units - Number of units into which a long SMS was split
|
58
|
+
# - MCC - Mobile Country Code (see here {https://en.wikipedia.org/wiki/Mobile_country_code} for more details)
|
59
|
+
# - MNC - Mobile Network Code (see here {https://en.wikipedia.org/wiki/Mobile_country_code} for more details)
|
60
|
+
# - ErrorCode - Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
|
61
|
+
# @option options [String] :method The method used to call the url. Defaults to POST.
|
62
|
+
# @option options [String] :log If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
|
63
|
+
def create(src, dst, text, options = nil)
|
64
|
+
valid_param?(:src, src, [Integer, String, Symbol], true)
|
65
|
+
valid_param?(:text, text, [String, Symbol], true)
|
66
|
+
valid_param?(:dst, dst, Array, true)
|
67
|
+
dst.each do |dst_num|
|
68
|
+
valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
|
69
|
+
end
|
70
|
+
|
71
|
+
if dst.include? src
|
72
|
+
raise InvalidRequestError, 'src and dst cannot be same'
|
73
|
+
end
|
74
|
+
|
75
|
+
params = {
|
76
|
+
src: src,
|
77
|
+
dst: dst.join('<'),
|
78
|
+
text: text
|
79
|
+
}
|
80
|
+
|
81
|
+
return perform_create(params) if options.nil?
|
82
|
+
valid_param?(:options, options, Hash, true)
|
83
|
+
|
84
|
+
if options.key?(:type) &&
|
85
|
+
valid_param?(:type, options[:type], String, true, 'sms')
|
86
|
+
params[:type] = options[:type]
|
87
|
+
end
|
88
|
+
|
89
|
+
if options.key?(:url) && valid_param?(:url, options[:url], String, true)
|
90
|
+
params[:url] = options[:url]
|
91
|
+
if options.key?(:method) &&
|
92
|
+
valid_param?(:method, options[:method], String, true, %w[POST GET])
|
93
|
+
params[:method] = options[:method]
|
94
|
+
else
|
95
|
+
params[:method] = 'POST'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if options.key?(:log) &&
|
100
|
+
valid_param?(:log, options[:log], [TrueClass, FalseClass], true)
|
101
|
+
params[:log] = options[:log]
|
102
|
+
end
|
103
|
+
perform_create(params)
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param [Hash] options
|
107
|
+
# @option options [String] :subaccount The id of the subaccount, if message details of the subaccount is needed.
|
108
|
+
# @option options [String] :message_direction Filter the results by message direction. The valid inputs are inbound and outbound.
|
109
|
+
# @option options [String] :message_time Filter out messages according to the time of completion. The filter can be used in the following five forms:
|
110
|
+
# - message_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use message_time=2012-03-21 11:47[:30]
|
111
|
+
# - message_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use message_time\__gt=2012-03-21 11:47
|
112
|
+
# - message_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after or exactly at 2012-03-21 11:47[:30], use message_time\__gte=2012-03-21 11:47[:30]
|
113
|
+
# - message_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before 2012-03-21 11:47, use message_time\__lt=2012-03-21 11:47
|
114
|
+
# - message_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before or exactly at 2012-03-21 11:47[:30], use message_time\__lte=2012-03-21 11:47[:30]
|
115
|
+
# - Note: The above filters can be combined to get messages that were sent/received in a particular time range. The timestamps need to be UTC timestamps.
|
116
|
+
# @option options [String] :message_state Status value of the message, is one of "queued", "sent", "failed", "delivered", "undelivered" or "rejected"
|
117
|
+
# @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
118
|
+
# @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.
|
119
|
+
# @option options [String] :error_code Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
|
120
|
+
def list(options = nil)
|
121
|
+
return perform_list if options.nil?
|
122
|
+
valid_param?(:options, options, Hash, true)
|
123
|
+
|
124
|
+
params = {}
|
125
|
+
params_expected = %i[
|
126
|
+
subaccount message_time message_time__gt message_time__gte
|
127
|
+
message_time__lt message_time__lte error_code
|
128
|
+
]
|
129
|
+
params_expected.each do |param|
|
130
|
+
if options.key?(param) &&
|
131
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
132
|
+
params[param] = options[param]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
%i[offset limit].each do |param|
|
137
|
+
if options.key?(param) &&
|
138
|
+
valid_param?(param, options[param], [Integer, Integer], true)
|
139
|
+
params[param] = options[param]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
if options.key?(:message_direction) &&
|
144
|
+
valid_param?(:message_direction, options[:message_direction],
|
145
|
+
[String, Symbol], true, %w[inbound outbound])
|
146
|
+
params[:message_direction] = options[:message_direction]
|
147
|
+
end
|
148
|
+
|
149
|
+
if options.key?(:message_state) &&
|
150
|
+
valid_param?(:message_state, options[:message_state],
|
151
|
+
[String, Symbol], true, %w[queued sent failed delivered
|
152
|
+
undelivered rejected])
|
153
|
+
params[:message_state] = options[:message_state]
|
154
|
+
end
|
155
|
+
|
156
|
+
if options.key?(:limit) &&
|
157
|
+
(options[:limit] > 20 || options[:limit] <= 0)
|
158
|
+
raise_invalid_request('The maximum number of results that can be '\
|
159
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
160
|
+
end
|
161
|
+
|
162
|
+
raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0
|
163
|
+
|
164
|
+
perform_list(params)
|
165
|
+
end
|
166
|
+
|
167
|
+
def each
|
168
|
+
offset = 0
|
169
|
+
loop do
|
170
|
+
message_list = list(offset: offset)
|
171
|
+
message_list[:objects].each { |message| yield message }
|
172
|
+
offset += 20
|
173
|
+
return unless message_list.length == 20
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
|
5
|
+
class PhoneNumber < Base::Resource
|
6
|
+
def initialize(client, options = nil)
|
7
|
+
@_name = 'PhoneNumber'
|
8
|
+
@_identifier_string = 'number'
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def buy(app_id = nil)
|
13
|
+
params = {}
|
14
|
+
params[:app_id] = app_id unless app_id.nil?
|
15
|
+
perform_action(nil, 'POST', params, true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
{
|
20
|
+
country: @country,
|
21
|
+
lata: @lata,
|
22
|
+
monthly_rental_rate: @monthly_rental_rate,
|
23
|
+
number: @number,
|
24
|
+
type: @type,
|
25
|
+
prefix: @prefix,
|
26
|
+
rate_center: @rate_center,
|
27
|
+
region: @region,
|
28
|
+
resource_uri: @resource_uri,
|
29
|
+
restriction: @restriction,
|
30
|
+
restriction_text: @restriction_text,
|
31
|
+
setup_rate: @setup_rate,
|
32
|
+
sms_enabled: @sms_enabled,
|
33
|
+
sms_rate: @sms_rate,
|
34
|
+
voice_enabled: @voice_enabled,
|
35
|
+
voice_rate: @voice_rate
|
36
|
+
}.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class PhoneNumberInterface < Base::ResourceInterface
|
41
|
+
def initialize(client, resource_list_json = nil)
|
42
|
+
@_name = 'PhoneNumber'
|
43
|
+
@_resource_type = PhoneNumber
|
44
|
+
@_identifier_string = 'number'
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param [String] country_iso The ISO code A2 of the country ( BE for Belgium, DE for Germany, GB for United Kingdom, US for United States etc ). See the Wikipedia site for a list of ISOs for different countries.
|
49
|
+
# @param [Hash] options
|
50
|
+
# @option options [String] :type The type of number you are looking for. The possible number types are fixed, mobile and tollfree. Defaults to any if this field is not specified. type also accepts the value any, which will search for all 3 number types.
|
51
|
+
# @option options [String] :pattern Represents the pattern of the number to be searched. Adding a pattern will search for numbers which start with the country code + pattern. For eg. a pattern of 415 and a country_iso: US will search for numbers starting with 1415.
|
52
|
+
# @option options [String] :region This filter is only applicable when the type is fixed. If the type is not provided, it is assumed to be fixed. Region based filtering can be performed with the following terms:
|
53
|
+
# - Exact names of the region: You could use region=Frankfurt if you were looking for a number in Frankfurt. Performed if the search term is three or more characters in length.
|
54
|
+
# @option options [String] :services Filters out phone numbers according to the services you want from that number. The following values are valid:
|
55
|
+
# - voice - If this option is selected, it ensures that the results have voice enabled numbers. These numbers may or may not be SMS enabled.
|
56
|
+
# - voice,sms - If this option is selected, it ensures that the results have both voice and sms enabled on the same number.
|
57
|
+
# - sms - If this option is selected, it ensures that the results have sms enabled numbers. These numbers may or may not be voice enabled.
|
58
|
+
# - By default, numbers that have either voice or sms or both enabled are returned.
|
59
|
+
# @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.
|
60
|
+
# @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.
|
61
|
+
# @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
62
|
+
# @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.
|
63
|
+
def search(country_iso, options = nil)
|
64
|
+
valid_param?(:country_iso, country_iso, [String, Symbol], true)
|
65
|
+
unless country_iso.length == 2
|
66
|
+
raise_invalid_request('country_iso should be of length 2')
|
67
|
+
end
|
68
|
+
params = { country_iso: country_iso }
|
69
|
+
|
70
|
+
return perform_list(params) if options.nil?
|
71
|
+
|
72
|
+
%i[type pattern region services lata rate_center].each do |param|
|
73
|
+
if options.key?(param) &&
|
74
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
75
|
+
params[param] = options[param]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
%i[offset limit].each do |param|
|
80
|
+
if options.key?(param) && valid_param?(param, options[param],
|
81
|
+
[Integer, Integer], true)
|
82
|
+
params[param] = options[param]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
87
|
+
raise_invalid_request('The maximum number of results that can be '\
|
88
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
89
|
+
end
|
90
|
+
|
91
|
+
if options.key?(:offset) && options[:offset] < 0
|
92
|
+
raise_invalid_request("Offset can't be negative")
|
93
|
+
end
|
94
|
+
|
95
|
+
perform_list(params)
|
96
|
+
end
|
97
|
+
|
98
|
+
def each(country_iso)
|
99
|
+
offset = 0
|
100
|
+
loop do
|
101
|
+
phone_number_list = search(country_iso, offset: offset)
|
102
|
+
phone_number_list[:objects].each { |phone_number| yield phone_number }
|
103
|
+
offset += 20
|
104
|
+
return unless number_list.length == 20
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def buy(number, app_id = nil)
|
109
|
+
valid_param?(:number, number, [Integer, String, Symbol], true)
|
110
|
+
PhoneNumber.new(@_client,
|
111
|
+
resource_id: number).buy(app_id)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class Number < Base::Resource
|
116
|
+
def initialize(client, options = nil)
|
117
|
+
@_name = 'Number'
|
118
|
+
@_identifier_string = 'number'
|
119
|
+
super
|
120
|
+
end
|
121
|
+
|
122
|
+
def update(options = nil)
|
123
|
+
valid_param?(:options, options, Hash, true)
|
124
|
+
|
125
|
+
params = {}
|
126
|
+
|
127
|
+
if options.key?(:subaccount) &&
|
128
|
+
valid_subaccount?(options[:subaccount], true)
|
129
|
+
params[:subaccount] = options[:subaccount]
|
130
|
+
end
|
131
|
+
|
132
|
+
%i[alias app_id].each do |param|
|
133
|
+
if options.key?(param) &&
|
134
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
135
|
+
params[param] = options[param]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
perform_update(params)
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete
|
143
|
+
perform_delete
|
144
|
+
end
|
145
|
+
|
146
|
+
def to_s
|
147
|
+
{
|
148
|
+
api_id: @api_id,
|
149
|
+
added_on: @added_on,
|
150
|
+
alias: @alias,
|
151
|
+
application: @application,
|
152
|
+
carrier: @carrier,
|
153
|
+
monthly_rental_rate: @monthly_rental_rate,
|
154
|
+
number: @number,
|
155
|
+
number_type: @number_type,
|
156
|
+
region: @region,
|
157
|
+
resource_uri: @resource_uri,
|
158
|
+
sms_enabled: @sms_enabled,
|
159
|
+
sms_rate: @sms_rate,
|
160
|
+
sub_account: @sub_account,
|
161
|
+
voice_enabled: @voice_enabled,
|
162
|
+
voice_rate: @voice_rate
|
163
|
+
}.to_s
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class NumberInterface < Base::ResourceInterface
|
168
|
+
def initialize(client, resource_list_json = nil)
|
169
|
+
@_name = 'Number'
|
170
|
+
@_resource_type = Number
|
171
|
+
@_identifier_string = 'number'
|
172
|
+
super
|
173
|
+
end
|
174
|
+
|
175
|
+
# @param [String] number
|
176
|
+
def get(number)
|
177
|
+
perform_get(number)
|
178
|
+
end
|
179
|
+
|
180
|
+
# @param [Hash] options
|
181
|
+
# @option options [String] :type The type of number you are filtering. You can filter by local and tollfree numbers. Defaults to a local number.
|
182
|
+
# @option options [String|Int] :number_startswith Used to specify the beginning of the number. For example, if the number '24' is specified, the API will fetch only those numbers beginning with '24'.
|
183
|
+
# @option options [String] :subaccount Requires the auth_id of the subaccount as input. If this parameter is included in the request, all numbers of the particular subaccount are displayed.
|
184
|
+
# @option options [String] :alias This is a name given to the number. The API will fetch only those numbers with the alias specified.
|
185
|
+
# @option options [String] :services Filters out phone numbers according to the services you want from that number. The following values are valid:
|
186
|
+
# - voice - Returns a list of numbers that provide 'voice' services. Additionally, if the numbers offer both 'voice' and 'sms', they are also listed. Note - This option does not exclusively list those services that provide both voice and sms .
|
187
|
+
# - voice,sms - Returns a list of numbers that provide both 'voice' and 'sms' services.
|
188
|
+
# - sms - Returns a list of numbers that provide only 'sms' services.
|
189
|
+
# @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
190
|
+
# @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.
|
191
|
+
def list(options = nil)
|
192
|
+
return perform_list if options.nil?
|
193
|
+
|
194
|
+
valid_param?(:options, options, Hash, true)
|
195
|
+
|
196
|
+
params = {}
|
197
|
+
|
198
|
+
%i[number_startswith subaccount alias].each do |param|
|
199
|
+
if options.key?(param) &&
|
200
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
201
|
+
params[param] = options[param]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
if options.key?(:services) &&
|
206
|
+
valid_param?(:services, options[:services], [String, Symbol],
|
207
|
+
true, %w[sms voice voice,sms])
|
208
|
+
params[:services] = options[:services]
|
209
|
+
end
|
210
|
+
|
211
|
+
if options.key?(:type) &&
|
212
|
+
valid_param?(:type, options[:type], [String, Symbol],
|
213
|
+
true, %w[local tollfree])
|
214
|
+
params[:type] = options[:type]
|
215
|
+
end
|
216
|
+
|
217
|
+
%i[offset limit].each do |param|
|
218
|
+
if options.key?(param) && valid_param?(param, options[param],
|
219
|
+
[Integer, Integer], true)
|
220
|
+
params[param] = options[param]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
225
|
+
raise_invalid_request('The maximum number of results that can be '\
|
226
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
227
|
+
end
|
228
|
+
|
229
|
+
if options.key?(:offset) && options[:offset] < 0
|
230
|
+
raise_invalid_request("Offset can't be negative")
|
231
|
+
end
|
232
|
+
|
233
|
+
perform_list(params)
|
234
|
+
end
|
235
|
+
|
236
|
+
def each
|
237
|
+
offset = 0
|
238
|
+
loop do
|
239
|
+
number_list = list(offset: offset)
|
240
|
+
number_list[:objects].each { |number| yield number }
|
241
|
+
offset += 20
|
242
|
+
return unless number_list.length == 20
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
# @param [Array] numbers An array of numbers that need to be added for the carrier. Make sure that you configure the numbers to point to the sip server @sbc.plivo.com. Eg: If the number you own from your carrier is 18554675486 then the sip address it needs to point to is 18554675486@sbc.plivo.com
|
247
|
+
# @param [String] carrier The carrier_id of the IncomingCarrier that the number is associated with. For more information, check our IncomingCarrier API {https://www.plivo.com/docs/api/incomingcarrier/}
|
248
|
+
# @param [String] region This is the region that is associated with the Number. You can use it to organize numbers based on the area they are from.
|
249
|
+
# @param [Hash] options
|
250
|
+
# @option options [String] :number_type This field does not impact the way Plivo uses this number. It is primarily adding more information about your number. You may use this field to categorize between local and tollfree numbers. Default is local.
|
251
|
+
# @option options [String] :app_id The application id of the application that is to be linked.
|
252
|
+
# @option options [String] :subaccount The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder.
|
253
|
+
def add_number(numbers, carrier, region, options = nil)
|
254
|
+
valid_param?(:carrier, carrier, [String, Symbol], true)
|
255
|
+
valid_param?(:region, region, [String, Symbol], true)
|
256
|
+
valid_param?(:numbers, numbers, Array, true)
|
257
|
+
numbers.each do |number|
|
258
|
+
valid_param?(:number, number, [Integer, String, Symbol], true)
|
259
|
+
end
|
260
|
+
|
261
|
+
params = {
|
262
|
+
numbers: numbers.join(','),
|
263
|
+
carrier: carrier,
|
264
|
+
region: region
|
265
|
+
}
|
266
|
+
|
267
|
+
return perform_post(params) if options.nil?
|
268
|
+
|
269
|
+
if options.key?(:subaccount) &&
|
270
|
+
valid_subaccount?(options[:subaccount], true)
|
271
|
+
params[:subaccount] = options[:subaccount]
|
272
|
+
end
|
273
|
+
|
274
|
+
%i[number_type app_id].each do |param|
|
275
|
+
if options.key?(param) &&
|
276
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
277
|
+
params[param] = options[param]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
perform_post(params)
|
282
|
+
end
|
283
|
+
|
284
|
+
# @param [String] number
|
285
|
+
# @param [Hash] options
|
286
|
+
# @option options [String] :alias The textual name given to the number.
|
287
|
+
# @option options [String] :app_id The application id of the application that is to be linked.
|
288
|
+
# @option options [String] :subaccount The auth_id of the subaccount to which this number should be added. This can only be performed by a main account holder.
|
289
|
+
def update(number, options = nil)
|
290
|
+
valid_param?(:number, number, [String, Symbol], true)
|
291
|
+
Number.new(@_client,
|
292
|
+
resource_id: number).update(options)
|
293
|
+
end
|
294
|
+
|
295
|
+
# @param [String] number
|
296
|
+
def delete(number)
|
297
|
+
valid_param?(:number, number, [String, Symbol], true)
|
298
|
+
Number.new(@_client, resource_id: number).delete
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|