Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created January 30, 2011 01:12
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save igrigorik/802395 to your computer and use it in GitHub Desktop.
Save igrigorik/802395 to your computer and use it in GitHub Desktop.
using Faraday with EM-Synchrony & EM-Http
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
@adamrobbie
Copy link

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