Sha256: f4d616e031b640a6e9401f2711bbdc2da2846a30e0aebf7021688a31ae05256b

Contents?: true

Size: 705 Bytes

Versions: 15

Compression:

Stored size: 705 Bytes

Contents

require 'active_support'

class LHS::Record

  module Create
    extend ActiveSupport::Concern

    module ClassMethods
      def create(data = {})
        create!(data)
      rescue LHC::Error => e
        json = JSON.parse(data.to_json)
        data = LHS::Data.new(json, nil, self, e.response.request)
        item = LHS::Item.new(data)
        item.errors = LHS::Errors.new(e.response)
        data._record_class.new(LHS::Data.new(item, data))
      end

      def create!(data = {})
        url = compute_url!(data)
        data = request(url: url, method: :post, body: data.to_json, headers: { 'Content-Type' => 'application/json' })
        data._record_class.new(data)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lhs-3.3.6 lib/lhs/concerns/record/create.rb
lhs-3.3.5 lib/lhs/concerns/record/create.rb
lhs-3.3.3 lib/lhs/concerns/record/create.rb
lhs-3.3.2 lib/lhs/concerns/record/create.rb
lhs-3.3.1 lib/lhs/concerns/record/create.rb
lhs-3.3.0 lib/lhs/concerns/record/create.rb
lhs-3.2.0 lib/lhs/concerns/record/create.rb
lhs-3.1.3 lib/lhs/concerns/record/create.rb
lhs-3.1.1 lib/lhs/concerns/record/create.rb
lhs-3.1.0 lib/lhs/concerns/record/create.rb
lhs-3.0.5 lib/lhs/concerns/record/create.rb
lhs-3.0.4 lib/lhs/concerns/record/create.rb
lhs-3.0.3 lib/lhs/concerns/record/create.rb
lhs-3.0.2 lib/lhs/concerns/record/create.rb
lhs-3.0.1 lib/lhs/concerns/record/create.rb