Class: Semaphore::Sms::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/semaphore/sms/client.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.

Raises:



15
16
17
18
# File 'lib/semaphore/sms/client.rb', line 15

def initialize(config)
  raise ConfigurationError, 'Config must have api key credentials' unless config.respond_to? :api_key
  @config = config
end

Instance Method Details

#accountObject



58
59
60
# File 'lib/semaphore/sms/client.rb', line 58

def 
  api_get("account")
end

#messages(id: nil, page: nil, limit: nil, start_date: nil, end_date: nil, network: nil, status: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/semaphore/sms/client.rb', line 46

def messages(id: nil, page: nil, limit: nil, start_date: nil, end_date: nil, network: nil, status: nil)
  options = {
    page: page,
    limit: limit,
    startDate: start_date,
    endDate: end_date,
    network: network,
    status: status
  }.compact
  api_get("messages#{id.nil? ? "" : "/#{id}"}", options)
end

#priority(message, recipients, sendername = nil) ⇒ Object

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/semaphore/sms/client.rb', line 33

def priority(message, recipients, sendername = nil)
  recipients = clean_and_validate(recipients)

  raise PhoneNumberError, 'Please verify the phonenumber' unless recipients

  options = {
    message: message,
    sendername: sendername || sender_name,
    number: recipients.kind_of?(Array) ? recipients.join(",") : recipients
  }.compact
  api_post("priority", options)
end

#send(message, recipients, sendername = nil) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/semaphore/sms/client.rb', line 20

def send(message, recipients, sendername = nil)
  recipients = clean_and_validate(recipients)

  raise PhoneNumberError, 'Please verify the phonenumber' unless recipients

  options = {
    message: message,
    sendername: sendername || sender_name,
    number: recipients
  }.compact
  api_post("messages", options)
end

#sender_names(page: nil, limit: nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/semaphore/sms/client.rb', line 70

def sender_names(page: nil, limit: nil)
  options = {
    page: page,
    limit: limit
  }.compact
  api_get("account/sendernames", options)
end

#transactions(page: nil, limit: nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/semaphore/sms/client.rb', line 62

def transactions(page: nil, limit: nil)
  options = {
    page: page,
    limit: limit
  }.compact
  api_get("account/transactions", options)
end

#users(page: nil, limit: nil) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/semaphore/sms/client.rb', line 78

def users(page: nil, limit: nil)
  options = {
    page: page,
    limit: limit
  }.compact
  api_get("account/users", options)
end