Created
January 31, 2013 20:17
-
-
Save sorentwo/4686049 to your computer and use it in GitHub Desktop.
Conflating Separate URLs
This file contains 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
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'] } |
This file contains 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
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