<commit_before>module WooApi
  module AppApi
    class User < Base
      RESOURCE_PATH = 'user/'

      def self.login
        request = build_request("#{RESOURCE_PATH}login", {
          email: ENV['WOO_APP_API_EMAIL'],
          pass: Digest::SHA512.new.update(ENV['WOO_APP_API_PASSWORD'])
        })
        response = HTTPI.post(request)
        json_body = JSON(response.body)
        if response.code == 200
          save_access_token(json_body)
        end
        response
      end

      # when no user is supplied, the users' own profile is returned
      def self.profile(user=nil)
        HTTPI.post(build_request("#{RESOURCE_PATH}profile/#{user.woo_id}", token_auth: true))
      end

      def self.search(options={query: '', offset: 0, pageSize: 10})
        HTTPI.post(build_request("#{RESOURCE_PATH}search", {token_auth: true}.merge(options)))
      end

      private

      def self.save_access_token(json_body)
        WooAppApiToken.create({
          access_token: json_body['access_token'],
          expires_at: json_body['expires_in'].seconds.from_now - 1.hour,
          scope: json_body['scope'],
          refresh_token: json_body['refresh_token']
        })
      end<commit_msg>Fix construction of path for requesting users from the API<commit_after>module WooApi
  module AppApi
    class User < Base
      RESOURCE_PATH = '/user'

      def self.login
        request = build_request("#{RESOURCE_PATH}/login", {
          email: ENV['WOO_APP_API_EMAIL'],
          pass: Digest::SHA512.new.update(ENV['WOO_APP_API_PASSWORD'])
        })
        response = HTTPI.post(request)
        json_body = JSON(response.body)
        if response.code == 200
          save_access_token(json_body)
        end
        response
      end

      # when no user is supplied, the users' own profile is returned
      def self.profile(user=nil)
        HTTPI.post(build_request("#{RESOURCE_PATH}profile/#{user.woo_id}", token_auth: true))
      end

      def self.search(options={query: '', offset: 0, pageSize: 10})
        HTTPI.post(build_request("#{RESOURCE_PATH}search", {token_auth: true}.merge(options)))
      end

      private

      def self.save_access_token(json_body)
        WooAppApiToken.create({
          access_token: json_body['access_token'],
          expires_at: json_body['expires_in'].seconds.from_now - 1.hour,
          scope: json_body['scope'],
          refresh_token: json_body['refresh_token']
        })
      end
{'fraction_non_alphanumeric': 0.11313868613138686, 'fraction_numerical': 0.008110300081103, 'mean_word_length': 2.6226138032305433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5366627', 'n_tokens_mistral': 785, 'n_tokens_neox': 753, 'n_words': 146}