Sha256: f3280ce2fe4496dc74c999eaee9132385d0806ddc5ee39baa4e48dff37998448

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

require "ribose/actions/base"

module Ribose
  module Actions
    module Create
      extend Ribose::Actions::Base

      def create
        response = create_resource
        response[resource] || response
      end

      private

      # Attribute validations
      #
      # This method will be invoked by the create action to validate the
      # attributes before submitting to the actual endpoint. We can override
      # this one to validate user provider attributes.
      #
      def validate(attributes)
        attributes
      end

      def request_body(attributes)
        custom_option.merge(resource_key.to_sym => validate(attributes))
      end

      def create_resource
        Ribose::Request.post(resources_path, request_body(attributes))
      end

      module ClassMethods
        # Create resource
        #
        # @param attributes [Hash] Resoruce attributes
        # @return [Sawyer::Resource] Newly created resource
        #
        def create(attributes)
          new(attributes).create
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ribose-0.4.1 lib/ribose/actions/create.rb
ribose-0.4.0 lib/ribose/actions/create.rb
ribose-0.3.2 lib/ribose/actions/create.rb
ribose-0.3.1 lib/ribose/actions/create.rb