Class: Coolsms::Client
- Inherits:
-
Object
- Object
- Coolsms::Client
- Defined in:
- lib/coolsms/client.rb
Constant Summary collapse
- COOLSMS_URL =
"https://api.coolsms.co.kr/1/send"
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #send_message(options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/coolsms/client.rb', line 10 def initialize() raise ArgumentError.new "sender must not be nil" unless [:sender] raise ArgumentError.new "api_key must not be nil" unless [:api_key] raise ArgumentError.new "api_secret must not be nil" unless [:api_secret] @api_key = [:api_key] @api_secret = [:api_secret] @sender = [:sender] end |
Instance Method Details
#send_message(options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/coolsms/client.rb', line 20 def () raise ArgumentError.new "to must not be nil" unless [:to] raise ArgumentError.new "text must not be nil" unless [:text] ts = slt = salt signature = signature(ts,slt) type = [:text].bytesize > 80 ? 'LMS' : 'SMS' body = { :api_key => @api_key, :type => type, :salt => slt, :signature => signature, :to => [:to], :timestamp => ts, :from => @sender, :text => [:text] } if type == 'LMS' body.merge! :subject => [:subject] ? [:subject] : "" end res = HTTParty.post(COOLSMS_URL, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :body => body) parse_response res end |