<commit_before>require 'json'
require 'rest-client'
require 'base64'
require 'gcore/api/exceptions'
require 'bigdecimal'

module Gcore
  class Api
    class Stores
      class Products
        
        #Display single sales order
        def self.show(params = {})
           store_code = params[:store_id] || params[:store_code]
           sku = params[:sku]
           url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products/#{sku}"
           begin
            return JSON.parse(RestClient.get(url, Gcore::Api.header),  {symbolize_names: true})
           rescue RestClient::ResourceNotFound
             raise Gcore::Api::Exceptions::SalesOrderNotFoundException.new(store_code: store_code, order_number: order_number )
           end           
        end
        
        def self.list(params = {})
          store_code = params[:store_id] || params[:store_code]
          allowed_params = [:limit, :page]
          url_params = params.select{|key, value| allowed_params.include? key} || {}           
          url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products"
          JSON.parse(RestClient.get(url, Gcore::Api.header.merge(params: url_params)), {symbolize_names: true})                
        end
        
        def self.mass_update(params = {})
            store_code = params[:store_id] || params[:store_code]
            verbose_mode = params[:verbose_mode]
            body = params[:body]
            url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products"
            
            #We are concerned with the header only
            resp = RestClient.put(url, body.to_json, Gcore::Api.header).headers
            output = resp.select{|key, value| [:location, :x_batch].include? key}
            
            #Poll the result

            loop do
                begin 
                    #Use HEAD for faster polling instead of GET
                    results = RestClient.head("#{Gcore::Api.endpoint}#{output[:location]}", Gcore::Api.header).headers
                    results.select!{|key, value| [:x_object_processed, :x_object_count].include? key}
                    results[:percentage] = ((BigDecimal.new(results[:x_object_processed]) / BigDecimal.new(results[:x_object_count])) * BigDecimal.new("100")).to_s("F")
                    results[:batch] = output[:x_batch]
                    if verbose_mode
                        Gcore::Api.logger.puts(results)
                    end
                rescue RestClient::ResourceNotFound
                    #Carry on, loop again.
                end
                break if results[:x_object_processed] >= results[:x_object_count]
                sleep 1
            end
            
            JSON.parse(RestClient.get("#{Gcore::Api.endpoint}#{output[:location]}", Gcore::Api.header), {symbolize_names: true})  
            
        end<commit_msg>Comparison of object counts must be integer comparison and not alphanumeric comparison<commit_after>require 'json'
require 'rest-client'
require 'base64'
require 'gcore/api/exceptions'
require 'bigdecimal'

module Gcore
  class Api
    class Stores
      class Products
        
        #Display single sales order
        def self.show(params = {})
           store_code = params[:store_id] || params[:store_code]
           sku = params[:sku]
           url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products/#{sku}"
           begin
            return JSON.parse(RestClient.get(url, Gcore::Api.header),  {symbolize_names: true})
           rescue RestClient::ResourceNotFound
             raise Gcore::Api::Exceptions::SalesOrderNotFoundException.new(store_code: store_code, order_number: order_number )
           end           
        end
        
        def self.list(params = {})
          store_code = params[:store_id] || params[:store_code]
          allowed_params = [:limit, :page]
          url_params = params.select{|key, value| allowed_params.include? key} || {}           
          url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products"
          JSON.parse(RestClient.get(url, Gcore::Api.header.merge(params: url_params)), {symbolize_names: true})                
        end
        
        def self.mass_update(params = {})
            store_code = params[:store_id] || params[:store_code]
            verbose_mode = params[:verbose_mode]
            body = params[:body]
            url = "#{Gcore::Api.endpoint}/stores/#{store_code}/products"
            
            #We are concerned with the header only
            resp = RestClient.put(url, body.to_json, Gcore::Api.header).headers
            output = resp.select{|key, value| [:location, :x_batch].include? key}
            
            #Poll the result

            loop do
                begin 
                    #Use HEAD for faster polling instead of GET
                    results = RestClient.head("#{Gcore::Api.endpoint}#{output[:location]}", Gcore::Api.header).headers
                    results.select!{|key, value| [:x_object_processed, :x_object_count].include? key}
                    results[:percentage] = ((BigDecimal.new(results[:x_object_processed]) / BigDecimal.new(results[:x_object_count])) * BigDecimal.new("100")).to_s("F")
                    results[:batch] = output[:x_batch]
                    if verbose_mode
                        Gcore::Api.logger.puts(results)
                    end
                    break if results[:x_object_processed].to_i >= results[:x_object_count].to_i
                rescue RestClient::ResourceNotFound
                    #Carry on, loop again.
                rescue StandardError => ex
                    Gcore::Api.logger.puts({message: ex.message, class: ex.class.name})
                end
                sleep 1
            end
            
            JSON.parse(RestClient.get("#{Gcore::Api.endpoint}#{output[:location]}", Gcore::Api.header), {symbolize_names: true})  
            
        end
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.002028397565922921, 'mean_word_length': 1.9868753154972236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7226819', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1588, 'n_words': 309}