Skip to main content

Ruby SDK Samples - Profile Operations

Get All Profiles
              
              
require 'ZOHOCRMSDK2_0'
class Profile
    def self.get_profiles
    # """
    # This method is used to retrieve the profiles data through an API request and print the response.
    # """
    # Get instance of ProfilesOperations Class
    po = Profiles::ProfilesOperations.new(DateTime.new(2018, 8, 10, 4, 11, 9, '+03:00'))
    # Call get_profiles method
    response = po.get_profiles
    status_code = response.status_code
    print "\n Status Code :" + status_code.to_s
    if [204, 304].include? status_code
      print(status_code == 204 ? 'No Content' : 'Not Modified')
      return
    end
    # Check if expected instance is received.
    if response.is_expected
      response_handler = response.data_object
      # Check if expected ResponseWrapper instance is received
      if response_handler.is_a? Profiles::ResponseWrapper
        # Get the list of obtained Profile instances
        profiles = response_handler.profiles
        profiles.each do |profile|
          # Get the DisplayLabel of the each Profile
          print "\n Profile DisplayLabel:"
          print profile.display_label
          unless profile.created_time.nil?
            # Get the CreatedTime of each Profile
            print "\n Profile CreatedTime:"
            print profile.created_time
          end
          unless profile.modified_time.nil?
            # Get the ModifiedTime of each Profile
            print "\n Profile ModifiedTime:"
            print profile.modified_time
          end
          # Get the Name of the each Profile
          print "\n Profile Name:"
          print profile.name
          # Get the Created User instance of each Profile
          created_by = profile.created_by
          # Check if created_by is not None
          unless created_by.nil?
            # Get the Name of the Created User
            print "\n Profile Created By User-Name:"
            print created_by.name
            # Get the ID of the Created User
            print "\n Profile Created By User-ID:"
            print created_by.id.to_s
          end
          # Get the modifiedBy User instance of each Profile
          modified_by = profile.modified_by
          # Check if modifiedBy is not None
          unless modified_by.nil?
            # Get the Name of the modifiedBy User
            print "\n Profile Modified User-Name:"
            print modified_by.id.to_s
            # Get the ID of the modifiedBy User
            print "\n Profile Modified User-ID:"
            print modified_by.name
          end
          # Get the Description of the each Profile
          print "\n Profile Description:"
          print profile.description
          # Get the ID of the each Profile
          print "\n Profile ID:"
          print profile.id.to_s
          # Get the Category of the each Profile
          print "\n Profile Category:"
          print profile.category
        end
      # Check if the request returned an exception
      elsif response_handler.is_a? Profiles::APIException
        exception = response_handler
        # Get the Code
        print 'code:'
        print exception.code.value
        # Get the Status
        print "\n status:"
        print exception.status.value
        # Get the details map
        exception.details.each do |k, v|
          print "\n"
          print k
          print v
          print "\n"
        end
        # Get the Message
        print "\n message:"
        print exception.message.value
        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
Get Specific Profile