Sha256: a543a5cabefde0cd0fc39520afc8589411025aa446d12fb2f6a75c17eecfe228
Contents?: true
Size: 914 Bytes
Versions: 6
Compression:
Stored size: 914 Bytes
Contents
module JsonApiClient class Connection attr_reader :faraday def initialize(site) @faraday = Faraday.new(site) do |builder| builder.request :url_encoded builder.use Middleware::JsonRequest builder.use Middleware::Status builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/ builder.adapter Faraday.default_adapter end yield(self) if block_given? end # insert middleware before ParseJson - middleware executed in reverse order - # inserted middleware will run after json parsed def use(middleware, *args, &block) faraday.builder.insert_before(FaradayMiddleware::ParseJson, middleware, *args, &block) end def delete(middleware) faraday.builder.delete(middleware) end def execute(query) faraday.send(query.request_method, query.path, query.params, query.headers) end end end
Version data entries
6 entries across 6 versions & 1 rubygems