Module: LHS::Item::Update

Extended by:
ActiveSupport::Concern
Included in:
LHS::Item
Defined in:
lib/lhs/concerns/item/update.rb

Instance Method Summary collapse

Instance Method Details

#update(params, options = nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/lhs/concerns/item/update.rb', line 9

def update(params, options = nil)
  update!(params, options)
rescue LHC::Error => e
  self.errors = LHS::Errors.new(e.response)
  false
end

#update!(params, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lhs/concerns/item/update.rb', line 16

def update!(params, options = {})
  options ||= {}
  _data.merge_raw!(LHS::Data.new(params, _data.parent, _data.class))
  response_data = _data.class.request(
    options.merge(
      method: :post,
      url: href,
      body: _data.to_json,
      headers: { 'Content-Type' => 'application/json' }
    )
  )
  _data.merge_raw!(response_data)
  true
end