Class: DevinoSms::Client
- Inherits:
-
Object
- Object
- DevinoSms::Client
- Defined in:
- lib/devino_sms.rb
Constant Summary collapse
- SMS_SERVER =
'http://rest.devinotele.com/'
Instance Attribute Summary collapse
-
#validity ⇒ Object
Returns the value of attribute validity.
Instance Method Summary collapse
- #balance ⇒ Object
- #income(start_date, finish_date) ⇒ Object
-
#initialize(login, password) ⇒ Client
constructor
A new instance of Client.
- #send(destinationAddress, sourceAddress, message, sendDate = nil) ⇒ Object
- #state(message_id) ⇒ Object
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(login, password) @session_id = session_id(login, password) self.validity = 10 end |
Instance Attribute Details
#validity ⇒ Object
Returns the value of attribute validity.
7 8 9 |
# File 'lib/devino_sms.rb', line 7 def validity @validity end |
Instance Method Details
#balance ⇒ Object
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, , sendDate = nil) query = build_query({'sendDate' => sendDate, 'destinationAddress' => destinationAddress, 'data' => , '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() response = session.get("Sms/State?#{build_query({'messageId' => })}") response.status == 200 ? JSON.parse(response.body) : raise(JSON.parse(response.body)['Desc']) end |