Class: VoipfoneClient::DivertListItem
- Defined in:
- lib/voipfone_client/divert_list_item.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
Attributes inherited from Session
Class Method Summary collapse
-
.all ⇒ Array
Get a list of phones which can be diverted to.
Instance Method Summary collapse
-
#initialize(name: nil, number: nil) ⇒ DivertListItem
constructor
Constructor for DivertListItem which accepts the name and number of the phone number to add to the diverts list.
-
#save ⇒ Boolean
Add a new number to the list of numbers which can be diverted to.
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.
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
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/voipfone_client/divert_list_item.rb', line 3 def name @name end |
#number ⇒ Object
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
.all ⇒ Array
Get a list of phones which can be diverted to. Returns a nested array of name and phone number.
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
#save ⇒ Boolean
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.
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 |