Sha256: a89292470a96c67ca96ef6f0d5435df6a301de6fa5b4fed29d297ec91a5385d0

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

module Locomotive
  module Steam

    class APIEntrySubmissionService < EntrySubmissionService

      attr_accessor_initialize :service, :request

      def submit(type_slug, attributes = {})
        if load_content_type(type_slug)
          create_entry(attributes)
        else
          nil
        end
      end

      private

      def load_content_type(slug)
        @content_type = site.content_types.where(slug: slug, public_submission_enabled: true).first
      end

      def create_entry(attributes)
        ::Mongoid::Fields::I18n.with_locale(locale) do
          entry = engine_service.public_create(attributes, { ip_address: ip_address })

          entity = entry.to_steam(@content_type)
          Locomotive::Steam::Decorators::I18nDecorator.new(entity, locale)
        end
      end

      def site
        self.request.env['locomotive.site']
      end

      def ip_address
        self.request.ip
      end

      def locale
        self.service.locale
      end

      def engine_service
        Locomotive::ContentEntryService.new(@content_type, nil)
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
locomotivecms-3.4.1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-4.0.0.alpha2 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-4.0.0.alpha1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.4.0 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.3.0 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.3.0.rc3 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.3.0.rc2 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.2.1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.3.0.rc1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.2.0 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.2.0.rc2 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.2.0.rc1 lib/locomotive/steam/services/api_entry_submission_service.rb