Sha256: 636a0380bc9a3de497aafeeedccb773b9e269a13f3c822473257c21d527ce522

Contents?: true

Size: 871 Bytes

Versions: 19

Compression:

Stored size: 871 Bytes

Contents

require 'active_support'
require File.dirname(__FILE__) + '/../../proxy'

class LHS::Item < LHS::Proxy

  module Save
    extend ActiveSupport::Concern

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

    def save!(options = {})
      options ||= {}
      record = _data.class
      data = _data._raw.dup
      if href.present?
        url = href
      else
        endpoint = record.find_endpoint(data)
        url = endpoint.compile(data)
        endpoint.remove_interpolated_params!(data)
      end

      options = options.merge(method: :post, url: url, body: data.to_json)
      options[:headers] ||= {}
      options[:headers].merge!('Content-Type' => 'application/json')

      data = record.request(options)
      _data.merge_raw!(data)
      true
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lhs-6.7.1 lib/lhs/concerns/item/save.rb
lhs-6.7.0 lib/lhs/concerns/item/save.rb
lhs-6.6.2 lib/lhs/concerns/item/save.rb
lhs-6.6.1 lib/lhs/concerns/item/save.rb
lhs-6.6.0 lib/lhs/concerns/item/save.rb
lhs-6.5.0 lib/lhs/concerns/item/save.rb
lhs-6.4.0 lib/lhs/concerns/item/save.rb
lhs-6.3.1 lib/lhs/concerns/item/save.rb
lhs-6.3.0 lib/lhs/concerns/item/save.rb
lhs-6.2.0 lib/lhs/concerns/item/save.rb
lhs-6.1.0 lib/lhs/concerns/item/save.rb
lhs-6.0.0 lib/lhs/concerns/item/save.rb
lhs-5.7.1 lib/lhs/concerns/item/save.rb
lhs-5.7.0 lib/lhs/concerns/item/save.rb
lhs-5.6.6 lib/lhs/concerns/item/save.rb
lhs-5.6.5 lib/lhs/concerns/item/save.rb
lhs-5.6.4 lib/lhs/concerns/item/save.rb
lhs-5.6.3 lib/lhs/concerns/item/save.rb
lhs-5.6.2 lib/lhs/concerns/item/save.rb