<commit_before>require 'api-auth'

module Remitano
  class Net
    attr_reader :request

    def initialize(request)
      @request = request
    end

    def execute
      @request.execute do |res, req, result|
        if result.code =~ /^2\d\d$/
          return Remitano::Helper.parse_json(res)
        else
          raise "Error #{result.code} #{res}"
        end
      end
    end

    def self.to_uri(path)
      return "#{server}/api/v1#{path}"
    end

    def self.server
      @server ||= (ENV['REMITANO_SERVER'] || "https://remitano.com")
    end

    def self.public_get(path, params = {})
      options = {
        :url => self.to_uri(path),
        :method => :get,
        :timeout => 20,
        :headers => {
          :params => params
        }
      }
      req = RestClient::Request.new(options)
      req.headers['Content-Type'] = 'application/json'
      new(req)
    end

    def self.get(path)
      request = new_request(:get, path)
      sign_request(request)
    end

    def self.post(path, params={})
      request = new_request(:post, path, params)
      sign_request(request)
    end

    def self.patch(path, params={})
      request = new_request(:put, path, params)
      sign_request(request)
    end

    def self.delete(path, params={})
      request = new_request(:delete, path, params)<commit_msg>set default api lang to vi<commit_after>require 'api-auth'

module Remitano
  class Net
    attr_reader :request

    def initialize(request)
      @request = request
    end

    def execute
      @request.execute do |res, req, result|
        if result.code =~ /^2\d\d$/
          return Remitano::Helper.parse_json(res)
        else
          raise "Error #{result.code} #{res}"
        end
      end
    end

    def self.to_uri(path)
      return "#{server}/api/v1#{path}"
    end

    def self.server
      @server ||= (ENV['REMITANO_SERVER'] || "https://remitano.com")
    end

    def self.public_get(path, params = {})
      options = {
        :url => self.to_uri(path),
        :method => :get,
        :timeout => 20,
        :headers => {
          :params => params,
          :lang => "vi"
        }
      }
      req = RestClient::Request.new(options)
      req.headers['Content-Type'] = 'application/json'
      new(req)
    end

    def self.get(path)
      request = new_request(:get, path)
      sign_request(request)
    end

    def self.post(path, params={})
      request = new_request(:post, path, params)
      sign_request(request)
    end

    def self.patch(path, params={})
      request = new_request(:put, path, params)
      sign_request(request)
    end

    def self.delete(path, params={})
      request = new_request(:delete, path, params)
{'fraction_non_alphanumeric': 0.13264554163596168, 'fraction_numerical': 0.0029476787030213707, 'mean_word_length': 2.146002317497103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3263224', 'n_tokens_mistral': 877, 'n_tokens_neox': 855, 'n_words': 196}