Class: SmsBroker::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_broker/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Service

Returns a new instance of Service.



41
42
43
# File 'lib/sms_broker/service.rb', line 41

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



39
40
41
# File 'lib/sms_broker/service.rb', line 39

def client
  @client
end

Class Method Details

.get(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sms_broker/service.rb', line 19

def self.get(name)
  options = service_configuration(name)

  result = Service.validate(name, options)

  unless result.valid?
    raise Exceptions::InvalidService, name.to_sym => result.errors
  end

  new CLIENTS[name.to_sym].new(options)
end

.service_configuration(name) ⇒ Object



31
32
33
# File 'lib/sms_broker/service.rb', line 31

def self.service_configuration(name)
  SmsBroker.configuration[:services_setups][name.to_sym]
end

.validate(name, options) ⇒ Object



35
36
37
# File 'lib/sms_broker/service.rb', line 35

def self.validate(name, options)
  Setup.service_validation_schemas[name.to_sym].validate(options)
end

Instance Method Details

#message(message) ⇒ Object



45
46
47
# File 'lib/sms_broker/service.rb', line 45

def message(message)
  MessageSender.new(client).message(message)
end

#status(message_id) ⇒ Object



53
54
55
# File 'lib/sms_broker/service.rb', line 53

def status(message_id)
  StatusRequester.new(client).status(message_id)
end

#voice_message(message) ⇒ Object

could have another params like lang



49
50
51
# File 'lib/sms_broker/service.rb', line 49

def voice_message(message) #could have another params like lang
  VoiceMessageSender.new(client).message(message)
end