Skip to main content

Ruby SDK Samples - Share Records Operations

Get Shared Record Details
Share a Record
              
              
require 'ZOHOCRMSDK2_0'
class SharedRecord
    def self.share_record(module_api_name, record_id)
    # """
    # This method is used to share the record and print the response.
    # :param module_api_name: The API Name of the module to share record.
    # :param record_id: The ID of the record to be shared
    # """

    # """
    # example
    # module_api_name = Contacts
    # record_id = 34096432112011
    # """
    # List to hold ShareRecord instances
    share_records = []
    # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
    sro = ZOHOCRMSDK::ShareRecords::ShareRecordsOperations.new(record_id, module_api_name)
    # Get instance of BodyWrapper Class that will contain the request body
    bw = ZOHOCRMSDK::ShareRecords::BodyWrapper.new
    # Get instance of User Class
    user = ZOHOCRMSDK::Users::User.new
    # Set User ID
    user.id = 34770615791024
    (0..1).each do |i|
      # Get instance of ShareRecord Class
      share_record = ZOHOCRMSDK::ShareRecords::ShareRecord.new
      # Set boolean value to share related records
      share_record.share_related_records = true
      # Set the permission. Possible values - full_access, read_only, read_write
      share_record.permission = 'read_write'
      # Set the User instance to user
      share_record.user = user
      # Add the instance to list
      share_records.push(share_record)
    end
    # Set the list to share of BodyWrapper instance
    bw.share = share_records
    # Call share_record method that takes BodyWrapper instance as parameter
    response = sro.share_record(bw)
    unless response.nil?
      status_code = response.status_code
      # Get the status code from response
      print "\n Status Code :" + status_code.to_s
      # Check if expected instance is received.
      if response.is_expected
        # Get object from response
        action_handler = response.data_object
        # Check if expected ActionWrapper instance is received.
        if action_handler.is_a? ZOHOCRMSDK::ShareRecords::ActionWrapper
          action_wrapper = action_handler
          # Get the list of obtained ActionResponse instances
          action_responses = action_wrapper.share
          action_responses.each do |action_response|
            # Check if expected SuccessResponse instance is received
            if action_response.is_a? ZOHOCRMSDK::ShareRecords::SuccessResponse
              success_response = action_response
              # Get the Code
              print 'code:'
              print success_response.code.value
              # Get the Status
              print "\n status:"
              print success_response.status.value
              # Get the Message
              print "\n message:"
              print success_response.message.value
              success_response.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end
            # Check if the request returned an exception
            elsif action_response.is_a? ZOHOCRMSDK::ShareRecords::APIException
              api_exception = action_response
              # Get the Code
              print 'code:'
              print api_exception.code.value
              # Get the Status
              print "\n status:"
              print api_exception.status.value
              # Get the Message
              print "\n message:"
              print api_exception.message.value
              # Get the details map
              api_exception.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end
              print "\n"
            end
          end
        # Check if the request returned an exception
        elsif action_handler.is_a? ZOHOCRMSDK::ShareRecords::APIException
          exception = action_handler
          # Get the Code
          print 'code:'
          print exception.code.value
          # Get the Status
          print "\n status:"
          print exception.status.value
          # Get the Message
          print "\n message:"
          print exception.message.value
          # Get the details map
          exception.details.each do |k, v|
            print "\n"
            print k
            print v
            print "\n"
          end
          print "\n"
        end
      else
        response_object = response.data_object
        response_object.instance_variables.each do |field|
          print field
          print "\n"
          print response_object.instance_variable_get(field)
        end
      end
    end
  end
end
 
