Class: Plivo::Resources::Powerpack

Inherits:
Base::Resource show all
Defined in:
lib/plivo/resources/powerpacks.rb

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Attribute Summary

Attributes inherited from Base::Resource

#id

Instance Method Summary collapse

Methods included from Utils

GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?

Constructor Details

#initialize(client, options = nil) ⇒ Powerpack

Returns a new instance of Powerpack.



6
7
8
9
10
# File 'lib/plivo/resources/powerpacks.rb', line 6

def initialize(client, options = nil)
  @_name = 'Powerpack'
  @_identifier_string = 'uuid'
  super
end

Instance Method Details

#add_number(number, options = nil) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/plivo/resources/powerpacks.rb', line 171

def add_number(number, options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  if options.nil?
    return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
               'POST')
    return
  end
  params = {}
  if options.key?(:service) &&
    valid_param?(:service, options[:service], String, true)
   params[:service] = options[:service]
  end
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
               'POST', params)
end

#add_tollfree(tollfree) ⇒ Object



187
188
189
190
191
# File 'lib/plivo/resources/powerpacks.rb', line 187

def add_tollfree(tollfree)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
               'POST')
end

#buy_add_number(options = nil) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/plivo/resources/powerpacks.rb', line 271

def buy_add_number(options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  params = {}
  params[:rent] = true
  if options.key?(:service) &&
    valid_param?(:service, options[:service], String, true)
   params[:service] = options[:service]
  end
  if options.key?(:number)
    return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + options[:number].to_s ,
               'POST', params)
  end
  if options.key?(:country_iso2).nil?
    raise_invalid_request('country_iso is cannot be empty')
  end
      
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:pattern) &&
    valid_param?(:pattern, options[:pattern], String, true)
   params[:starts_with] = options[:pattern]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end

 response = perform_custom_action_apiresponse('PhoneNumber',
 'GET', params, true)
  numbers = response['objects'][0]['number']
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + numbers.to_s,
               'POST', params)
end

#count_numbers(options = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/plivo/resources/powerpacks.rb', line 107

def count_numbers(options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  if options.nil?
   response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
   'GET')
   meta = response['meta']
   return meta['total_count']
  end
 
  params = {}
  
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:starts_with) &&
    valid_param?(:starts_with, options[:starts_with], String, true)
   params[:starts_with] = options[:starts_with]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso2] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end
  if options.key?(:service) &&
    valid_param?(:service, options[:service], String, true)
   params[:service] = options[:service]
  end
  response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
  'GET', param, true)
  meta = response['meta']
  return meta['total_count']
end

#delete(unrent_numbers = false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/plivo/resources/powerpacks.rb', line 18

def delete(unrent_numbers = false)
    valid_param?(:unrent_numbers, unrent_numbers, [TrueClass, FalseClass],
      false, [true, false])
    
    params = {
      :unrent_numbers => unrent_numbers
    }
    perform_action_apiresponse('', 'DELETE', params)
    # perform_delete(params)
end

#find_number(number, options = nil) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/plivo/resources/powerpacks.rb', line 156

def find_number(number, options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  if options.nil?
    return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
               'GET')
  end
  params = {}
  if options.key?(:service) &&
    valid_param?(:service, options[:service], String, true)
   params[:service] = options[:service]
  end
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
               'GET', params)
end

#find_shortcode(shortcode) ⇒ Object



259
260
261
262
263
# File 'lib/plivo/resources/powerpacks.rb', line 259

def find_shortcode(shortcode)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + shortcode.to_s ,
               'GET')
end

#find_tollfree(tollfree) ⇒ Object



265
266
267
268
269
# File 'lib/plivo/resources/powerpacks.rb', line 265

def find_tollfree(tollfree)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
               'GET')
end

#getnumberpool_uuid(uuid) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/plivo/resources/powerpacks.rb', line 99

def getnumberpool_uuid(uuid)
  valid_param?(:uuid, uuid, [String, Symbol], true)
  response = perform_action()
  numberpool_path = response.number_pool
  numberpool_array = numberpool_path.split("/")
  numberpool_array[5]
end

#list_numbers(options = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/plivo/resources/powerpacks.rb', line 56

def list_numbers(options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
  'GET') if options.nil?

  params = {}
  
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:starts_with) &&
    valid_param?(:starts_with, options[:starts_with], String, true)
   params[:starts_with] = options[:starts_with]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso2] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end
  if options.key?(:service) &&
    valid_param?(:service, options[:service], String, true)
   params[:service] = options[:service]
  end
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
  'GET', params, true)
end

#list_shortcodes(options = nil) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/plivo/resources/powerpacks.rb', line 211

def list_shortcodes(options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode',
               'GET') if options.nil?
  params = {}
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode',
               'GET', params)
end

#list_tollfree(options = nil) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/plivo/resources/powerpacks.rb', line 235

def list_tollfree(options = nil)
  number_pool_uuid = getnumberpool_uuid(uuid)
  return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
               'GET') if options.nil?
  params = {}
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
               'GET', params)
end

#numberpoolObject



12
13
14
15
16
# File 'lib/plivo/resources/powerpacks.rb', line 12

def numberpool
  number_pool_uuid = getnumberpool_uuid(uuid)
  options = {'number_pool_id' => number_pool_uuid}
  NumberPool.new(@_client, {resource_json: options})
end

#remove_number(number, unrent = false) ⇒ Object



193
194
195
196
197
# File 'lib/plivo/resources/powerpacks.rb', line 193

def remove_number(number, unrent= false)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
               'DELETE', { unrent: unrent }, false)
end

#remove_shortcode(number) ⇒ Object



205
206
207
208
209
# File 'lib/plivo/resources/powerpacks.rb', line 205

def remove_shortcode(number)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + number.to_s ,
               'DELETE', { unrent: false }, false)
end

#remove_tollfree(number, unrent = false) ⇒ Object



199
200
201
202
203
# File 'lib/plivo/resources/powerpacks.rb', line 199

def remove_tollfree(number, unrent= false)
  number_pool_uuid = getnumberpool_uuid(uuid)
  perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + number.to_s ,
               'DELETE', { unrent: unrent }, false)
end

#to_sObject



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/plivo/resources/powerpacks.rb', line 323

def to_s
  {
    name: @name,
    application_type: @application_type,
    application_id: @application_id,
    sticky_sender: @sticky_sender,
    local_connect: @local_connect,
    uuid: @uuid,
    number_pool:@number_pool,
    created_on:@created_on,
    number_priority:@number_priority
  }.to_s
end

#update(options = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/plivo/resources/powerpacks.rb', line 29

def update(options = nil)
  valid_param?(:options, options, Hash, true)
  params = {}
  if options.key?(:application_type) 
    params[:application_type] = options[:application_type]
  end
 
  if options.key?(:application_id) 
    params[:application_id] = options[:application_id]
  end
 
  if options.key?(:sticky_sender) 
    params[:sticky_sender] = options[:sticky_sender]
  end

  if options.key?(:local_connect) 
    params[:local_connect] = options[:local_connect]
  end
  if options.key?(:name) 
    params[:name] = options[:name]
  end
  if options.key?(:number_priority) 
    params[:number_priority] = options[:number_priority]
  end
  perform_action_apiresponse('', 'POST', params)
end