diff options
Diffstat (limited to 'lib/helper.rb')
-rw-r--r-- | lib/helper.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/helper.rb b/lib/helper.rb new file mode 100644 index 0000000..a9f451e --- /dev/null +++ b/lib/helper.rb @@ -0,0 +1,26 @@ +helpers do + + # Authentification + def protected! + response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") and \ + throw(:halt, [401, "Not authorized\n"]) and \ + return unless authorized? + end + + def authorized? + @auth ||= Rack::Auth::Basic::Request.new(request.env) + @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['api', API_KEY] + end + + +=begin + def xml(object) + builder do |xml| + xml.instruct! + object.to_xml + end + end +=end + +end + |