Permalink
Browse files

merge

  • Loading branch information...
2 parents 7826910 + ba82cb9 commit 9727ec2e15ee3f030eae9e9a272a9e5fdb5b8bb7 @kkalass kkalass committed Dec 4, 2010
File renamed without changes.
View
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
3 README
@@ -1,3 +0,0 @@
-Sinatra backend under /server
-
-html5 application to be used in headquarters: /hqclient
View
@@ -0,0 +1,6 @@
+# Disaster Maps
+
+API for sending data on events from the field
+
+## API Documentation
+
File renamed without changes.
View
@@ -1,2 +1,8 @@
#rack config
+require 'rubygems'
+require 'bundler'
+
+require File.join(File.dirname(__FILE__), "service")
+
+run Sinatra::Application
File renamed without changes.
File renamed without changes.
View
@@ -1,17 +0,0 @@
-require 'yaml'
-require 'mongoid'
-
-file_name = File.join(File.dirname(__FILE__), "config", "mongoid.yml")
-@settings = YAML.load_file(file_name)
-env = ENV['RACK_ENV'] || 'development'
-
-Mongoid.configure do |config|
- config.from_hash(@settings[env])
-end
-
-require './models/event'
-require 'sinatra'
-
-get '/api/v1/events/:id' do
- Event.find_by_id(params[:id])
-end
View
@@ -0,0 +1,33 @@
+require 'yaml'
+require 'mongoid'
+
+file_name = File.join(File.dirname(__FILE__), "config", "mongoid.yml")
+@settings = YAML.load_file(file_name)
+env = ENV['RACK_ENV'] || 'development'
+
+Mongoid.configure do |config|
+ config.from_hash(@settings[env])
+end
+
+require './models/event'
+require 'sinatra'
+
+get '/api/v1/events/:id' do
+ event = Event.find_by_id(params[:id].to_i)
+ raise Sinatra::NotFound unless event
+ event.to_json
+end
+
+get '/api/v1/tags/:tag/events' do
+ events = Event.find(:tag => params[:tag])
+ raise Sinatra::NotFound unless events
+ events.to_json
+end
+
+post '/api/v1/events' do
+ Event.create(JSON.parse(params[:event]))
+end
+
+get '/' do
+ 'Hello world!'
+end
@@ -3,5 +3,5 @@
e.title 'Bridge collapsed'
e.description 'Villiage of Balti, Near Gligit is cut off from the supply route due to the collapsed bridge'
e.location [73.3, 36.2]
- e.tags %w(bridge)
+ e.tags %w(bridge cut-off-supply-route)
end
File renamed without changes.
@@ -14,39 +14,57 @@ def app
describe 'GET /api/v1/events/:id' do
it 'should return event by id' do
- # Event.mocks(:find).expects(1).returns(@event)
+ Event.expects(:find_by_id).with(1).returns(@event)
get '/api/v1/events/1'
- response.should be_ok
+ last_response.should be_ok
+ end
+
+ it 'should return a 404 for an event that doesn\'t exist' do
+ Event.expects(:find_by_id).with(1).returns(nil)
+ get '/api/v1/events/1'
+ last_response.should_not be_ok
end
end
- describe 'GET /api/v1/events/:tag' do
- it 'should return events by tag'
- it 'should return a 404 for an event that doesn\'t exist'
+ describe 'GET /api/v1/tags/:tag/events' do
+ it 'should return events by tag' do
+ Event.expects(:find).with(:tag => 'bridge').returns([@event])
+ get '/api/v1/tags/bridge/events'
+ last_response.should be_ok
+ JSON.parse(last_response.body).first.should have_key('tags')
+ end
+
+ it 'should return a 404 for an tag that doesn\'t exist' do
+ Event.expects(:find).with(:tag => 'bridge').returns(nil)
+ get '/api/v1/tags/bridge/events'
+ last_response.should_not be_ok
+ end
end
describe 'GET /api/v1/events/:bounds' do
it 'should return events by tag' do
+ pending
get '/api/v1/events/73.0646,35.6842,74.3033,36.2907'
end
end
describe 'GET /api/v1/events/:location' do
it 'should return events by point location' do
+ pending
get '/api/v1/events/73.3,36.2'
end
end
describe 'POST /api/v1/events' do
it 'should create an event' do
parameter_hash = {
- :title => 'House destroyed',
- :description => 'House belonging to Mr Karzai was completely destroyed, family homeless',
- :location => [73.2, 36.2],
- :tags => %(homeless)
+ "title" => 'House destroyed',
+ "description" => 'House belonging to Mr Karzai was completely destroyed, family homeless',
+ "location" => [73.2, 36.2],
+ "tags" => %(homeless)
}
Event.expects(:create).with(parameter_hash)
- post '/api/v1/events', parameter_hash.to_json
+ post '/api/v1/events', :event => parameter_hash.to_json
last_response.should be_ok
# id = JSON.parse(last_response.body)['id']
# get "/api/v1/events/#{id}"
@@ -55,4 +73,4 @@ def app
# attributes['description'].should == 'House belonging to Mr Karzai was completely destroyed, family homeless'
end
end
-end
+end
@@ -1,6 +1,5 @@
require File.join(File.dirname(__FILE__), '..', 'service.rb')
-
require 'sinatra'
require 'rack/test'
require 'rspec'

0 comments on commit 9727ec2

Please sign in to comment.