Class: SellsyV2::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/sellsy_v2/company.rb,
lib/sellsy_v2/company/address.rb

Defined Under Namespace

Classes: Address

Constant Summary collapse

ROOT_PATH =
'/companies'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ Company

Returns a new instance of Company.



8
9
10
11
12
13
14
15
# File 'lib/sellsy_v2/company.rb', line 8

def initialize(attr)
  attr.each do |k,v|
    define_singleton_method(k) { instance_variable_get("@#{k}") }
    define_singleton_method("#{k}=") { |val| instance_variable_set("@#{k}", val) }

    instance_variable_set("@#{k}", v)
  end
end

Class Method Details

.all(**options) ⇒ Object



17
18
19
20
21
22
# File 'lib/sellsy_v2/company.rb', line 17

def self.all(**options)
  companies_response = Request.new(path: ROOT_PATH, verb: 'get', options: options).call
  if companies_response.success?
    companies_response.data.dig('data').map{Company.new(_1)}
  end
end

.find(id, **options) ⇒ Object



24
25
26
27
28
29
# File 'lib/sellsy_v2/company.rb', line 24

def self.find(id, **options)
  company_response = Request.new(path: "#{ROOT_PATH}/#{id}", verb: 'get', options: options).call
  if company_response.success?
    Company.new(company_response.data)
  end
end

Instance Method Details

#addresses(**options) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/sellsy_v2/company.rb', line 31

def addresses(**options)
  verb = 'get'
  path = "#{ROOT_PATH}/#{id}/addresses"
  company_addresses_response = Request.new(path: path, verb: verb, options: options).call
  if company_addresses_response.success?
    company_addresses_response.data.dig('data').map{Address.new(_1)}
  end
end