Skip to content

Instantly share code, notes, and snippets.

@tmzhuang

tmzhuang/test.rb Secret

Created January 24, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmzhuang/436b501689853fecc713db3b58eb7de3 to your computer and use it in GitHub Desktop.
Save tmzhuang/436b501689853fecc713db3b58eb7de3 to your computer and use it in GitHub Desktop.
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