Skip to content

Instantly share code, notes, and snippets.

@benaskins
Last active February 14, 2018 21:51
Show Gist options
  • Save benaskins/6c01475c14bd25954304c5132724be54 to your computer and use it in GitHub Desktop.
Save benaskins/6c01475c14bd25954304c5132724be54 to your computer and use it in GitHub Desktop.
Create overview html file for Lattice goals

Run it like this

TOKEN=your_token ruby lattice.rb

It will produce a page.html which you can then open and paste into a Google Doc or something

You can get your token by snooping on the HTML requests in Chrome dev tools. It will be as part of the authorization request header in the form "Bearer {token}".

require 'uri'
require 'net/http'
require 'openssl'
require 'json'
require 'erb'
url = URI("https://router.latticehq.com/graphql/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["origin"] = 'https://envato.latticehq.com'
request["authorization"] = "Bearer #{ENV['TOKEN']}"
request.body = "{\"query\":\"query Routes($state_0: GoalStateEnum!, $last_1: Int!) {\\n viewer {\\n ...Fl\\n }\\n}\\n\\nfragment Fa on Goal {\\n status\\n name\\n\\tdescription\\n\\tentityId\\n _childowners: ownersList {\\n name\\n }\\n\\t_metrics: metricsList {\\n\\t\\tcomplete\\n\\t\\ttitle\\n\\t}\\n}\\n\\nfragment Ff on Goal {\\n entityId\\n _metrics: metricsList {\\n complete\\n title\\n }\\n _children: children {\\n edges {\\n node {\\n ...Fa\\n }\\n }\\n }\\n}\\n\\nfragment Fk on Viewer {\\n user {\\n myGoals: ownedGoals(state: $state_0, last: $last_1) {\\n edges {\\n node {\\n status\\n name\\n\\t\\t\\t\\t\\tdescription\\n\\t\\t\\t\\t\\tentityId\\n ...Ff\\n }\\n }\\n }\\n }\\n}\\n\\nfragment Fl on Viewer {\\n ...Fk\\n}\\n\",\"variables\":{\"state_0\":\"ACTIVE\",\"last_1\":100},\"operationName\":\"Routes\"}"
response = http.request(request)
body = JSON.parse(response.body)
@goals = body['data']['viewer']['user']['myGoals']['edges']
erb_file = 'page.html.erb'
html_file = File.basename(erb_file, '.erb')
erb_str = File.read(erb_file)
renderer = ERB.new(erb_str)
result = renderer.result()
File.open(html_file, 'w') do |f|
f.write(result)
end
<html>
<head>
<title>Test</title>
</head>
<body>
<% for goal in @goals %>
<h1 style="background-color:<%= goal['node']['status'] %>"><%= goal['node']['name'] %></h1>
<p><%= goal['node']['description'] %></p>
<a href="https://envato.latticehq.com/goals/<%= goal['node']['entityId'] %>">View in Lattice</a>
<h2>Key Results</h2>
<ul>
<% for metric in goal['node']['_metrics'].sort_by { |m| m['title'] } %>
<% if metric['complete'] %>
<li><%= metric['title'] %> ✅</li>
<% else %>
<li><%= metric['title'] %></li>
<% end %>
<% end %>
</ul>
<h2>Child Goals</h2>
<% for child in goal['node']['_children']['edges'] %>
<h3 style="background-color:<%= child['node']['status'] %>"><%= child['node']['name'] %></h3>
<strong>Owner: </strong> <%= child['node']['_childowners'].first['name'] %>
<p><%= child['node']['description'] %></p>
<a href="https://envato.latticehq.com/goals/<%= child['node']['entityId'] %>">View in Lattice</a>
<h4>Key Results</h4>
<ul>
<% for metric in child['node']['_metrics'].sort_by { |m| m['title'] } %>
<% if metric['complete'] %>
<li><%= metric['title'] %> ✅</li>
<% else %>
<li><%= metric['title'] %></li>
<% end %>
<% end %>
</ul>
<% end %>
<% end %>
</body>
</html>
query Routes($state_0: GoalStateEnum!, $last_1: Int!) {
viewer {
...Fl
}
}
fragment Fa on Goal {
status
name
description
entityId
_childowners: ownersList {
name
}
_metrics: metricsList {
complete
title
}
}
fragment Ff on Goal {
entityId
_metrics: metricsList {
complete
title
}
_children: children {
edges {
node {
...Fa
}
}
}
}
fragment Fk on Viewer {
user {
myGoals: ownedGoals(state: $state_0, last: $last_1) {
edges {
node {
status
name
description
entityId
...Ff
}
}
}
}
}
fragment Fl on Viewer {
...Fk
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment