Sha256: 01208c98ec37bfdfeb346f170387bc0f476399376d662b8c92375e92fe246887

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

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 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mailstro-0.0.4 lib/mailstro/resource.rb