Class: Rpdoc::PostmanResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rpdoc/postman_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rspec_example, rspec_request, rspec_response) ⇒ PostmanResponse

Returns a new instance of PostmanResponse.



9
10
11
12
13
14
15
16
# File 'lib/rpdoc/postman_response.rb', line 9

def initialize(rspec_example, rspec_request, rspec_response)
  @rspec_example = rspec_example
  @rspec_request = rspec_request
  @rspec_response = rspec_response
  @configuration = Rpdoc.configuration

  @data = response_data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/rpdoc/postman_response.rb', line 7

def data
  @data
end

Instance Method Details

#saveObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rpdoc/postman_response.rb', line 18

def save
  root_path ||= @configuration.rpdoc_root
  folder_path = "#{root_path}/#{@rspec_example.[:rpdoc_example_folders].join('/')}/#{@rspec_example.[:rpdoc_action_key]}"
  FileUtils.mkdir_p(folder_path) unless File.exists?(folder_path)

  request_file_path = "#{folder_path}/#{@configuration.rpdoc_request_filename}"
  File.open(request_file_path, 'w+') { |f| f.write(JSON.pretty_generate(request_data)) } unless File.exists?(request_file_path)

  response_file_path = "#{folder_path}/#{@rspec_example.[:rpdoc_example_key]}.json"
  File.open(response_file_path, 'w+') { |f| f.write(JSON.pretty_generate(response_data)) }
end