Sha256: deee9dff7c7af16aec8bc3d85df073813ba50997fbcefcc3f5464b2fe66b6221

Contents?: true

Size: 723 Bytes

Versions: 6

Compression:

Stored size: 723 Bytes

Contents

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

class LHS::Item < LHS::Proxy

  module Save
    extend ActiveSupport::Concern

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

    def save!
      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

      data = record.request(method: :post, url: url, body: data.to_json, headers: { 'Content-Type' => 'application/json' })
      _data.merge_raw!(data)
      true
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lhs-5.0.4 lib/lhs/concerns/item/save.rb
lhs-5.0.3 lib/lhs/concerns/item/save.rb
lhs-5.0.1 lib/lhs/concerns/item/save.rb
lhs-5.0.0 lib/lhs/concerns/item/save.rb
lhs-4.2.1 lib/lhs/concerns/item/save.rb
lhs-4.2.0 lib/lhs/concerns/item/save.rb