Class: SmsBroker::StatusRequester

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ StatusRequester

Returns a new instance of StatusRequester.



6
7
8
# File 'lib/sms_broker/status_requester.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/sms_broker/status_requester.rb', line 3

def client
  @client
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/sms_broker/status_requester.rb', line 3

def errors
  @errors
end

Instance Method Details

#requestObject



16
17
18
19
20
21
22
# File 'lib/sms_broker/status_requester.rb', line 16

def request
  unless valid?
    return Client::Response::Error.new(client.name, errors, errors)
  end

  client.message_status(build_request)
end

#status(message_id) ⇒ Object



10
11
12
13
14
# File 'lib/sms_broker/status_requester.rb', line 10

def status(message_id)
  @message_id = message_id

  self
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/sms_broker/status_requester.rb', line 24

def valid?
  schema = { message_id: Compel.string.required }

  result = Compel.hash.keys(schema).validate(build_request)

  @errors = result.errors

  result.valid?
end