Module: Moneybird::Traits::Save

Instance Method Summary collapse

Instance Method Details

#create(attributes) ⇒ Object Also known as: update



17
18
19
20
21
# File 'lib/moneybird/traits/save.rb', line 17

def create(attributes)
  build(attributes).tap do |resource|
    save(resource)
  end
end

#save(resource) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/moneybird/traits/save.rb', line 6

def save(resource)
  response =
    if resource.persisted?
      client.patch(resource_path(resource), resource.to_json)
    else
      client.post(resource_path(resource), resource.to_json)
    end
  resource.attributes = response
  resource
end