Class: DummyService

Inherits:
Service show all
Defined in:
app/service_adaptors/dummy_service.rb

Overview

A Dummy service that may be useful for testing (manual or perhaps in automated tests), that simply creates the responses you tell it to, after sleeping the amount you tell it to.

DummyService:
  type: DummyService
  priority: 3
  sleep: 4.5 # seconds
  responses:
    - service_type_value: fulltext
      display_text: foo
      url: http://google.com
    - service_type_value: highlighted_link
      display_text: bar
      url: http://amazon.com

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary collapse

Attributes inherited from Service

#group, #name, #priority, #request, #service_id, #status, #task, #url

Instance Method Summary collapse

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config = {}) ⇒ DummyService

Returns a new instance of DummyService.



21
22
23
24
25
# File 'app/service_adaptors/dummy_service.rb', line 21

def initialize(config = {})
  self.responses = []
  self.sleep = 0
  super
end

Instance Attribute Details

#responsesObject

Returns the value of attribute responses.



19
20
21
# File 'app/service_adaptors/dummy_service.rb', line 19

def responses
  @responses
end

#sleepObject

Returns the value of attribute sleep.



19
20
21
# File 'app/service_adaptors/dummy_service.rb', line 19

def sleep
  @sleep
end

Instance Method Details

#handle(request) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'app/service_adaptors/dummy_service.rb', line 31

def handle(request)
  
  ::Kernel.sleep( self.sleep ) if self.sleep
  
  responses.each do |response|   
    request.add_service_response( { :service => self }.merge(response.symbolize_keys ) )
  end
  
  return request.dispatched(self, true)
end

#service_types_generatedObject



27
28
29
# File 'app/service_adaptors/dummy_service.rb', line 27

def service_types_generated
  responses.collect {|r| ServiceTypeValue[ r["service_type_value"] ]}.compact.uniq
end