Skip to content

Instantly share code, notes, and snippets.

@gertig
Created February 6, 2011 01:43
Show Gist options
  • Save gertig/813016 to your computer and use it in GitHub Desktop.
Save gertig/813016 to your computer and use it in GitHub Desktop.
Rails 3 demo of using HTTParty and Moment for delayed jobs
# models/scheduler.rb
require 'httparty'
require 'pp'
MOMENT_API_KEY = 'XXXXXXXXXXXXX'
class Scheduler
include HTTParty
base_uri 'https://momentapp.com'
format :json
def initialize(user_id, time_increment)
#@auth = { :apikey => MOMENT_API_KEY }
@user_id = user_id
@time_increment = time_increment
end
def schedule_it()
options = { :query => {
:apikey => MOMENT_API_KEY,
'job[at]' => (Time.now + 1.minute).to_s(:moment),
'job[method]' => 'GET',
'job[uri]' => "http://mydomain.heroku.com/custom/#{@user_id}/mycustomaction"
}
}
self.class.post('/jobs.json', options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment