Class: Backend::Cells::QuandlCellsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/cells/quandl_cells_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

accounts_range_crit, crit_params, journal_entries_states_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Instance Method Details

#showObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/backend/cells/quandl_cells_controller.rb', line 4

def show
  start = Time.zone.today << 12
  finish = start >> 12 - 1
  # params[:threshold] = 183.50
  dataset = params[:dataset] || 'CHRIS/LIFFE_EBM4'
  identifier = Identifier.find_by(nature: :quandl_token)
  token = (identifier ? identifier.value : 'BwQESxTYjPRj58EbvzQA')
  url = "https://www.quandl.com/api/v1/datasets/#{dataset}.json?auth_token=#{token}&trim_start=#{start}&trim_end=#{finish}"
  url = "https://www.quandl.com/api/v1/datasets/#{dataset}.json?auth_token=#{token}"
  data = JSON.load(open(url))
  if data['errors'].any?
  # TODO: Prevent ?
  else
    @data = data.deep_symbolize_keys
  end
end