class AliDayu::Base
Attributes
app_key[RW]
app_secret[RW]
post_url[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ali_dayu/base.rb, line 8 def initialize(options = {}) self.app_key = options['app_key'] || AliDayu.app_key self.app_secret = options['app_secret'] || AliDayu.app_secret self.post_url = options['post_url'] || AliDayu.post_url end
Public Instance Methods
deliver(*args)
click to toggle source
# File lib/ali_dayu/base.rb, line 14 def deliver(*args) raise NotImplementedError, 'crontab must be implemented' end
Private Instance Methods
encrypt(arg)
click to toggle source
# File lib/ali_dayu/base.rb, line 25 def encrypt(arg) _arg = arg.map{|k,v| "#{k}#{v}"} ::Digest::MD5.hexdigest("#{self.app_secret}#{_arg.join("")}#{self.app_secret}").upcase end
post(uri, options)
click to toggle source
# File lib/ali_dayu/base.rb, line 30 def post(uri, options) response = "" url = URI.parse(uri) Net::HTTP.start(url.host, url.port) do |http| req = Net::HTTP::Post.new(url.path) req.set_form_data(options) response = http.request(req).body end JSON.parse(response) end
sort_options(arg)
click to toggle source
# File lib/ali_dayu/base.rb, line 19 def sort_options(arg) hash = Hash.new arg.sort.map{|e| hash[e[0]] = e[1] } hash end