class Endpointer::ResourceExecutor

Public Instance Methods

perform(request, resource, options) click to toggle source
# File lib/endpointer/resource_executor.rb, line 7
def perform(request, resource, options)
  begin
    cache(options.cache_dir).get(resource, get_request_body(request))
  rescue Endpointer::Errors::CachedItemNotFoundError
    response = Endpointer::PerformerFactory.create(resource.method).execute(request, resource)
    cache(options.cache_dir).set(resource, get_request_body(request), response)
    response
  end
end

Private Instance Methods

cache(cache_dir) click to toggle source
# File lib/endpointer/resource_executor.rb, line 19
def cache(cache_dir)
  @cache ||= Endpointer::Cacher.new(cache_dir)
end
get_request_body(request) click to toggle source
# File lib/endpointer/resource_executor.rb, line 23
def get_request_body(request)
  request_body = request.body.read
  request.body.rewind
  request_body
end