Class: Mpayer::Fetch

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mpayer_ruby/fetch.rb

Class Method Summary collapse

Class Method Details

.get(path, options = {}, &block) ⇒ Object



26
27
28
29
# File 'lib/mpayer_ruby/fetch.rb', line 26

def get(path, options = {}, &block)
	options.merge!({base_uri: Mpayer.configuration.base_url})
	save_json(super)
end

.headersObject



11
12
13
# File 'lib/mpayer_ruby/fetch.rb', line 11

def headers
	Mpayer.configuration.header.merge!(super)
end

.load_json?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/mpayer_ruby/fetch.rb', line 42

def load_json?
	# load JSON if WebMock is off while testing and only in local env with load mpayer turned on
	defined?(WebMock).nil? and ENV['CI_TEST'].nil? and defined?(Minitest) and ENV['LOAD_MPAYER'] == "true"
end

.save_json(response) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/mpayer_ruby/fetch.rb', line 31

def save_json(response)
	if load_json?
		request_method = response.request.http_method.name.split('::').last.upcase
		file_path = response.request.path.to_s
		slash,model,*file_name = file_path.split('?')[0].split(/\/|\?/)
		file_location = "lib/mpayer_ruby/support/fake_mpayer/#{model}/#{request_method}_#{file_name.join('_')}.json"
		File.write(file_location, response.body)
	end
	response
end