-
-
Save tmzhuang/436b501689853fecc713db3b58eb7de3 to your computer and use it in GitHub Desktop.
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 'net/http' | |
require 'json' | |
BASE = "https://api.hubapi.com" | |
HAPIKEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |
WORKFLOW_ENDPOINT = "/automation/v3/workflows" | |
WORKFLOW_ID = "/1663717" | |
def get_workflow | |
uri = URI(BASE + WORKFLOW_ENDPOINT + WORKFLOW_ID) | |
params = { hapikey: HAPIKEY } | |
uri.query = URI.encode_www_form(params) | |
puts "original uri: #{uri}" | |
res = Net::HTTP.get(uri) | |
#puts res.body if res.is_a?(Net::HTTPSuccess) | |
hash = JSON.parse(res) | |
end | |
def post_workflow(workflow) | |
json = workflow.to_json | |
header = {"User-Agent" => "rubytest/0.1", | |
"Content-Type" => "application/json"} | |
uri = URI(BASE + WORKFLOW_ENDPOINT) | |
params = { hapikey: HAPIKEY } | |
uri.query = URI.encode_www_form(params) | |
puts uri | |
res = Net::HTTP.post uri, json, header | |
puts res.body | |
end | |
if __FILE__ == $0 | |
workflow = get_workflow | |
workflow['name'] = "test2" | |
actions = workflow['actions'] | |
actions.each do |action| | |
if action["type"] == "DELAY" | |
action["delayMillis"] = "120000" | |
end | |
end | |
post_workflow(workflow) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment