Module: Moneybird::Traits::Save

Instance Method Summary collapse

Instance Method Details

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



15
16
17
18
19
# File 'lib/moneybird/traits/save.rb', line 15

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

#save(resource) ⇒ Object



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

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