Class: Smshelper::Api::Smstrade
- Inherits:
-
Base
- Object
- Base
- Smshelper::Api::Smstrade
show all
- Defined in:
- lib/smshelper/api/smstrade.rb
Instance Attribute Summary
Attributes inherited from Base
#extra_options, #sent_message_ids, #sent_message_statuses
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Smstrade
Returns a new instance of Smstrade.
6
7
8
9
10
|
# File 'lib/smshelper/api/smstrade.rb', line 6
def initialize(*args)
config = args.shift
add_query_options! :key => config.smstrade[:api_key]
super
end
|
Instance Method Details
#get_balance ⇒ Object
30
31
32
33
|
# File 'lib/smshelper/api/smstrade.rb', line 30
def get_balance
resp = (post 'credits')
{'EUR' => resp.parsed_response}
end
|
#get_callback_response(args = {}) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/smshelper/api/smstrade.rb', line 39
def get_callback_response(args = {})
DeliveryReport.new(
:message_id => args['message_id'],
:timestamp => Time.now,
:delivered => ((args['status'] == 'DELIVERED') ? true : false),
:original_params => args
)
end
|
#get_status(message_id) ⇒ Object
35
36
37
|
# File 'lib/smshelper/api/smstrade.rb', line 35
def get_status(message_id)
raise NotImplementedError, "Sms status checks unsupported by #{self.class.name}"
end
|
#send_message(message) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/smshelper/api/smstrade.rb', line 12
def send_message(message)
if message.utf_8
message.to_hex_be
q = {:messagetype => 'unicode', :concat => '1', :message_id => '1'}
else
q = {:concat => '1', :message_id => '1'}
end
options = {
:to => message.recipient,
:message => message.text,
:from => message.sender}
options = options.merge(@extra_options) unless @extra_options.nil?
resp = (post '', :extra_query => options.merge(q)).split(/\n/)
process_response_code(resp.first) ? (@sent_message_ids << resp.last; resp.last) : (raise ErrorDuringSend, @response_code.smstrade(resp.first))
end
|