Module: Submail::Helper

Included in:
AddressBookMail, AddressBookMessage, MailSend, MailXSend, MessageXSend
Defined in:
lib/submail/helper.rb

Instance Method Summary collapse

Instance Method Details

#create_signatrue(request, config) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/submail/helper.rb', line 28

def create_signatrue(request, config)
  appkey = config["appkey"]
  appid = config["appid"]
  signtype = config["signtype"]
  request["sign_type"] = signtype
  keys = request.keys.sort
  values = []
  keys.each do |k|
    values << "%s=%s"%[k,request[k]]
  end
  signstr = "%s%s%s%s%s"%[appid,appkey, values.join('&'),appid, appkey]
  if signtype == "normal"
    appkey
  elsif signtype == "md5"
    Digest::MD5.hexdigest(signstr)
  else
    Digest::SHA1.hexdigest(signstr)
  end
end

#get_timestampObject



23
24
25
26
# File 'lib/submail/helper.rb', line 23

def get_timestamp
  json = JSON.parse http_get("https://api.submail.cn/service/timestamp.json")
  json["timestamp"]
end

#http_get(url) ⇒ Object



3
4
5
6
7
# File 'lib/submail/helper.rb', line 3

def http_get(url)
  uri = URI.parse(url)
  request = Net::HTTP::Get.new(uri.to_s)
  http_request(uri, request)
end

#http_post(url, postdata) ⇒ Object



9
10
11
12
13
14
# File 'lib/submail/helper.rb', line 9

def http_post(url, postdata)
  uri = URI.parse(url)
  request = Net::HTTP::Post.new(uri.to_s)
  request.set_form_data postdata
  http_request(uri, request)
end

#http_request(uri, request) ⇒ Object



16
17
18
19
20
21
# File 'lib/submail/helper.rb', line 16

def http_request(uri, request)
  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request request
  end
  response.body
end