Module: OCRSDK::Mock
- Defined in:
- lib/ocrsdk/mock.rb
Constant Summary collapse
- MOCKS_PATH =
File.realpath(File.join(File.dirname(__FILE__), '..', '..', 'mocks'))
Class Method Summary collapse
- .in_progress ⇒ Object
- .not_enough_credits ⇒ Object
- .response(method, status) ⇒ Object
- .stub_get_task_status(response) ⇒ Object
- .stub_process_image(response) ⇒ Object
- .stub_result(response) ⇒ Object
- .success ⇒ Object
Class Method Details
.in_progress ⇒ Object
14 15 16 17 |
# File 'lib/ocrsdk/mock.rb', line 14 def in_progress success stub_get_task_status response(:get_task_status, :in_progress) end |
.not_enough_credits ⇒ Object
19 20 21 22 23 |
# File 'lib/ocrsdk/mock.rb', line 19 def not_enough_credits success stub_process_image response(:process_image, :not_enough_credits) stub_get_task_status response(:get_task_status, :not_enough_credits) end |
.response(method, status) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ocrsdk/mock.rb', line 37 def response(method, status) path = File.join(MOCKS_PATH, method.to_s, "#{status.to_s}.xml") unless File.exist? path warn "No predefined xml response for #{method}/#{status} found. Path: #{path}" end File.new(path).read end |
.stub_get_task_status(response) ⇒ Object
29 30 31 |
# File 'lib/ocrsdk/mock.rb', line 29 def stub_get_task_status(response) WebMock::API.stub_request(:get, /.*:.*@cloud.ocrsdk.com\/getTaskStatus\?taskId=.*/).to_return(body: response) end |
.stub_process_image(response) ⇒ Object
25 26 27 |
# File 'lib/ocrsdk/mock.rb', line 25 def stub_process_image(response) WebMock::API.stub_request(:post, /.*:.*@cloud.ocrsdk.com\/processImage/).to_return(body: response) end |
.stub_result(response) ⇒ Object
33 34 35 |
# File 'lib/ocrsdk/mock.rb', line 33 def stub_result(response) WebMock::API.stub_request(:get, 'http://cloud.ocrsdk.com/result_url').to_return(body: response) end |
.success ⇒ Object
8 9 10 11 12 |
# File 'lib/ocrsdk/mock.rb', line 8 def success stub_process_image response(:process_image, :success) stub_get_task_status response(:get_task_status, :completed) stub_result response(:result, :simple) end |