class Supercast::Client::FaradaySupercastEncoder
Used to workaround buggy behavior in Faraday: the library will try to reshape anything that we pass to `req.params` with one of its default encoders. I don't think this process is supposed to be lossy, but it is – in particular when we send our integer-indexed maps (i.e. arrays), Faraday ends up stripping out the integer indexes.
We work around the problem by implementing our own simplified encoder and telling Faraday to use that.
The class also performs simple caching so that we don't have to encode parameters twice for every request (once to build the request and once for logging).
When initialized with `multipart: true`, the encoder just inspects the hash instead to get a decent representation for logging. In the case of a multipart request, Faraday won't use the result of this encoder.
Public Class Methods
# File lib/supercast/client.rb, line 212 def initialize @cache = {} end
Public Instance Methods
We should never need to do this so it's not implemented.
# File lib/supercast/client.rb, line 225 def decode(_str) raise NotImplementedError, "#{self.class.name} does not implement #decode" end
This is quite subtle, but for a `multipart/form-data` request Faraday will throw away the result of this encoder and build its body.
# File lib/supercast/client.rb, line 218 def encode(hash) @cache.fetch(hash) do |k| @cache[k] = Util.encode_parameters(hash) end end