Class: Mpayer::Fetch
- Inherits:
-
Object
- Object
- Mpayer::Fetch
- Includes:
- HTTParty
- Defined in:
- lib/mpayer_ruby/fetch.rb
Class Method Summary collapse
- .get(path, options = {}, &block) ⇒ Object
- .headers ⇒ Object
- .load_json? ⇒ Boolean
- .save_json(response) ⇒ Object
Class Method Details
.get(path, options = {}, &block) ⇒ Object
26 27 28 29 |
# File 'lib/mpayer_ruby/fetch.rb', line 26 def get(path, = {}, &block) .merge!({base_uri: Mpayer.configuration.base_url}) save_json(super) end |
.headers ⇒ Object
11 12 13 |
# File 'lib/mpayer_ruby/fetch.rb', line 11 def headers Mpayer.configuration.header.merge!(super) end |
.load_json? ⇒ 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 |