Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

using Faraday with EM-Synchrony & EM-Http

View faraday-em-http.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.