Created
January 30, 2011 01:12
-
-
Save igrigorik/802395 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::Connection.new(:url => 'http://api.postrank.com') do |builder| | |
builder.use Faraday::Adapter::EMSynchrony # 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
If using nokogiri would setting the content type to xml and using a post request with your xml document be sufficient to get this working.