Skip to content

Instantly share code, notes, and snippets.

@pochi
Created May 6, 2012 15:57
Show Gist options
  • Save pochi/2623073 to your computer and use it in GitHub Desktop.
Save pochi/2623073 to your computer and use it in GitHub Desktop.
# coding: utf-8 [1/9254]
require "sinatra"
require "json"
@@clients = []
get "/login.json" do
@@clients << { :id => params[:id], :unreads => [] }
puts @@clients.size
content_type :json, :charset => 'utf-8'
{ :login => :ok }.to_json
end
get "/post.json" do
@@clients.each do |c|
c[:unreads] << params[:message] if c[:id] != params[:id]
end
content_type :json, :charset => 'utf-8'
{ :message => params[:message] }.to_json
end
get "/update.json" do
messages = (@@clients.find { |c| c[:id] == params[:id] })[:unreads]
messages = messages.empty? ? "" : messages
(@@clients.find { |c| c[:id] == params[:id] })[:unreads] = []
puts params.inspect
content_type :json, :charset => 'utf-8'
{ :message => messages }.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment