This gem is written to work with rails 3 or sinatra applications using activerecord. Add/Update record through ActiveRecord according with received model attributes.
Add the dependency to your Gemfile
gem "model_receiver"Install it...
bundleYou probably want to password protect the interface, an easy way is to add something like this
require 'model_receiver'
module YourSinatra
class ModelReceiverApp < ModelReceiver::App
helpers do
def protected_www
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Enter your user name and password")
throw(:halt, [401, "Not authorized\n"])
end
end
def authorized?
@auth ||= ::Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials &&
@auth.credentials == ['login', 'password']
end
end
before { protected_www }
end
endAdd a route to your applications to config.ru file
run Rack::URLMap.new({
"/" => YourSinatra::App,
"/model_receiver" => YourSinatra::ModelReceiverApp
})Add the dependency to your Gemfile
gem "model_receiver"Install it...
bundleAdd a route to your application for accessing the interface
match "/model_receiver" => ModelReceiver::App, :anchor => falseYou probably want to password protect the interface, an easy way is to add something like this your config.ru file
if Rails.env.production?
ModelReceiver::App.use Rack::Auth::Basic do |username, password|
username == 'username' && password == 'password'
end
endMikhail Davidovich