2019-04-19 11:39:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ServiceResponse
|
2019-06-11 12:08:25 -04:00
|
|
|
def self.success(message: nil)
|
|
|
|
new(status: :success, message: message)
|
2019-04-19 11:39:12 -04:00
|
|
|
end
|
|
|
|
|
2019-06-11 12:08:25 -04:00
|
|
|
def self.error(message:, http_status: nil)
|
|
|
|
new(status: :error, message: message, http_status: http_status)
|
2019-04-19 11:39:12 -04:00
|
|
|
end
|
|
|
|
|
2019-06-11 12:08:25 -04:00
|
|
|
attr_reader :status, :message, :http_status
|
2019-04-19 11:39:12 -04:00
|
|
|
|
2019-06-11 12:08:25 -04:00
|
|
|
def initialize(status:, message: nil, http_status: nil)
|
2019-04-19 11:39:12 -04:00
|
|
|
self.status = status
|
|
|
|
self.message = message
|
|
|
|
self.http_status = http_status
|
|
|
|
end
|
|
|
|
|
|
|
|
def success?
|
|
|
|
status == :success
|
|
|
|
end
|
|
|
|
|
|
|
|
def error?
|
|
|
|
status == :error
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-06-11 12:08:25 -04:00
|
|
|
attr_writer :status, :message, :http_status
|
2019-04-19 11:39:12 -04:00
|
|
|
end
|