Class: Musoni::Fetch
- Inherits:
-
Object
- Object
- Musoni::Fetch
- Includes:
- HTTParty
- Defined in:
- lib/musoni_ruby/fetch.rb
Class Method Summary collapse
- .date_parameters(options) ⇒ Object
- .headers ⇒ Object
- .load_json? ⇒ Boolean
- .save_json(response) ⇒ Object
Class Method Details
.date_parameters(options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/musoni_ruby/fetch.rb', line 42 def date_parameters() date_params = .select{|k,v| k.to_s.match(/Date/) or %w{Time Date DateTime}.include?(v.class.name)} if date_params.any? date_params.each do |k,v| date_params[k] = v.strftime("%d-%m-%Y") if %w{Time Date DateTime}.include?(v.class.name) end date_locale ={} date_locale[:dateFormat] ||= "dd-MM-yyyy" date_locale[:locale] ||= "en_GB" date_params.merge!(date_locale) else {} end end |
.headers ⇒ Object
11 12 13 |
# File 'lib/musoni_ruby/fetch.rb', line 11 def headers Musoni.configuration.header.merge!(super) end |
.load_json? ⇒ Boolean
37 38 39 40 |
# File 'lib/musoni_ruby/fetch.rb', line 37 def load_json? # load JSON if WebMock is off while testing and only in local env with load musoni turned on defined?(WebMock).nil? and ENV['CI_TEST'].nil? and defined?(Minitest) and ENV['LOAD_MUSONI'] == "true" end |
.save_json(response) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/musoni_ruby/fetch.rb', line 29 def save_json(response) 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/musoni_ruby/support/fake_musoni/#{model}/#{request_method}_#{file_name.join('_')}.json" File.write(file_location, response.body) end |