Skip to content

Instantly share code, notes, and snippets.

@jsuchal
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsuchal/360308ac6e703d21512a to your computer and use it in GitHub Desktop.
Save jsuchal/360308ac6e703d21512a to your computer and use it in GitHub Desktop.
class Api::OpenDataController < ApplicationController
respond_to :xml, :json
def sync
records = OpenData.order(:updated_at, :id).limit(100)
records = records.where('(updated_at, id) > (?, ?)',
Time.parse(params[:since]),
params[:last_id] || 0
) if params[:since]
if records.any?
next_url = api_open_data_url(since: records.last.updated_at.as_json, last_id: records.last.id)
headers['Link'] = "<#{next_url}>; rel='next'" # Hypermedia API
end
respond_with(records)
end
end
# CREATE index ON open_data (updated_at, id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment