Skip to content
Browse files

HTTP response codes added

  • Loading branch information...
1 parent b758332 commit bc474d7e36ed98604c545dc3a99ba8a9a9ddb1ba @dshorthouse dshorthouse committed
Showing with 14 additions and 5 deletions.
  1. +8 −5 application.rb
  2. +5 −0 spec/application_spec.rb
  3. +1 −0 views/namefinder.builder
View
13 application.rb
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
require 'sinatra'
require 'sinatra/base'
-# require "sinatra/reloader" if development?
require 'sinatra/flash'
require 'builder'
require File.join(File.dirname(__FILE__), 'environment')
@@ -20,9 +19,10 @@ def find(params)
engine = params[:engine] || 0
if input_url.blank? && file.blank? && input.blank?
- @output = { :status => "NO PARAMETERS" }
+ @output = { :status => 400, :message => "No parameters were supplied" }
+ status @output[:status]
flash.sweep
- flash.now[:warning] = "No parameters were supplied"
+ flash.now[:warning] = @output[:message]
case format
when 'json'
content_type 'application/json', :charset => 'utf-8'
@@ -62,7 +62,7 @@ def find(params)
end
def input_large?(input)
- !input || input.size > 5000
+ !input || input.size > 5000
end
def workers_running?
@@ -76,7 +76,10 @@ def name_finder_presentation(name_finder_instance, format, do_redirect = false)
@output = name_finder_instance.output
flash.sweep
flash.now[:warning] = "That URL was inaccessible." if @output[:status] == 404
- flash.now[:error] = "The name engines failed. Administrators have been notified." if @output[:status] == 500
+ if @output[:status] == 500
+ status 500
+ flash.now[:error] = "The name engines failed. Administrators have been notified."
+ end
case format
when 'json'
content_type 'application/json', :charset => 'utf-8'
View
5 spec/application_spec.rb
@@ -105,6 +105,11 @@ def get_url(text)
r.status.should == 200
r.body.match('Passiflora pilosicorona').should be_true
end
+
+ it "API should return correct http respsonse code if there are no parameters" do
+ get "/name_finder.json"
+ last_response.status.should == 400
+ end
it "API should be able to find names in a small submitted utf-8 text" do
text = 'Betula alba Beçem'
View
1 views/namefinder.builder
@@ -1,6 +1,7 @@
xml.instruct!
xml.result do
xml.status @output[:status]
+ xml.message @output[:message] if @output[:message]
xml.total @output[:total] if @output[:total]
xml.input_url @output[:input_url] if @output[:input_url]
xml.url @output[:url] if @output[:url]

0 comments on commit bc474d7

Please sign in to comment.
Something went wrong with that request. Please try again.