whichdigital / active-rest-client

ActiveRestClient API Client
https://rubygems.org/gems/active_rest_client
MIT License
385 stars 44 forks source link

Feature request: Ability to stop request and return result in before_request #86

Open slbug opened 9 years ago

slbug commented 9 years ago

Something like this (returning false stops request):

class Post < ActiveRestClient::Base
  before_request :verify_something

  def verify_something(name, request, response)
    if some_condition?
      response.body = ''
      return false
    end

   true
  end
end

or call method to set request

class Post < ActiveRestClient::Base
  before_request :verify_something

  def verify_something(name, request)
    set_response('') if some_condition?
  end
end
andyjeffries commented 9 years ago

For the first one, I would suggest just raising an exception (because if something happens to stop the request, you'd need to know that happened so you could correct it in the calling code anyway).

The second one I like the idea of. I don't have time to work on it at the moment, but I'd support it in principle. I'd prefer something like force_response('...') over set_ as I find set_ to be quite ugly.