Class: VoipfoneClient::DivertListItem

Inherits:
Session
  • Object
show all
Defined in:
lib/voipfone_client/divert_list_item.rb

Instance Attribute Summary collapse

Attributes inherited from Session

#browser

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#authenticated?, #login, #parse_response

Constructor Details

#initialize(name: nil, number: nil) ⇒ DivertListItem

Constructor for VoipfoneClient::DivertListItem which accepts the name and number of the phone number to add to the diverts list.

Parameters:

  • name (String) (defaults to: nil)

    the name of the phone to be diverted to

  • number (String) (defaults to: nil)

    the number of the phone to be diverted to.



8
9
10
11
12
# File 'lib/voipfone_client/divert_list_item.rb', line 8

def initialize(name: nil, number: nil)
  @name = name
  @number = number
  super()
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/voipfone_client/divert_list_item.rb', line 3

def name
  @name
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/voipfone_client/divert_list_item.rb', line 3

def number
  @number
end

Class Method Details

.allArray

Get a list of phones which can be diverted to. Returns a nested array of name and phone number.

Returns:

  • (Array)

    of names and phone numbers



39
40
41
42
43
44
45
# File 'lib/voipfone_client/divert_list_item.rb', line 39

def all
  d = self.new
  request = d.browser.get("#{VoipfoneClient::API_GET_URL}?divertsCommon")
  d.parse_response(request)["divertsCommon"].collect do |i|
    DivertListItem.new(name: i.first, number: i.last)
  end
end

Instance Method Details

#saveBoolean

Add a new number to the list of numbers which can be diverted to. Requires a name and a phone number, which will have spaces stripped from it. May be in international format.

Returns:

  • (Boolean)

    true on success or a failure message (in which case a VoipfoneAPIError will be raised)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/voipfone_client/divert_list_item.rb', line 18

def save
  if @name.nil? || @number.nil?
    raise ArgumentError, "You need to include a name and number to add to the diverts list"
  end
  @number = @number.gsub(" ","")
  parameters = {
    "div-list-name" => @name,
    "div-list-num" => number
  }
  request = @browser.post("#{VoipfoneClient::API_POST_URL}?setDivertsList", parameters)
  response = parse_response(request)
  if response == [@name, @number]
    return true
  else
    raise VoipfoneAPIError, "Although Voipfone returned an OK, the data they stored didn't match what you asked for: #{response}"
  end
end