<commit_before>module NikeplusClient
  class Account < Base
    def initialize(username, password)
      @username = username
      @password = password
    end

    def token
      return @access_token if @access_token
      response = extract_hash_from_json_response_body(request_token)
      fail WrongCredential if response.key?('error')
      @access_token = response['access_token']
    end

    private

    def request_token
      post_request('https://developer.nike.com/services/login', username: @username, password: @password)
    end
  end

  class WrongCredential < Exception; end
end<commit_msg>Extract method on Account class<commit_after>module NikeplusClient
  class Account < Base
    def initialize(username, password)
      @username = username
      @password = password
    end

    def token
      return @access_token if @access_token
      response = extract_hash_from_json_response_body(request_token)
      check_token_validy(response)
      @access_token = response['access_token']
    end

    private

    def check_token_validy(response)
      fail WrongCredential unless token_valid?(response)
    end

    def token_valid?(response)
      !response.key?('error')
    end

    def request_token
      post_request('https://developer.nike.com/services/login', username: @username, password: <PASSWORD>)
    end
  end

  class WrongCredential < Exception; end
end
{'fraction_non_alphanumeric': 0.07604017216642754, 'fraction_numerical': 0.0, 'mean_word_length': 3.4568690095846644, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '5084225', 'n_tokens_mistral': 399, 'n_tokens_neox': 383, 'n_words': 97}