module ApiProblem

Constants

MissingProblemType
MissingTitle
VERSION

Public Class Methods

build(problem_type, title, options={}) click to toggle source
# File lib/api_problem.rb, line 8
def self.build(problem_type, title, options={})
  response ={}
  raise ApiProblem::MissingProblemType if problem_type.nil?
  raise ApiProblem::MissingTitle if title.nil?
  new_options = build_options(options)
  unless new_options.empty?
    { problemType: problem_type, title: title }.merge(new_options)
  else
    { problemType: problem_type, title: title }
  end
end

Private Class Methods

build_options(options) click to toggle source
# File lib/api_problem.rb, line 25
def self.build_options(options)
  new_options ={}
  options.each do |key, value|
    key = convert_key(key)
    value = convert_value(key, value)
    new_options[key] = value
  end
  new_options
end
convert_key(key) click to toggle source
# File lib/api_problem.rb, line 35
def self.convert_key(key)
  if key == :http_status || key == "http_status"
    key = "httpStatus"
  elsif key == :problem_instance || key == "problem_instance"
    key = "problemInstance"
  end
  key.to_s
end
convert_value(key, value) click to toggle source
# File lib/api_problem.rb, line 44
def self.convert_value(key, value)
  if key == "httpStatus"
    value = value.to_i
  end
  value
end

Public Instance Methods

api_problem(problem_type, title, options={}) click to toggle source
# File lib/api_problem.rb, line 20
def api_problem(problem_type, title, options={})
  ApiProblem.build problem_type, title, options
end