Class: SMSAero
- Inherits:
-
Object
show all
- Defined in:
- lib/smsaero.rb
Constant Summary
collapse
- URL =
'https://gate.smsaero.ru/%{action}'
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ SMSAero
Returns a new instance of SMSAero.
6
7
8
9
10
11
12
13
|
# File 'lib/smsaero.rb', line 6
def initialize(*args)
options = args.
raise 'User and password should be provided!' unless options[:user] && options[:password]
@user = options[:user]
@password_hash = Digest::MD5.hexdigest(options[:password])
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(action, *args, &block) ⇒ Object
19
20
21
|
# File 'lib/smsaero.rb', line 19
def method_missing(action, *args, &block)
process_request(action, *args, &block)
end
|
Instance Method Details
#process_request(action, *args, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/smsaero.rb', line 23
def process_request(action, *args, &block)
options = args.
options.reverse_merge! answer: :json
uri = URI(URL % { action: action })
uri.query = URI.encode_www_form options
result = Net::HTTP.post_form uri, user: @user, password: @password_hash
JSON.parse(result.body)
end
|
#send_message(options = {}) ⇒ Object
15
16
17
|
# File 'lib/smsaero.rb', line 15
def send_message(options={})
process_request :send, options
end
|