-
-
Save kgrz/4051485 to your computer and use it in GitHub Desktop.
using Faraday with EM-Synchrony & EM-Http
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 'net/http' | |
require 'pp' | |
# Repos: | |
# https://github.com/technoweenie/faraday | |
# https://github.com/pengwynn/faraday_middleware | |
# Blog posts: | |
# http://adventuresincoding.com/2010/09/writing-modular-http-client-code-with-faraday | |
# http://wynnnetherland.com/projects/faraday-middleware | |
conn = Faraday.new(:url => 'http://api.postrank.com') do |builder| | |
builder.adapter :em_synchrony # make http request with eventmachine and synchrony | |
builder.use Faraday::Response::Yajl # parse body with yajl | |
end | |
resp = conn.get do |req| | |
req.url "/v2/feed/info?appkey=demokey&format=json&id=igvita.com" | |
end | |
pp resp | |
puts | |
# Set EM-Synchrony to be default drive + parse JSON responses | |
Faraday.default_connection = Faraday::Connection.new do |builder| | |
builder.use Faraday::Adapter::EMSynchrony | |
builder.use Faraday::Response::Yajl | |
end | |
resp = Faraday.get "http://api.postrank.com/v2/feed/info?appkey=demokey&format=json&id=igvita.com" | |
pp resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment