Module: SyncableModels::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/syncable_models/controller.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- BATCH_COUNT =
50
Instance Method Summary collapse
- #do_authorize_by_key ⇒ Object
- #fetch(klass) ⇒ Object
- #render_argument_error ⇒ Object
- #set_synced(klass, id_key = :uuid) ⇒ Object
Instance Method Details
#do_authorize_by_key ⇒ Object
54 55 56 57 58 |
# File 'lib/syncable_models/controller.rb', line 54 def if params[:key] != api_key return render json: { status: 401, message: 'Unauthorized'} end end |
#fetch(klass) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/syncable_models/controller.rb', line 31 def fetch(klass) if params[:destination] count = params[:count].present? ? params[:count].to_i : BATCH_COUNT result = klass.not_synced(params[:destination]).limit(count).map(&:to_import_hash) render json: { status: 200, objects: result } else render_argument_error end end |
#render_argument_error ⇒ Object
50 51 52 |
# File 'lib/syncable_models/controller.rb', line 50 def render_argument_error return render json: { status: 400, message: 'Not enough arguments' } end |
#set_synced(klass, id_key = :uuid) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/syncable_models/controller.rb', line 41 def set_synced(klass, id_key = :uuid) if params[:ids] && params[:destination] klass.where(id_key => params[:ids]).sync(params[:destination]) render json: { status: 200 } else render_argument_error end end |