Class: Codat::Models::Financial
- Defined in:
- lib/codat/models/financial.rb
Overview
Financials for a given company.
Constant Summary collapse
- ENDPOINT =
{ profit_and_loss: '/companies/:company_id/data/financials/profitAndLoss', balance_sheet: '/companies/:company_id/data/financials/balanceSheet' }.freeze
Class Method Summary collapse
Methods inherited from BaseModel
attributes, #format_url, format_url, get, #get, #initialize, post, #post
Constructor Details
This class inherits a constructor from Codat::BaseModel
Class Method Details
.balance_sheet(params = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/codat/models/financial.rb', line 37 def self.balance_sheet(params = {}) company_id = params.delete(:company_id) raise CompanyNotProvidedError if company_id.nil? || company_id.empty? url = format_url( ENDPOINT[:balance_sheet], company_id: company_id.to_s.strip ) params.delete(:company_id) params = params.map { |key, value| [Camelizer.transform(key), value] }.to_h result = get(url, params) return [] if result.status == 404 || result.status == 400 result.body[:reports].map { |report| new(json: report) } end |
.profit_and_loss(params = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/codat/models/financial.rb', line 18 def self.profit_and_loss(params = {}) company_id = params.delete(:company_id) raise CompanyNotProvidedError if company_id.nil? || company_id.empty? url = format_url( ENDPOINT[:profit_and_loss], company_id: company_id.to_s.strip ) params = params.map { |key, value| [Camelizer.transform(key), value] }.to_h result = get(url, params) return [] if result.status == 404 || result.status == 400 result.body[:reports].map { |report| new(json: report) } end |