Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
贺飞灵 authored and 贺飞灵 committed Apr 16, 2013
1 parent d511f18 commit a6f8482
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/upyun/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def write_file(filepath, fd, mkdir='true')
end
end

def clear(urls)
url = 'http://purge.upyun.com/purge/'
uri = URI.parse(URI.encode(url))
urls = urls.join "\n"
Net::HTTP.start(uri.host, uri.port) do |http|
date = get_gmt_date
headers = {
'Date' => date,
'Authorization' => sign_clear(get_gmt_date, urls),
'Content-Type' => 'application/x-www-form-urlencoded'
}

http.request_post(uri.request_uri, "purge=" + URI.encode_www_form_component(urls), headers)
end
end

# 生成api使用的policy 以及 signature 可以是图片或者是文件附件 图片最大为2M 文件附件最大为5M
def api_form_params(file_type = "pic", notify_url = "", return_url = "", expire_date = 1.days)
policy_doc = {
Expand Down Expand Up @@ -83,5 +99,10 @@ def sign(method, date, url, length)
sign = "#{method}&#{url}&#{date}&#{length}&#{password}"
"UpYun #{@username}:#{Digest::MD5.hexdigest(sign)}"
end

def sign_clear(date,url)
sign = "#{url}&#{@bucketname}&#{date}&#{@password}"
"UpYun #{@bucketname}:#{@username}:#{Digest::MD5.hexdigest(sign)}"
end
end
end

0 comments on commit a6f8482

Please sign in to comment.