<commit_before>module Simplefb
  require 'net/http'
  require 'json'
  
  class Error < StandardError; end
  
  class << self
    attr_accessor :app_id, :app_secret
    attr_writer :logger
  end
  
  def self.logger
    return @logger ||= BasicLogger.new
  end
  
  def self.app_access_token
    "#{@app_id}|#{@app_secret}"
  end
  
  def self.query_endpoint(endpoint, access_token, options={})
    logger.info "Querying endpoint: #{endpoint}"
    options[:access_token]=access_token
    perform_request("https://graph.facebook.com/#{endpoint}", options)
  end
  
  def self.debug_token(access_token)
    logger.info "Debugging token"
    raise Error, "No Access Token Given" unless access_token
    perform_request("https://graph.facebook.com/debug_token", :input_token=>access_token, :access_token=>app_access_token)
  end
  
  def self.get_access_token(code, redirect_uri)
    raise Error, "No code given" unless code
    logger.info "*** Getting access token"
    
    access_token_response = perform_request("https://graph.facebook.com/oauth/access_token", :client_id=>@app_id, :redirect_uri=>redirect_uri, :client_secret=>@app_secret, :code=>code)
        
    cracked_access_token_response=access_token_response.body.scan(/(\w+)=(\w+)+/)
    cracked_access_token_response_hash=cracked_access_token_response.reduce({}) { |hash, curr| hash[curr[0]]=curr[1];hash } 
    access_token=cracked_access_token_response_hash['access_token']
    
    return access_token
  end
  
  def self.get_login_prompt_url(redirect_uri)
    raise Error, 'No app ID provided' unless @app_id
    url="https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&scope=public_profile,email,user_friends&redirect_uri=#{redirect_uri}"
    return url
  end
  
  private
  
  def self.debug_response(response)
    logger.debug "#{response.code}"
    logger.debug response.body
    response.each do |header, value|
      logger.debug "#{header}, #{value}"
    end
  end<commit_msg>-Parse Unix times for better readability<commit_after>module Simplefb
  require 'net/http'
  require 'json'
  
  class Error < StandardError; end
  
  class << self
    attr_accessor :app_id, :app_secret
    attr_writer :logger
  end
  
  def self.logger
    return @logger ||= BasicLogger.new
  end
  
  def self.app_access_token
    "#{@app_id}|#{@app_secret}"
  end
  
  def self.query_endpoint(endpoint, access_token, options={})
    logger.info "Querying endpoint: #{endpoint}"
    options[:access_token]=access_token
    perform_request("https://graph.facebook.com/#{endpoint}", options)
  end
  
  def self.debug_token(access_token)
    logger.info "Debugging token"
    raise Error, "No Access Token Given" unless access_token
    response=perform_request("https://graph.facebook.com/debug_token", :input_token=>access_token, :access_token=>app_access_token)
    
    # Parse Unix times for easier reading
    %w(issued_at expires_at).each {|field| response['data'][field]=Time.at(response['data'][field])}
    response
  end
  
  def self.get_access_token(code, redirect_uri)
    raise Error, "No code given" unless code
    logger.info "*** Getting access token"
    
    access_token_response = perform_request("https://graph.facebook.com/oauth/access_token", :client_id=>@app_id, :redirect_uri=>redirect_uri, :client_secret=>@app_secret, :code=>code)
        
    cracked_access_token_response=access_token_response.body.scan(/(\w+)=(\w+)+/)
    cracked_access_token_response_hash=cracked_access_token_response.reduce({}) { |hash, curr| hash[curr[0]]=curr[1];hash } 
    access_token=cracked_access_token_response_hash['access_token']
    
    return access_token
  end
  
  def self.get_login_prompt_url(redirect_uri)
    raise Error, 'No app ID provided' unless @app_id
    url="https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&scope=public_profile,email,user_friends&redirect_uri=#{redirect_uri}"
    return url
  end
  
  private
  
  def self.debug_response(response)
    logger.debug "#{response.code}"
    logger.debug response.body
    response.each do |header, value|
      logger.debug "#{header}, #{value}"
    end
  end
{'fraction_non_alphanumeric': 0.12144073983937698, 'fraction_numerical': 0.0009734728644439036, 'mean_word_length': 4.407894736842105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, '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': '6159967', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1336, 'n_words': 247}