lib/codat/models/company.rb in codat-0.1.1 vs lib/codat/models/company.rb in codat-0.1.2
- old
+ new
@@ -4,28 +4,40 @@
module Codat
module Models
# Companies for a given company.
class Company < BaseModel
- ENDPOINT = '/companies'
+ ENDPOINTS = {
+ collection: '/companies',
+ single: '/companies/:company_id'
+ }.freeze
attributes :id, :name, :platform, :redirect, :status, :last_sync, :data_connections
attributes :integration_id, :source_id, :platform_name, :link_url
+ # Returns the list of companies in the Codat account.
def self.all(params = {})
- result = get(ENDPOINT, params)
+ result = get(ENDPOINTS[:collection], params)
return [] if result.status == 404
return result.body if result.status == 400
result.body[:results].map { |company| new(json: company) }
end
- def self.create(params = {})
- url = format_url(ENDPOINT, {})
+ def self.find(company_id)
+ url = format_url(ENDPOINTS[:single], company_id: company_id)
- result = post(url, params)
+ result = get(url)
+
+ return nil if result.status == 404
+
+ new(json: result.body)
+ end
+
+ def self.create(params = {})
+ result = post(ENDPOINTS[:collection], params)
return { error: 'An error occured.' } if result.status == 404 || result.status == 400
new(json: result.body)
end