Created
May 15, 2017 08:27
-
-
Save ryanchang/321da4683f215b895eaa175c44e927e2 to your computer and use it in GitHub Desktop.
GrowingIO原始数据导出
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'openssl' | |
require 'rest-client' | |
require 'json' | |
def auth_token(secret, project, ai, tm) | |
message = ("POST\n/auth/token\nproject=" + project + "&ai=" + ai + "&tm=" + tm).encode("utf-8") | |
digest = OpenSSL::Digest.new('sha256') | |
OpenSSL::HMAC.hexdigest(digest, secret.encode("utf-8"), message) | |
end | |
# 公钥,私钥及AI可在"项目管理" -> "项目配置" -> "CS属性"获取,项目UID可在当前项目URL中获取 | |
public_key = "<公钥>" | |
secret = "<私钥>" | |
project = "<项目UID>" | |
ai = "<项目ID>" | |
tm = DateTime.now.strftime('%Q') | |
auth = auth_token(secret, project, ai, tm) | |
url = "https://www.growingio.com/auth/token" | |
headers = {"X-Client-Id" => public_key} | |
payload = {"project" => project, "ai" => ai, "tm" => tm, "auth" => auth} | |
begin | |
res = RestClient.post(url, payload ,headers) | |
result = JSON::parse res.body | |
if result["status"] == "success" | |
p result["code"] | |
end | |
rescue RestClient::ExceptionWithResponse => e | |
puts e | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment