forked from toddwschneider/sec-13f-filings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_controller.rb
75 lines (61 loc) · 1.98 KB
/
data_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class DataController < ApplicationController
before_action :set_public_cache_header
def autocomplete
managers_data = ThirteenFFiler.
autocomplete(params[:q]).
limit(8).
map do |f|
{
name: f.name,
extra: "#{f.city_and_state}",
url: manager_path(f)
}
end
cusips_data = CompanyCusipLookup.
autocomplete(params[:q]).
limit(5).
map do |c|
{
name: c.issuer_name,
extra: [c.symbol, c.cusip, c.class_title.upcase].compact.join(" - "),
url: cusip_index_path(cusip: c.cusip)
}
end
render json: {managers: managers_data, cusips: cusips_data}
end
def thirteen_f_data
filing = ThirteenF.without_xml_fields.find_by!(external_id: params[:external_id])
render json: DataTableFormatter.thirteen_f_to_aggregated_datatable(filing)
end
def thirteen_f_detailed_data
filing = ThirteenF.without_xml_fields.find_by!(external_id: params[:external_id])
render json: DataTableFormatter.thirteen_f_to_detailed_datatable(filing)
end
def compare_holdings_data
filing = ThirteenF.without_xml_fields.find_by!(external_id: params[:external_id])
other_filing = ThirteenF.without_xml_fields.find_by!(external_id: params[:other_external_id])
render json: DataTableFormatter.thirteen_f_comparison_to_datatable(filing, other_filing)
end
def all_cusip_holders_data
year = params[:year].to_i
quarter = params[:quarter].to_i
head :bad_request unless (1..4).include?(quarter) && year <= Date.today.year
data = DataTableFormatter.all_cusip_holdings_to_datatable(
cusip: parsed_cusip,
year: year,
quarter: quarter
)
render json: data
end
def manager_cusip_history_data
data = DataTableFormatter.manager_cusip_history_to_datatable(
cusip: parsed_cusip,
manager_cik: params[:cik]
)
render json: data
end
private
def set_public_cache_header
expires_in 1.hour, public: true
end
end