Class: DevinoSms::Client

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

Constant Summary collapse

SMS_SERVER =
'http://rest.devinotele.com/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login, password) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/devino_sms.rb', line 11

def initialize(, password)
  @session_id   = session_id(, password)
  self.validity = 10
end

Instance Attribute Details

#validityObject

Returns the value of attribute validity.



7
8
9
# File 'lib/devino_sms.rb', line 7

def validity
  @validity
end

Instance Method Details

#balanceObject



33
34
35
36
37
# File 'lib/devino_sms.rb', line 33

def balance
  response = session.get("User/Balance?#{build_query}")

  response.status == 200 ? response.body.to_f : raise(JSON.parse(response.body)['Desc'])
end

#income(start_date, finish_date) ⇒ Object



39
40
41
42
43
44
# File 'lib/devino_sms.rb', line 39

def income(start_date, finish_date)
  response = session.get("Sms/In?#{build_query({'minDateUTC' => start_date,
                                                'maxDateUTC' => finish_date})}")

  response.status == 200 ? JSON.parse(response.body) : raise(JSON.parse(response.body)['Desc'])
end

#send(destinationAddress, sourceAddress, message, sendDate = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/devino_sms.rb', line 16

def send(destinationAddress, sourceAddress, message, sendDate = nil)
  query =  build_query({'sendDate'           => sendDate,
                        'destinationAddress' => destinationAddress,
                        'data'               => message,
                        'sourceAddress'      => sourceAddress,
                        'validity'           => validity}, true)

  response = session.post("Sms/Send", query)
  response.status == 200 ? JSON.parse(response.body) : raise(JSON.parse(response.body)['Desc'])
end

#state(message_id) ⇒ Object



27
28
29
30
31
# File 'lib/devino_sms.rb', line 27

def state(message_id)
  response = session.get("Sms/State?#{build_query({'messageId' => message_id})}")

  response.status == 200 ? JSON.parse(response.body) : raise(JSON.parse(response.body)['Desc'])
end