summaryrefslogtreecommitdiff
path: root/lib/helper.rb
blob: a9f451e3c4fc479fbe174775c27d359d32558562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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