Class: SmsRu::Stoplist

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_ru/stoplist.rb

Overview

Manages the account stoplist (numbers that never receive messages and are never charged). Reached via SmsRu#stoplist, e.g. ‘client.stoplist.add(…)`.

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Stoplist

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Stoplist.

Parameters:

  • request (Method)

    the client’s bound ‘request` method



9
10
11
# File 'lib/sms_ru/stoplist.rb', line 9

def initialize(request)
  @request = request
end

Instance Method Details

#add(phone, note: nil) ⇒ Boolean

Adds a number to the stoplist. ‘note` is visible only to you.

Parameters:

  • phone (String, Integer)

    the number to stoplist

  • note (String, nil) (defaults to: nil)

    an optional private note

Returns:

  • (Boolean)

    true on success

Raises:



19
20
21
22
# File 'lib/sms_ru/stoplist.rb', line 19

def add(phone, note: nil)
  @request.call("/stoplist/add", stoplist_phone: phone.to_s, stoplist_text: note.to_s)
  true
end

#listArray<SmsRu::StoplistEntry>

Returns every stoplisted number as an Array of SmsRu::StoplistEntry.

Returns:

Raises:



38
39
40
41
# File 'lib/sms_ru/stoplist.rb', line 38

def list
  data = @request.call("/stoplist/get")
  Coerce.records(data["stoplist"]).map { |phone, note| StoplistEntry.new(phone: String(phone), note: String(note)) }
end

#remove(phone) ⇒ Boolean

Removes a number from the stoplist.

Parameters:

  • phone (String, Integer)

    the number to remove

Returns:

  • (Boolean)

    true on success

Raises:



29
30
31
32
# File 'lib/sms_ru/stoplist.rb', line 29

def remove(phone)
  @request.call("/stoplist/del", stoplist_phone: phone.to_s)
  true
end