Skip to content

Commit

Permalink
Added readme with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
frison committed Feb 18, 2011
1 parent 88e0125 commit 2fbb49a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
= UrlJob

Rails gem that provides an engine which allows for creating urls that execute jobs

== Install

gem install url_job

== Usage

Lets assume you have an class like the following:

class Redirector < Struct.new(:redirect_to)
def initialize(redirect)
self.redirect_to = redirect
end

def perform(args={})
self
end
end

By creating a UrlJob using the following:
uj = UrlJob::Job.from_object(Redirector.new("http://frison.ca"))

And visiting:
http://localhost:3000/uj/#{uj.token}

The result will be deserializing the Redirector job, and calling it's perform method.
The perform method should return an object that responds to either: 'redirect_to' or 'render', and the corresponding action will occur. The perform method will be passed in a dictionary with the following keys:
:ip_address => The ip address of the url visitor
:user_agent => The user agent of the url visitor
:referrer => The referrer of the url visitor
:token => The token used to visit the url.

A more interesting example might be an object like:

class Tracker
def initialize
end

def perform(params={})
@url_job = UrlJob::Job.find_by_token(params[:token])
UrlTrack.create(:url_job => @url_job,
:referrer => params[:referrer],
:ip_address => params[:ip_address],
:user_agent => params[:user_agent])

OpenStruct.new({:render => " "})
end
end

This way you could do something like:
uj = UrlJob::Job.from_object(Tracker.new)

And embed a image tag like:
<img src="http://localhost:3000/uj/#{uj.token}" height="1px" width="1px">

Inside some emails to track some email opens

== Licence

Copyright (c) 2011 Timothy Frison

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 2fbb49a

Please sign in to comment.