Created
June 29, 2017 13:26
-
-
Save edbond/f7a00a35954f670d2327849c473eeb94 to your computer and use it in GitHub Desktop.
Spyke
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
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