Sha256: 86562a6b9702e0d76135c746bfc5206b0699d2683c6854cb0a83ca8189547a2b

Contents?: true

Size: 673 Bytes

Versions: 20

Compression:

Stored size: 673 Bytes

Contents

require 'active_support'

class LHS::Service

  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.class, e.response.request)
          item = LHS::Item.new(data)
          item.errors = LHS::Errors.new(e.response)
          LHS::Data.new(item, data)
      end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
lhs-1.6.1 lib/lhs/concerns/service/create.rb
lhs-1.6.0 lib/lhs/concerns/service/create.rb
lhs-2.0.5 lib/lhs/concerns/service/create.rb
lhs-2.0.4 lib/lhs/concerns/service/create.rb
lhs-2.0.3 lib/lhs/concerns/service/create.rb
lhs-2.0.2 lib/lhs/concerns/service/create.rb
lhs-2.0.1 lib/lhs/concerns/service/create.rb
lhs-2.0.0 lib/lhs/concerns/service/create.rb
lhs-1.5.0 lib/lhs/concerns/service/create.rb
lhs-1.4.0 lib/lhs/concerns/service/create.rb
lhs-1.3.1 lib/lhs/concerns/service/create.rb
lhs-1.3.0 lib/lhs/concerns/service/create.rb
lhs-1.2.3 lib/lhs/concerns/service/create.rb
lhs-1.2.2 lib/lhs/concerns/service/create.rb
lhs-1.2.1 lib/lhs/concerns/service/create.rb
lhs-1.2.0 lib/lhs/concerns/service/create.rb
lhs-1.1.0 lib/lhs/concerns/service/create.rb
lhs-1.0.0 lib/lhs/concerns/service/create.rb
lhs-0.4.0 lib/lhs/concerns/service/create.rb
lhs-0.3.0 lib/lhs/concerns/service/create.rb