<commit_before>class ADM::AccessToken
  attr_reader :client_id, :client_secret
  attr_reader :token

  def initialize opts
    @token      = opts['access_token']
    @expires_at = Time.now+opts['expires_in'].to_i
    @type       = opts['token_type']
    @scope      = opts['scope']
  end

  def to_s
    token
  end

  def valid?
    @expires_at < Time.now
  end

  def self.fetch client_id=nil, client_secret=nil
    client_id ||= ADM.client_id
    client_secret ||= ADM.client_secret
    data = request_data client_id, client_secret

    if data['error']
      raise TokenGetError, data['error_description']
    end

    new(data)
  end

  def self.request_data client_id, client_secret
    request = Typhoeus::Request.new(
      'https://api.amazon.com/auth/O2/token',
      method: :post,
      body: {
        grant_type: :'client_credentials',
        scope: :'messaging:push',
        client_id: client_id,
        client_secret: client_secret
      },
      headers: {
        :Accept => :'application/json'
      }
    )<commit_msg>using params option insted of body (it is not 'x-www-form-urlencoded')<commit_after>class ADM::AccessToken
  attr_reader :client_id, :client_secret
  attr_reader :token

  def initialize opts
    @token      = opts['access_token']
    @expires_at = Time.now+opts['expires_in'].to_i
    @type       = opts['token_type']
    @scope      = opts['scope']
  end

  def to_s
    token
  end

  def valid?
    @expires_at < Time.now
  end

  def self.fetch client_id=nil, client_secret=nil
    client_id ||= ADM.client_id
    client_secret ||= ADM.client_secret
    data = request_data client_id, client_secret

    if data['error']
      raise TokenGetError, data['error_description']
    end

    new(data)
  end

  def self.request_data client_id, client_secret
    request = Typhoeus::Request.new(
      'https://api.amazon.com/auth/O2/token',
      method: :post,
      params: {
        grant_type: :'client_credentials',
        scope: :'messaging:push',
        client_id: client_id,
        client_secret: client_secret
      },
      headers: {
        :Accept => :'application/json'
      }
    )
{'fraction_non_alphanumeric': 0.11069593647828117, 'fraction_numerical': 0.0009341429238673517, 'mean_word_length': 2.712305025996534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '1169270', 'n_tokens_mistral': 727, 'n_tokens_neox': 709, 'n_words': 147}