Skip to content

ecomcharge/model_receiver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

model_receiver

This gem is written to work with rails 3 or sinatra applications using activerecord. Add/Update record through ActiveRecord according with received model attributes.

Quick Start For Sinatra Applications

Add the dependency to your Gemfile

gem "model_receiver"

Install it...

bundle

You 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
end

Add a route to your applications to config.ru file

run Rack::URLMap.new({
  "/"               => YourSinatra::App,
  "/model_receiver" => YourSinatra::ModelReceiverApp
})

Quick Start For Rails 3 Applications

Add the dependency to your Gemfile

gem "model_receiver"

Install it...

bundle

Add a route to your application for accessing the interface

match "/model_receiver" => ModelReceiver::App, :anchor => false

You 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
end

Author

Mikhail Davidovich

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 7

Languages