Class: Smshelper::Api::Webtext
- Inherits:
-
Base
- Object
- Base
- Smshelper::Api::Webtext
show all
- Defined in:
- lib/smshelper/api/webtext.rb
Instance Attribute Summary
Attributes inherited from Base
#extra_options, #sent_message_ids, #sent_message_statuses
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Webtext
Returns a new instance of Webtext.
8
9
10
11
12
|
# File 'lib/smshelper/api/webtext.rb', line 8
def initialize(*args)
config = args.shift
add_query_options! :api_id => config.webtext[:uname], :api_pwd => config.webtext[:passwd]
super
end
|
Instance Method Details
#get_balance ⇒ Object
31
32
33
|
# File 'lib/smshelper/api/webtext.rb', line 31
def get_balance
{'EUR' => (post "get_balance.html").to_s.split(':').last.strip}
end
|
#get_status(message_id) ⇒ Object
35
36
37
|
# File 'lib/smshelper/api/webtext.rb', line 35
def get_status(message_id)
raise NotImplementedError, "Sms status checks unsupported by #{self.class.name}"
end
|
#send_message(message) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/smshelper/api/webtext.rb', line 14
def send_message(message)
uuid = (Digest::CRC32.hexdigest @uuid.generate).unpack('U*').collect {|x| sprintf '%02X', x}.join
if message.utf_8
message.to_hex_be
q = {:unicode => '1', :hex => message.text}
else
q = {:txt => message.text}
end
options = {:dest => message.recipient, :tag => message.sender, :msgid => uuid}
options = options.merge(@extra_options) unless @extra_options.nil?
resp = (post "send_text.html", :extra_query => options.merge(q))
process_response_code(resp.to_s) ? (@sent_message_ids << uuid; uuid) : (raise ErrorDuringSend, @response_code.webtext(resp))
end
|