lib/learnosity/sdk/request/init.rb
# XXX: Needs to be public for unit tests
Needs to be public for unit tests
Needs to be public for unit tests
def validate
          if @service.nil?
            raise Learnosity::Sdk::ValidationException, 'The `service` argument wasn\'t found or was empty'
          elsif ! @@valid_services.include? @service
            raise Learnosity::Sdk::ValidationException, "The service provided (#{service}) is not valid"
          end
          if @security_packet.nil? or ! @security_packet.is_a? Hash
            raise Learnosity::Sdk::ValidationException, 'The security packet must be a Hash'
          else
            @security_packet.each do |k, v|
              unless @@valid_security_keys.include? k
                raise ValidationException, "Invalid key found in the security packet: #{k}"
              end
            end
            if @service == 'questions' and ! @security_packet.include? 'user_id'
              raise ValidationException, 'Questions API requires a `user_id` in the security packet'
            end
            unless @security_packet.include? 'timestamp'
              @security_packet['timestamp'] = Time.now.gmtime.strftime('%Y%m%d-%H%m')
            end
          end
          if @secret.nil? or ! @secret.is_a? String
            raise ValidationException, 'The `secret` argument must be a valid string'
          end
          if ! @request_packet.nil? and ! @request_packet.is_a? Hash
            raise ValidationException, 'The request packet must be a hash'
          end
          if ! @action.nil? and ! @action.is_a? String
            raise ValidationException, 'The `action` argument must be a string'
          end
        end
def validate if @service . nil? raise Learnosity :: Sdk :: ValidationException , 'The `service` argument wasn\'t found or was empty' elsif ! @@valid_services . include? @service raise Learnosity :: Sdk :: ValidationException , "The service provided (#{service}) is not valid" end if @security_packet . nil? or ! @security_packet . is_a? Hash raise Learnosity :: Sdk :: ValidationException , 'The security packet must be a Hash' else @security_packet . each do | k , v | unless @@valid_security_keys . include? k raise ValidationException , "Invalid key found in the security packet: #{k}" end end if @service == 'questions' and ! @security_packet . include? 'user_id' raise ValidationException , 'Questions API requires a `user_id` in the security packet' end unless @security_packet . include? 'timestamp' @security_packet [ 'timestamp' ] = Time . now . gmtime . strftime ( '%Y%m%d-%H%m' ) end end if @secret . nil? or ! @secret . is_a? String raise ValidationException , 'The `secret` argument must be a valid string' end if ! @request_packet . nil? and ! @request_packet . is_a? Hash raise ValidationException , 'The request packet must be a hash' end if ! @action . nil? and ! @action . is_a? String raise ValidationException , 'The `action` argument must be a string' end end
XXX: Needs to be public for unit tests
XXX : Needs to be public for unit tests
# XXX we don't do JSON to native object conversion for now, as the PHP SDK does # XXX we don't do JSON to native object conversion for now, as the PHP SDK does