Created
April 8, 2014 14:20
-
-
Save kbarber/10131752 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'pp' | |
def replace_catalog(catalog) | |
uri = URI.parse("http://localhost:8080/v3/commands") | |
http = Net::HTTP.new(uri.host, uri.port) | |
# request = Net::HTTP::Post.new(uri.request_uri) | |
payload = { | |
"command" => "replace catalog", | |
"version" => 4, | |
"payload" => catalog.to_json, | |
}.to_json | |
headers = { 'Accept' => '*/*', 'Content-Type' => 'application/json' } | |
response = http.request_post(uri.request_uri, payload, headers) | |
puts response.body | |
end | |
def random_string | |
(0...50).map { ('a'..'z').to_a[rand(26)] }.join | |
end | |
def random_resource | |
{ | |
"type" => "Class", | |
"title" => random_string, | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
} | |
} | |
end | |
payload1 = { | |
"name" => "host-0", | |
"version" => "3", | |
"transaction-uuid" => "foo", | |
"environment" => "giraffe", | |
"edges" => [ | |
{ | |
"source" => { | |
"type" => "Class", | |
"title" => "foo", | |
}, | |
"target" => { | |
"type" => "File", | |
"title" => "foo", | |
}, | |
"relationship" => "contains", | |
}, | |
], | |
"resources" => [ | |
{ | |
"type" => "Class", | |
"title" => "foo", | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
}, | |
}, | |
{ | |
"type" => "File", | |
"title" => "foo", | |
"exported" => false, | |
"file" => "asdf", | |
"line" => 3, | |
"tags" => ["asdf"], | |
"parameters" => { | |
}, | |
}, | |
] | |
} | |
puts "Populating data ..." | |
100.times do | |
payload1["resources"].push random_resource | |
end | |
#pp payload1 | |
puts "Submitting command now ..." | |
replace_catalog(payload1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment