Sha256: d143afda639c914b076014efd5fa4c4c6d4da15c8f8557545b9ecffa4911ebf2

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

require_relative '../helpers/application_helper'
module AsanaExceptionNotifier
  module Request
    # middleware used only in development for testing purpose
    class Middleware
      include AsanaExceptionNotifier::ApplicationHelper
      # Method that is used to debug requests to API's
      # The method receives the request object and prints it content to console
      #
      # @param [EventMachine::HttpRequest] client The Http request made to an API
      # @param [Hash] head The http headers sent to API
      # @param [String, nil] body The body sent to API
      # @return [Array<Hash,String>] Returns the http headers and the body
      def request(client, head, body)
        puts "############## HTTP REQUEST  #####################\n"
        puts JSON.pretty_generate(
          headers: head,
          url: client.req.uri,
          body: force_utf8_encoding(body.to_s.inspect)
        )
        [head, body]
      end

      # Method that is used to debug responses from API's
      # The method receives the response object and prints it content to console
      #
      # @param [EventMachine::HttpResponse] resp The Http response received from API
      # @return [EventMachine::HttpResponse]
      def response(resp)
        puts "############## HTTP RESPONSE  #####################\n"
        headers = resp.response_header
        puts JSON.pretty_generate(
          headers: headers,
          status: headers.status,
          body: force_utf8_encoding(resp.response.to_s.inspect)
        )
        resp
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
asana_exception_notifier-0.2.2 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.2.1 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.2.0 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.1.0 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.9 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.8 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.7 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.6 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.5 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.4 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.3 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.2 lib/asana_exception_notifier/request/middleware.rb
asana_exception_notifier-0.0.1 lib/asana_exception_notifier/request/middleware.rb