Sha256: 53456a10efa97da4ee3a469cf69145af3e3a90855116211a773dabfa343f0f77
Contents?: true
Size: 836 Bytes
Versions: 18
Compression:
Stored size: 836 Bytes
Contents
module DropboxApi::MiddleWare class DecodeResult < Faraday::Middleware def call(rq_env) @app.call(rq_env).on_complete do |rs_env| if !rs_env[:response_headers]['Dropbox-Api-Result'].nil? rs_env[:api_result] = decode rs_env[:response_headers]['Dropbox-Api-Result'] elsif rs_env[:response_headers]['content-type'] == 'application/json' rs_env[:api_result] = decode rs_env[:body] end end end def decode(json) # Dropbox may send a response with the string 'null' in its body, this # would be a void result. `add_folder_member` is an example of an # endpoint without return values. if json == "null" {} else JSON.parse json end end end Faraday::Response.register_middleware :decode_result => DecodeResult end
Version data entries
18 entries across 18 versions & 1 rubygems