Skip to content

Instantly share code, notes, and snippets.

@edbond
Created June 29, 2017 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edbond/f7a00a35954f670d2327849c473eeb94 to your computer and use it in GitHub Desktop.
Save edbond/f7a00a35954f670d2327849c473eeb94 to your computer and use it in GitHub Desktop.
Spyke
class JSONParser < Faraday::Response::Middleware
def parse(body)
json = MultiJson.load(body, symbolize_keys: true)
{
data: json[:result],
metadata: json[:extra],
errors: json[:errors]
}
end
end
Spyke::Base.connection = Faraday.new(url: 'http://api.com') do |c|
c.request :json
c.use JSONParser
c.adapter Faraday.default_adapter
end
class Article < Spyke::Base
# Disabled
include_root_in_json false # { title: ... }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment