Class: CTM::ReceivingNumberList

Inherits:
List
  • Object
show all
Defined in:
lib/ctm/receiving_number_list.rb

Instance Attribute Summary

Attributes inherited from List

#filters, #list_type, #objects, #page, #per_page, #token, #total_entries, #total_pages

Instance Method Summary collapse

Methods inherited from List

#create, #each, #each_page, #find, #get

Constructor Details

#initialize(options = {}, token = nil) ⇒ ReceivingNumberList

Returns a new instance of ReceivingNumberList.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ctm/receiving_number_list.rb', line 3

def initialize(options={}, token=nil)
  super('ReceivingNumber', options, token)
  @account_id = options[:account_id]
  @number_id  = options[:number_id]
  if @number_id && @account_id
    @list_type_path = "accounts/#{@account_id}/numbers/#{@number_id}/#{@list_token_type}"
  elsif @account_id
    @list_type_path = "accounts/#{@account_id}/#{@list_token_type}"
  else
    @list_type_path = @list_token_type
  end
end

Instance Method Details

#add(receiving_number) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ctm/receiving_number_list.rb', line 16

def add(receiving_number)
  path_str = "/api/v1/#{@list_type_path}/#{receiving_number.id}/add.json"
  res = self.class.post(path_str, :body => {}.merge(:auth_token => @token))
  if res && res['status'] == 'success'
    CTM::Number.new(res['receiving_number'], @token)
  else
    puts res.inspect
    raise CTM::Error::Add.new(res["reason"])
  end
end

#rem(receiving_number) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ctm/receiving_number_list.rb', line 27

def rem(receiving_number)
  path_str = "/api/v1/#{@list_type_path}/#{receiving_number.id}/rem.json"
  res = self.class.delete(path_str, :body => {}.merge(:auth_token => @token))
  if res && res['status'] == 'success'
    CTM::Number.new(res['receiving_number'], @token)
  else
    puts res.inspect
    raise CTM::Error::Add.new(res["reason"])
  end
end