Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created January 31, 2013 20:17
Show Gist options
  • Save sorentwo/4686049 to your computer and use it in GitHub Desktop.
Save sorentwo/4686049 to your computer and use it in GitHub Desktop.
Conflating Separate URLs
require 'faraday'
require 'json'
connection = Faraday.new
headers = { 'Content-Type' => 'application/json', 'Accepts' => 'application/json', 'Authorization' => 'token TOKEN' }
likes = connection.get do |req|
req.url 'http://localhost:3000/api/likes'
req.headers = headers
end
comments = connection.get do |req|
req.url 'http://localhost:3000/api/comments'
req.headers = headers
end
messages = connection.get do |req|
req.url 'http://localhost:3000/api/messages'
req.headers = headers
end
feed = [comments + likes + messages]
.map { |body| JSON.parse(body) }
.sort_by { |hash| hash['created_at'] }
require 'faraday'
require 'json'
connection = Faraday.new
headers = { 'Content-Type' => 'application/json', 'Accepts' => 'application/json', 'Authorization' => 'token TOKEN' }
events = connection.get do |req|
req.url 'http://localhost:3000/api/events'
req.headers = headers
end
JSON.parse(events)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment