Class: SinchSms

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

Class Method Summary collapse

Class Method Details

.send(key, secret, message, to) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sinch_sms.rb', line 9

def self.send(key, secret, message, to)
  body = "{\"message\":\"#{message}\"}"
  timestamp = Time.now.iso8601
  authorization = auth(key, secret, "/v1/sms/#{to}", "POST", timestamp,  body)

  uri = URI.parse("https://messagingApi.sinch.com/v1/sms/" + to)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  headers = {"content-type" => "application/json", "x-timestamp" => timestamp, "authorization" => authorization}
  request = Net::HTTP::Post.new(uri.request_uri)
  request.initialize_http_header(headers)
  request.body = body
  return JSON.parse(http.request(request).body)
end

.status(key, secret, id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sinch_sms.rb', line 25

def self.status(key, secret, id)
  timestamp = Time.now.iso8601
  authorization = self.auth(key, secret, "/v1/message/status/#{id}", "GET", timestamp)

  uri = URI.parse("https://messagingApi.sinch.com/v1/message/status/" + id)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  headers = {"content-type" => "application/json", "x-timestamp" => timestamp, "authorization" => authorization}
  request = Net::HTTP::Get.new(uri.request_uri)
  request.initialize_http_header(headers)

  return JSON.parse(http.request(request).body)
end