Sha256: a1cec91de9e2eec46c162ddff3519a4eaff8c2033d9f81b669d75c41504104ba

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

module RedboothRuby
  module Operations
    module Base
      module ClassMethods
        include RedboothRuby::Helpers
        # Options for request
        # overwrite this in the model to set security
        #
        # @return [Hash]
        def options_for_request(attributes)
          fail AuthenticationError unless attributes[:session]
          {
            session: attributes[:session]
          }
        end

        protected

        # URl for the member endpoints
        # overwrite this in the model if the api is not well named
        #
        def api_member_url(id = nil, method = nil)
          url = api_resource_name(method)
          url += "/#{ id }" if id
          url
        end

        # URl for the collection endpoints
        # overwrite this in the model if the api is not well named
        #
        def api_collection_url(attrs = {})
          api_resource_name
        end

        # resource name
        # overwrite this in the model if the api is not well named
        #
        def api_resource_name(method = nil)
          "#{ underscore(name.split('::').last) }s"
        end
      end

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
redbooth-ruby-0.2.3 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.2.2 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.2.1 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.2.0 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.1.4 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.1.3 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.1.1 lib/redbooth-ruby/operations/base.rb
redbooth-ruby-0.1.0 lib/redbooth-ruby/operations/base.rb