Class: SupplejackApi::SourcesController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SupplejackApi::SourcesController
- Defined in:
- app/controllers/supplejack_api/sources_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #index ⇒ Object
- #link_check_records ⇒ Object
- #reindex ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 13 def create params[:source][:partner_id] = params[:partner_id] if params[:source][:_id].present? @source = Source.find_or_initialize_by(_id: params[:source][:_id]) @source.update_attributes(params[:source]) else @source = Source.create(params[:source]) end render json: @source end |
#index ⇒ Object
25 26 27 28 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 25 def index @sources = params[:source].nil? ? Source.all : Source.where(params[:source]) render json: @sources end |
#link_check_records ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 48 def link_check_records @source = Source.find(params[:id]) @records = [] @records += first_two_records(@source.source_id, :oldest).map(&:source_url) @records += first_two_records(@source.source_id, :latest).map(&:source_url) render json: @records.to_json end |
#reindex ⇒ Object
41 42 43 44 45 46 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 41 def reindex @source = Source.find(params[:id]) Resque.enqueue(IndexSourceWorker, @source.source_id, params[:date]) render nothing: true end |
#show ⇒ Object
30 31 32 33 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 30 def show @source = Source.find(params[:id]) render json: @source end |
#update ⇒ Object
35 36 37 38 39 |
# File 'app/controllers/supplejack_api/sources_controller.rb', line 35 def update @source = Source.find(params[:id]) @source.update_attributes(params[:source]) render json: @source end |