Created
February 6, 2011 01:43
-
-
Save gertig/813016 to your computer and use it in GitHub Desktop.
Rails 3 demo of using HTTParty and Moment for delayed jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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