Sha256: f4cb843ee47cc85239ea6b8afdf1eb488a695f5a1da1b7a257f3766d3fee990c

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

module GroupDocs
  module Api
    module Helpers
      module AccessRights

        include Api::Helpers::ByteFlag
        #Changed in release 1.5.9
        ACCESS_RIGHTS = {
          :view     => 1,
          :annotate => 2,
          :download => 4,
          :export   => 8,
          :all => 31
        }

        private

        #
        # Converts shared link access rights array to byte flag.
        #
        # @param [Array<String, Symbol>] rights
        # @return [Integer]
        # @raise [ArgumentError] if rights is not an array
        # @raise [ArgumentError] if right is unknown
        # @api private
        #
        def convert_access_rights_to_byte(rights)
          rights.is_a?(Array) or raise ArgumentError, "Rights should be an array, received: #{rights.inspect}"
          rights = rights.map(&:to_sym)

          possible_rights = ACCESS_RIGHTS.map { |hash| hash.first }
          rights.each do |right|
            possible_rights.include?(right) or raise ArgumentError, "Unknown access right: #{rights.inspect}"
          end

          byte_from_array(rights, ACCESS_RIGHTS)
        end

        #
        # Converts byte flag to shared link access rights array.
        #
        # @param [Integer] rights
        # @return [Array<Symbol>]
        # @raise [ArgumentError] if rights is not integer
        # @api private
        #
        def convert_byte_to_access_rights(rights)
          rights.is_a?(Integer) or raise ArgumentError, "Rights should be an integer, received: #{rights.inspect}"
          array_from_byte(rights, ACCESS_RIGHTS)
        end

      end # AccessRights
    end # Helpers
  end # Api
end # GroupDocs

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groupdocs-2.3.0 lib/groupdocs/api/helpers/access_rights_helper.rb