Class: Iro::Api::StocksController

Inherits:
Iro::ApiController
  • Object
show all
Defined in:
app/controllers/iro/api/stocks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/iro/api/stocks_controller.rb', line 49

def create
  @stock = Iro::Stock.new(stock_params)
  authorize! :create, @stock

  if @stock.save
    flash_notice @stock
  else
    flash_alert @stock
  end
  redirect_to action: :index
end

#destroyObject



72
73
74
75
# File 'app/controllers/iro/api/stocks_controller.rb', line 72

def destroy
  @stock.destroy
  redirect_to stocks_url, notice: 'Stock was successfully destroyed.'
end

#editObject



46
47
# File 'app/controllers/iro/api/stocks_controller.rb', line 46

def edit
end

#indexObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/iro/api/stocks_controller.rb', line 5

def index
  authorize! :index, Iro::Stock

  respond_to do |format|
    format.json do
      render
    end
  end
end

#newObject



41
42
43
44
# File 'app/controllers/iro/api/stocks_controller.rb', line 41

def new
  @stock = Iro::Stock.new
  authorize! :new, @stock
end

#showObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/iro/api/stocks_controller.rb', line 15

def show
  authorize! :show, @stock
  end_on = Time.now.to_date.in_time_zone('UTC')

  begin_on = params[:begin_on].to_date.in_time_zone('UTC') if params[:begin_on]
  end_on   = params[:end_on].to_date.in_time_zone('UTC')   if params[:end_on]

  case params[:period]
  when '1-mo'
    begin_on = ( Time.now - 30.days ).to_date.in_time_zone('UTC')
    # end_on   = Time.now.to_date.in_time_zone('UTC')
  when '3-mo'
    begin_on = ( Time.now - 90.days ).to_date.in_time_zone('UTC')
    # end_on   = Time.now.to_date.in_time_zone('UTC')
  when '1-yr'
    begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC')
    # end_on   = Time.now.to_date.in_time_zone('UTC')
  end

  @datapoints = Iro::Datapoint.where({
    :quote_at.gte => begin_on,
    :quote_at.lte => end_on,
    symbol: params[:ticker],
  }).order_by({ quote_at: :asc })
end

#updateObject



61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/iro/api/stocks_controller.rb', line 61

def update
  @stock = Iro::Stock.find params[:id]
  authorize! :update, @stock
  if @stock.update(stock_params)
    flash_notice @stock
  else
    flash_alert @stock
  end
  redirect_to request.referrer
end