Sha256: 280b369d43b6e909a96919c0c647fe7827fc480e668b11dfaf645a9e00ca8ee4

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Locomotive
  module Steam

    class APIEntrySubmissionService < Struct.new(:site, :locale)

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

      def find(type_slug, slug)
        if entry = load_content_type(type_slug).entries.where(_slug: slug).first
          make_entity(entry)
        end
      end

      def to_json(entry)
        make_entity(entry).to_json
      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
          service.public_create(attributes)
        end
      end

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

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

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
locomotivecms-3.1.0.rc1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.1 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc7 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc6 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc5 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc4 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc3 lib/locomotive/steam/services/api_entry_submission_service.rb
locomotivecms-3.0.0.rc2 lib/locomotive/steam/services/api_entry_submission_service.rb