2013-04-27 14:07:14 +02:00
module Dyndnsd
module Responder
class RestStyle
2013-04-27 15:42:29 +02:00
def response_for_error ( state )
2013-04-27 14:07:14 +02:00
# general http errors
return [ 405 , { " Content-Type " = > " text/plain " } , [ " Method Not Allowed " ] ] if state == :method_forbidden
return [ 404 , { " Content-Type " = > " text/plain " } , [ " Not Found " ] ] if state == :not_found
# specific errors
return [ 422 , { " Content-Type " = > " text/plain " } , [ " Hostname missing " ] ] if state == :hostname_missing
return [ 403 , { " Content-Type " = > " text/plain " } , [ " Forbidden " ] ] if state == :host_forbidden
return [ 422 , { " Content-Type " = > " text/plain " } , [ " Hostname malformed " ] ] if state == :hostname_malformed
2013-04-27 15:42:29 +02:00
end
2016-12-07 14:16:57 +01:00
2013-04-27 15:42:29 +02:00
def response_for_changes ( states , ip )
2016-12-07 14:16:57 +01:00
body = states . map { | state | state == :good ? " Changed to #{ ip . is_a? ( Array ) ? ip . join ( ' ' ) : ip } " : " No change needed for #{ ip . is_a? ( Array ) ? ip . join ( ' ' ) : ip } " } . join ( " \n " )
2013-04-27 15:42:29 +02:00
return [ 200 , { " Content-Type " = > " text/plain " } , [ body ] ]
2013-04-27 14:07:14 +02:00
end
end
end
end