Sha256: be94adf0586c8f104151128b21cf895c3bd27b71ac14bbe48bf5ac8eb748f3bd

Contents?: true

Size: 903 Bytes

Versions: 4

Compression:

Stored size: 903 Bytes

Contents

module Apidiesel
  module Handlers
    module JSON
      class RequestHandler
        include HttpRequestHelper

        def run(request, api_config)
          action = request.action

          payload = ::JSON.dump(request.parameters)

          request.metadata[:started_at] = DateTime.now

          execute_request(request: request,
                          payload: payload,
                          api_config: api_config) do |http_request|
            http_request.headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
            http_request
          end

          request.metadata[:finished_at] = DateTime.now

          if request.http_response.code == 204
            request.response_body = {}
          else
            request.response_body = ::JSON.parse(request.http_response.body)
          end

          request
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apidiesel-0.15 lib/apidiesel/handlers/json.rb
apidiesel-0.14 lib/apidiesel/handlers/json.rb
apidiesel-0.13 lib/apidiesel/handlers/json.rb
apidiesel-0.12 lib/apidiesel/handlers/json.rb