Update Share Permissions
              
              
require 'ZOHOCRMSDK2_0'
class SharedRecord
    def self.update_share_permissions(module_api_name, record_id)
    # """
    # This method is used to update the sharing permissions of a record granted to users as Read-Write, Read-only, or grant full access.
    # :param module_api_name: The API Name of the module to update share permissions.
    # :param record_id: The ID of the record
    # """

    # """
    # example
    # module_api_name = Contacts
    # record_id = 34096432112011
    # """
    # List to hold ShareRecord instances
    share_records = []
    # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
    sro = ZOHOCRMSDK::ShareRecords::ShareRecordsOperations.new(record_id, module_api_name)
    # Get instance of BodyWrapper Class that will contain the request body
    bw = ZOHOCRMSDK::ShareRecords::BodyWrapper.new
    # Get instance of User Class
    user = ZOHOCRMSDK::Users::User.new
    # Set User ID
    user.id = 3_477_061_000_005_791_024
    (0..1).each do |i|
      share_record = ZOHOCRMSDK::ShareRecords::ShareRecord.new
      # Set boolean value to share related records
      share_record.share_related_records = true
      # Set the permission. Possible values - full_access, read_only, read_write
      share_record.permission = 'full_access'
      # Set the User instance to user
      share_record.user = user
      # Add the instance to list
      share_records.push(share_record)
    end
    # Set the list to share of BodyWrapper instance
    bw.share = share_records
    response = sro.update_share_permissions(bw)
    unless response.nil?
      status_code = response.status_code
      # Get the status code from response
      print "\n Status Code :" + status_code.to_s
      # Check if expected instance is received.
      if response.is_expected
        # Get object from response
        action_handler = response.data_object
        # Check if expected ActionWrapper instance is received.
        if action_handler.is_a? ZOHOCRMSDK::ShareRecords::ActionWrapper
          action_wrapper = action_handler
          action_responses = action_wrapper.share
          action_responses.each do |action_response|
            # Check if expected SuccessResponse instance is received
            if action_response.is_a? ZOHOCRMSDK::ShareRecords::SuccessResponse
              success_response = action_response
              # Get the Code
              print 'code:'
              print success_response.code.value
              # Get the Status
              print "\n status:"
              print success_response.status.value
              # Get the Message
              print "\n message:"
              print success_response.message.value
              # Get the details
              success_response.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end

            # Check if the request returned an exception
            elsif action_response.is_a? ZOHOCRMSDK::ShareRecords::APIException
              api_exception = action_response
              # Get the Code
              print 'code:'
              print api_exception.code.value
              # Get the Status
              print "\n status:"
              print api_exception.status.value
              # Get the Message
              print "\n message:"
              print api_exception.message.value
              # Get the details map
              api_exception.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end
              print "\n"
            end
          end
        # Check if the request returned an exception
        elsif action_handler.is_a? ZOHOCRMSDK::ShareRecords::APIException
          exception = action_handler
          # Get the Code
          print 'code:'
          print exception.code.value
          # Get the Status
          print "\n status:"
          print exception.status.value
          # Get the Message
          print "\n message:"
          print exception.message.value
          # Get the Detail
          exception.details.each do |k, v|
            print "\n"
            print k
            print v
            print "\n"
          end
          print "\n"
        end
      else
        response_object = response.data_object
        response_object.instance_variables.each do |field|
          print field
          print "\n"
          print response_object.instance_variable_get(field)
        end
      end
    end
  end
end
 
Revoke Access to a Shared Record
              
              
require 'ZOHOCRMSDK2_0'
class SharedRecord
    def self.revoke_shared_record(module_api_name, record_id)
    # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
    sro = ZOHOCRMSDK::ShareRecords::ShareRecordsOperations.new(record_id, module_api_name)
    # Call revoke_shared_record method
    response = sro.revoke_shared_record
    unless response.nil?
      status_code = response.status_code
      # Get the status code from response
      print "\n Status Code :" + status_code.to_s
      # Check if expected instance is received.
      if response.is_expected
        # Get object from response
        action_handler = response.data_object
        # Check if expected DeleteActionWrapper instance is received.
        if action_handler.is_a? ZOHOCRMSDK::ShareRecords::DeleteActionWrapper
          action_wrapper = action_handler
          # Get the list of obtained ActionResponse instances
          action_response = action_wrapper.share
          if !action_response.nil?
             # Check if expected SuccessResponse instance is received
             if action_response.is_a? ZOHOCRMSDK::ShareRecords::SuccessResponse
              success_response = action_response
              # Get the Code
              print 'code:'
              print success_response.code.value
              # Get the Status
              print "\n status:"
              print success_response.status.value
              # Get the Message
              print "\n message:"
              print success_response.message.value
              # Get the details dict
              success_response.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end

            # Check if the request returned an exception
            elsif action_response.is_a? ZOHOCRMSDK::ShareRecords::APIException
              api_exception = action_response
              # Get the Code
              print 'code:'
              print api_exception.code.value
              # Get the Status
              print "\n status:"
              print api_exception.status.value
              # Get the Message
              print "\n message:"
              print api_exception.message.value
              # Get the details map
              api_exception.details.each do |k, v|
                print "\n"
                print k
                print v
                print "\n"
              end
              print "\n"
            end
          end
        # Check if the request returned an exception
        elsif action_handler.is_a? ZOHOCRMSDK::ShareRecords::APIException
          exception = action_handler
          # Get the Code
          print 'code:'
          print exception.code.value
          # Get the Status
          print "\n status:"
          print exception.status.value
          # Get the Message
          print "\n message:"
          print exception.message.value
          # Get the details dict
          exception.details.each do |k, v|
            print "\n"
            print k
            print v
            print "\n"
          end
          print "\n"
        end
      else
        response_object = response.data_object
        response_object.instance_variables.each do |field|
          print field
          print "\n"
          print response_object.instance_variable_get(field)
        end
      end
    end
  end
end