<commit_before>require 'json'
require 'faraday'
require 'yaml'

# Accessor for the Government's API that
# allows the GET and POST methods.
class ApiAccessor

  def initialize
    read_config
    @conn = Faraday.new(:url => @base_uri) do |faraday|
      # faraday.request :url_encoded # form-encode POST params
      # faraday.response :logger                  # log requests to STDOUT
      faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
    end
    new_access_token
  end

  # Reads the configuration of the environment to use.
  # Params:
  # +env+:: environment to use. Default is testing
  def read_config(env = 'production')
    config = YAML.load_file('config/gov_api.yml')
    @base_uri = config[env]['uri']
    @req_token = config[env]['request_token']
    @client_secret = config[env]['client_secret']
  end

  # Gets the information of a public body.
  # Params:
  # +id+:: id to obtain a single public body, none to get all.
  def get_bodies(id = nil, page = '1')
    check_expiry
    if id
      return @conn.get "instituciones/#{id}"
    end
    @conn.get 'instituciones', {:page => page}
  end

  # Gets the information of a request.<commit_msg>Setting timeout to 5 seconds<commit_after>require 'json'
require 'faraday'
require 'yaml'

# Accessor for the Government's API that
# allows the GET and POST methods.
class ApiAccessor

  def initialize
    read_config
    @conn = Faraday.new(:url => @base_uri) do |faraday|
      # faraday.request :url_encoded # form-encode POST params
      # faraday.response :logger                  # log requests to STDOUT
      faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
      faraday.options.timeout = 5
    end
    new_access_token
  end

  # Reads the configuration of the environment to use.
  # Params:
  # +env+:: environment to use. Default is testing
  def read_config(env = 'production')
    config = YAML.load_file('config/gov_api.yml')
    @base_uri = config[env]['uri']
    @req_token = config[env]['request_token']
    @client_secret = config[env]['client_secret']
  end

  # Gets the information of a public body.
  # Params:
  # +id+:: id to obtain a single public body, none to get all.
  def get_bodies(id = nil, page = '1')
    check_expiry
    if id
      return @conn.get "instituciones/#{id}"
    end
    @conn.get 'instituciones', {:page => page}
  end

  # Gets the information of a request.
{'fraction_non_alphanumeric': 0.10302027306578403, 'fraction_numerical': 0.0016549441456350847, 'mean_word_length': 3.1979166666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6853830', 'n_tokens_mistral': 791, 'n_tokens_neox': 749, 'n_words': 243}