Class: Iro::DatapointsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/iro/datapoints_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #schwab_sync, #schwab_sync_exec

Instance Method Details

#createObject

params: d, k, v



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/iro/datapoints_controller.rb', line 5

def create
  # puts! params, 'datapoints#create'

  authorize! :create, Iro::Datapoint
  begin
    Iro::Datapoint.create!(
      date:  params[:d],
      kind:  params[:k],
      value: params[:v],
    )
    render json: { status: :ok }
  rescue Mongoid::Errors::Validations => err
    puts! err, 'could not create datapoint'
    render json: { status: 401 }, status: 401
  end
end

#indexObject



22
23
24
25
26
# File 'app/controllers/iro/datapoints_controller.rb', line 22

def index
  authorize! :datapoints_index, Iro
  @symbol = params[:symbol] || params[:q]
  @datapoints = Iro::Datapoint.where( symbol: @symbol ).order_by( quote_at: :desc ).limit(100)
end