Class: Nova::API::Resource::ThirdParty

Inherits:
Base show all
Defined in:
lib/nova/api/resource/third_party.rb

Constant Summary collapse

ALLOWED_ATTRIBUTES =
%i[
  trading_name identification address phone social_reason municipal_inscription state_inscription email notes supplier
  customer retention whatsapp twitter facebook linkedin google instagram site csll pis cofins irpj values_past
]

Constants inherited from Base

Base::PRODUCTION_HOST, Base::SCHEME, Base::STAGING_HOST

Constants inherited from Utils::BaseStruct

Utils::BaseStruct::DATE_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_url

Methods inherited from Utils::BaseStruct

#allowed_attributes

Class Method Details

.create(parameters) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/nova/api/resource/third_party.rb', line 52

def self.create(parameters)
  model = new parameters

  model.attributes.delete(:id)

  model.save
end

.customers(parameters = {}) ⇒ Object



44
45
46
# File 'lib/nova/api/resource/third_party.rb', line 44

def self.customers(parameters = {})
  do_get_search("/api/customers", parameters.to_h)
end

.destroy(id) ⇒ Object



66
67
68
69
70
# File 'lib/nova/api/resource/third_party.rb', line 66

def self.destroy(id)
  model = initialize_empty_model_with_id(self, id)

  model.destroy
end

.endpointObject



36
37
38
# File 'lib/nova/api/resource/third_party.rb', line 36

def self.endpoint
  '/api/third_parties'
end

.list(parameters = {}) ⇒ Object



40
41
42
# File 'lib/nova/api/resource/third_party.rb', line 40

def self.list(parameters = {})
  do_get_search(endpoint, parameters.to_h)
end

.suppliers(parameters = {}) ⇒ Object



48
49
50
# File 'lib/nova/api/resource/third_party.rb', line 48

def self.suppliers(parameters = {})
  do_get_search("/api/suppliers", parameters.to_h)
end

.update(id, parameters) ⇒ Object



60
61
62
63
64
# File 'lib/nova/api/resource/third_party.rb', line 60

def self.update(id, parameters)
  model = new parameters.merge(id: id)

  model.update
end

Instance Method Details

#destroyObject



92
93
94
95
96
# File 'lib/nova/api/resource/third_party.rb', line 92

def destroy
  protect_operation_from_missing_value

  do_delete("#{endpoint}")
end

#endpointObject



72
73
74
75
76
# File 'lib/nova/api/resource/third_party.rb', line 72

def endpoint
  protect_operation_from_missing_value

  "/api/third_parties/#{id}"
end

#saveObject



78
79
80
81
82
83
84
# File 'lib/nova/api/resource/third_party.rb', line 78

def save
  if id.nil?
    do_post(self.class.endpoint, allowed_attributes)
  else
    do_patch("#{endpoint}", allowed_attributes)
  end
end

#updateObject



86
87
88
89
90
# File 'lib/nova/api/resource/third_party.rb', line 86

def update
  protect_operation_from_missing_value

  do_patch("#{endpoint}", allowed_attributes)
end