Class: VoipfoneClient::GlobalDivert

Inherits:
Client
  • Object
show all
Defined in:
lib/voipfone_client/global_divert.rb

Overview

Set up a global (whole-account) divert on your account. You need to specify the type of divert and the number to which the divert will go to. There are 4 supported situations which can be diverted for, namely:

- all calls (i.e. no calls will reach the pbx / phones - immediate divert)
- when there is a failure in the phone system
- when the phone(s) are busy
- when there's no answer

Constant Summary collapse

VOIPFONE_DIVERT_NAMES =

A hash of voipfone divert names vs our divert names. Note that when we query voipfone the returned value of the divert type is UPPERCASE.

{
  "all" => "all",
  "chanunavail" => "fail",
  "busy" => "busy",
  "noanswer" => "no_answer"
}

Instance Attribute Summary collapse

Attributes inherited from Client

#browser

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#account_balance, #account_details, #parse_response, #phone_numbers, #voicemail

Constructor Details

#initialize(divert_list_item = nil) ⇒ GlobalDivert

Constructor for ‘GlobalDivert` which allows you to pass in a `DivertListItem` to be used as the receiving number. You still need to specify the divert type.

Parameters:

  • divert_list_item (DivertListItem) (defaults to: nil)

    a ‘DivertListItem` object which will be used to fill the `GlobalDivert` number.



16
17
18
19
20
21
# File 'lib/voipfone_client/global_divert.rb', line 16

def initialize(divert_list_item = nil)
  if divert_list_item.is_a?(DivertListItem)
    @number = divert_list_item.number
  end
  super()
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



11
12
13
# File 'lib/voipfone_client/global_divert.rb', line 11

def number
  @number
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/voipfone_client/global_divert.rb', line 11

def type
  @type
end

Class Method Details

.allArray

Get current diverts

Returns:

  • (Array)

    A nested set of arrays with divert information for each type of divert currently set



49
50
51
52
53
54
55
56
57
58
# File 'lib/voipfone_client/global_divert.rb', line 49

def all
  g = self.new
  request = g.browser.get("#{VoipfoneClient::API_GET_URL}?divertsMain")
  g.parse_response(request)["divertsMain"].collect do |d|
    divert = GlobalDivert.new
    divert.number = d[1]
    divert.type = VOIPFONE_DIVERT_NAMES[d[2].downcase].to_sym
    divert
  end
end

Instance Method Details

#clear!Boolean

Clear all diverts

Returns:

  • (Boolean)

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



43
44
45
# File 'lib/voipfone_client/global_divert.rb', line 43

def clear!
  set_diverts()
end

#saveBoolean

Save the divert on your account

Returns:

  • (Boolean)

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



34
35
36
37
38
39
# File 'lib/voipfone_client/global_divert.rb', line 34

def save
  if @type.nil? || @number.nil?
    raise ArgumentError, "You need to set a divert type and divert number before you can save the divert."
  end
  set_diverts(@type => @number)
end