lib/stub_requests/api.rb in stub_requests-0.1.3 vs lib/stub_requests/api.rb in stub_requests-0.1.4

- old
+ new

@@ -45,37 +45,23 @@ # # @return [Service] a new service or a previously registered service # # :reek:UtilityFunction def register_service(service_id, service_uri, &block) - StubRequests::Registration.register_service(service_id, service_uri, &block) + StubRequests::ServiceRegistry.register_service(service_id, service_uri, &block) end # # Stub a request to a registered service endpoint # # # @param [Symbol] service_id the id of a registered service # @param [Symbol] endpoint_id the id of a registered endpoint - # @param [Hash<Symbol>] uri_replacements a list of URI replacements - # @param [Hash<Symbol>] options - # @option options [optional, Hash<Symbol>] :request webmock request options - # @option options [optional, Hash<Symbol>] :response webmock response options - # @option options [optional, Array, Exception, StandardError, String] :error webmock error to raise - # @option options [optional, TrueClass] :timeout set to true to raise some kind of timeout error + # @param [Hash<Symbol>] route_params a map with route parameters # # @note the kind of timeout error raised by webmock is depending on the HTTP client used # - # @example Stub a request to a registered service endpoint - # register_stub( - # :google_api, - # :get_map_location, - # {}, # No URI replacements needed for this endpoint - # { request: { headers: { "Accept" => "application/json" }}}, - # { response: { body: { id: "abyasdjasd", status: "successful" }}} - # ) - # # @example Stub a request to a registered service endpoint using block version # register_stub(:documents, :index) do # with(headers: { "Accept" => "application/json" }}}) # to_return(body: "No content", status: 204) # end @@ -83,12 +69,12 @@ # @see #stub_http_request # @return [WebMock::RequestStub] a mocked request # # :reek:UtilityFunction # :reek:LongParameterList { max_params: 5 } - def stub_endpoint(service_id, endpoint_id, uri_replacements = {}, options = {}, &callback) - StubRequests::Registration.stub_endpoint(service_id, endpoint_id, uri_replacements, options, &callback) + def stub_endpoint(service_id, endpoint_id, route_params = {}, &callback) + StubRequests::ServiceRegistry.stub_endpoint(service_id, endpoint_id, route_params, &callback) end # # Subscribe to notifications for a service endpoint # @@ -99,12 +85,12 @@ # # @return [void] # # :reek:UtilityFunction # :reek:LongParameterList - def subscribe_to(service_id, endpoint_id, verb, callback) - StubRequests::Observable.subscribe_to(service_id, endpoint_id, verb, callback) + def register_callback(service_id, endpoint_id, verb, callback) + StubRequests::CallbackRegistry.register(service_id, endpoint_id, verb, callback) end # # Unsubscribe from notifications for a service endpoint # @@ -112,10 +98,10 @@ # @param [Symbol] endpoint_id the id of an endpoint # # @return [void] # # :reek:UtilityFunction - def unsubscribe_from(service_id, endpoint_id, verb) - StubRequests::Observable.unsubscribe_from(service_id, endpoint_id, verb) + def unregister_callback(service_id, endpoint_id, verb) + StubRequests::CallbackRegistry.unregister(service_id, endpoint_id, verb) end end end