class Swgr2rb::SwaggerJsonFetcher

SwaggerJsonFetcher fetches a Swagger JSON given its path. Since the path can either be a URL of Swagger or a path to a .json file, SwaggerJsonFetcher either makes a GET request to the given URL and returns its response, or reads and parses a specified .json file.

Public Class Methods

get_swagger_json(path) click to toggle source
# File lib/json_fetcher/swagger_json_fetcher.rb, line 14
def get_swagger_json(path)
  if URI.extract(path).present?
    send_request_to_swagger(path)
  else
    read_file(path)
  end
end

Private Class Methods

generate_request_to_swagger(endpoint_path) click to toggle source
# File lib/json_fetcher/swagger_json_fetcher.rb, line 37
def generate_request_to_swagger(endpoint_path)
  Request.new(endpoint_path,
              'get',
              nil,
              nil)
end
read_file(file_path) click to toggle source
# File lib/json_fetcher/swagger_json_fetcher.rb, line 30
def read_file(file_path)
  JSON.parse(File.read(file_path))
rescue IOError, JSON::ParserError
  raise Swgr2rbError,
        "An error occurred while trying to read JSON file '#{file_path}'"
end
send_request_to_swagger(endpoint_path) click to toggle source
# File lib/json_fetcher/swagger_json_fetcher.rb, line 24
def send_request_to_swagger(endpoint_path)
  request = generate_request_to_swagger(endpoint_path)
  response = ConductorSender.send_request(request)
  response.body
end