Skip to content

Instantly share code, notes, and snippets.

@OsQu
Created February 11, 2014 15:11
Show Gist options
  • Save OsQu/8936656 to your computer and use it in GitHub Desktop.
Save OsQu/8936656 to your computer and use it in GitHub Desktop.
Authorize flowdock with OAUTH and list flows
require 'sinatra'
require 'faraday'
require 'multi_json'
get "/" do
send_file 'initial.html'
end
get "/callback" do
conn = Faraday.new(url: "https://api.flowdock.com/")
response = conn.post do |req|
req.url("/oauth/token")
req.headers["Content-Type"] = "application/json"
req.body = MultiJson.dump({
client_id: "MY_CLIENT_ID",
client_secret: "MY_CLIENT_SECRET",
code: params[:code],
redirect_uri: "http://localhost:4567/callback",
grant_type: "authorization_code"
})
end
@access_token = MultiJson.load(response.body)["access_token"]
erb :list
end
<html>
<body>
<a href="https://www.flowdock.com/oauth/authorize?client_id=MY_CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost%3A4567%2Fcallback&response_type=code">Authorize</a>
</body>
</html>
<html>
<body>
<ul id="list">
</ul>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$.ajax({
url: "https://api.flowdock.com/flows",
type: "GET",
headers: { "Authorization": "Bearer <%= @access_token %>" }
}).done(function(flows) {
$.each(flows, function(index, flow) {
$("#list").append($("<li>").text(flow.name));
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment