Class: SmsRu::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_ru.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ SMS

Returns a new instance of SMS.



6
7
8
9
10
11
# File 'lib/sms_ru.rb', line 6

def initialize(params)
  @api_id = params[:api_id]
  @login = params[:login]
  @password = params[:password]
  @auth_token_expire = nil
end

Instance Method Details

#auth_tokenObject



29
30
31
32
33
34
35
# File 'lib/sms_ru.rb', line 29

def auth_token
  if @auth_token_expire < Time.now
    renew_auth_token
  else
    @auth_token
  end
end

#send(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sms_ru.rb', line 13

def send(params)
  query_params = ""
  params.each do |key, value|
    query_params += "&#{key.to_s}=#{URI::encode(value.to_s)}"
  end
  if @api_id.nil?
    require 'digest/sha2'
    hash = Digest::SHA512.hexdigest(@password+auth_token+@api_id)
    uri = URI.parse("http://sms.ru/sms/send?api_id=#@api_id#{query_params}")
  else
    uri = URI.parse("http://sms.ru/sms/send?api_id=#@api_id#{query_params}")
    response = Net::HTTP.get_response(uri)
    response.body.split("\n").first
  end
end