Skip to content
Browse files

Makes response JSON parsing use MultiJson

  • Loading branch information...
1 parent f937ea4 commit 9cfb5aca1c50774ee4423bbddf604ffa5ab8e77f @vesan committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/kippt/connection.rb
View
13 lib/kippt/connection.rb
@@ -1,6 +1,17 @@
require "multi_json"
+require "faraday_middleware/response_middleware"
module Kippt::Connection
+ class ParseMultiJson < FaradayMiddleware::ResponseMiddleware
+ define_parser do |body|
+ begin
+ MultiJson.load(body) unless body.strip.empty?
+ rescue MultiJson::DecodeError
+ nil
+ end
+ end
+ end
+
def get(url, options = {})
request(:get, url, options)
end
@@ -21,7 +32,7 @@ def delete(url, options = {})
def connection
@connection ||= Faraday.new("https://kippt.com/api") do |builder|
- builder.use FaradayMiddleware::ParseJson
+ builder.use Kippt::Connection::ParseMultiJson
# builder.use Faraday::Response::Logger
builder.adapter Faraday.default_adapter
end

0 comments on commit 9cfb5ac

Please sign in to comment.
Something went wrong with that request. Please try again.