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

- old
+ new

@@ -19,19 +19,10 @@ module API # extends "self" # @!parse extend self extend self - # :reek:LongParameterList { max_params: 4 } - # @api private - def self._stub_endpoint(service_id, endpoint_id, uri_replacements = {}, options = {}) - _service, endpoint, uri = StubRequests::URI.for_service_endpoint(service_id, endpoint_id, uri_replacements) - endpoint_stub = WebMock::Builder.build(endpoint.verb, uri, options) - - ::WebMock::StubRegistry.instance.register_request_stub(endpoint_stub) - end - # :nodoc: def self.included(base) base.send(:extend, self) end @@ -54,13 +45,11 @@ # # @return [Service] a new service or a previously registered service # # :reek:UtilityFunction def register_service(service_id, service_uri, &block) - service = ServiceRegistry.instance.register(service_id, service_uri) - Docile.dsl_eval(service.endpoints, &block) if block.present? - service + StubRequests::Registration.register_service(service_id, service_uri, &block) end # # Stub a request to a registered service endpoint # @@ -95,13 +84,38 @@ # @return [WebMock::RequestStub] a mocked request # # :reek:UtilityFunction # :reek:LongParameterList { max_params: 5 } def stub_endpoint(service_id, endpoint_id, uri_replacements = {}, options = {}, &callback) - service, endpoint, uri = StubRequests::URI.for_service_endpoint(service_id, endpoint_id, uri_replacements) - endpoint_stub = WebMock::Builder.build(endpoint.verb, uri, options, &callback) + StubRequests::Registration.stub_endpoint(service_id, endpoint_id, uri_replacements, options, &callback) + end - Metrics.record(service, endpoint, endpoint_stub) - ::WebMock::StubRegistry.instance.register_request_stub(endpoint_stub) + # + # Subscribe to notifications for a service endpoint + # + # @param [Symbol] service_id the id of a service + # @param [Symbol] endpoint_id the id of an endpoint + # @param [Symbol] verb an HTTP verb/method + # @param [Proc] callback a Proc to call when receiving response + # + # @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) + end + + # + # Unsubscribe from notifications for a service endpoint + # + # @param [Symbol] service_id the id of a service + # @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) end end end