require 'faraday' require 'faraday_middleware' require 'hashie/mash' require_relative 'middleware/response/raise_error' module Mailstro class Resource private def params(params) params.merge(:api_key => Mailstro.configuration.api_key) end def post(path, body = {}) connection.post(path) do |request| request.headers = { 'Content-Type' => 'application/json' } request.body = params(body) end.body end def delete(path, body = {}) connection.delete(path) do |request| request.headers = { 'Content-Type' => 'application/json' } request.body = params(body) end.body end def connection @connection ||= Faraday.new(:url => Mailstro.configuration.api_endpoint) do |faraday| faraday.use Mailstro::Middleware::Response::RaiseError faraday.request :url_encoded faraday.request :json faraday.response :mashify faraday.response :json faraday.adapter Faraday.default_adapter end end end end