<commit_before># encoding: utf-8
module Fakturownia
  module API

    # Get JSON-formatted invoice based on invoice id (from Fakturownia)
    def self.invoice invoice_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.json"
      response = self.make_get_request(endpoint)

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get JSON-formatted invoice based on order id
    def self.invoice_by_order_id order_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices"
      response = self.make_get_request(endpoint, { :oid => order_id })

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get JSON-formatted invoices based from given period
    # Available periods = [:all, :this_month, :last_month, :this_year, :last_year, :more]
    # If period = :more than date_from and date_to has to be set
    def self.invoices period, date_from = nil, date_to = nil
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices.json?period=#{period}"
      additional_params = { :period => period }
      if period.to_s == 'more'
        additional_params[:date_from] = date_from
        additional_params[:date_to] = date_to
      end
      response = self.make_get_request(endpoint, additional_params)

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get invoice PDF based on invoice id
    def self.pdf invoice_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.pdf"
      response = self.make_get_request(endpoint)
       
      (response.code == '200') ? response.body : nil<commit_msg>Added ".json" suffix for "fakturownia.pl/invoices"<commit_after># encoding: utf-8
module Fakturownia
  module API

    # Get JSON-formatted invoice based on invoice id (from Fakturownia)
    def self.invoice invoice_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.json"
      response = self.make_get_request(endpoint)

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get JSON-formatted invoice based on order id
    def self.invoice_by_order_id order_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices.json"
      response = self.make_get_request(endpoint, { :oid => order_id })

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get JSON-formatted invoices based from given period
    # Available periods = [:all, :this_month, :last_month, :this_year, :last_year, :more]
    # If period = :more than date_from and date_to has to be set
    def self.invoices period, date_from = nil, date_to = nil
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices.json?period=#{period}"
      additional_params = { :period => period }
      if period.to_s == 'more'
        additional_params[:date_from] = date_from
        additional_params[:date_to] = date_to
      end
      response = self.make_get_request(endpoint, additional_params)

      (response.code == '200') ? JSON.parse(response.body) : nil 
    end

    # Get invoice PDF based on invoice id
    def self.pdf invoice_id
      endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.pdf"
      response = self.make_get_request(endpoint)
       
      (response.code == '200') ? response.body : nil
{'fraction_non_alphanumeric': 0.11826086956521739, 'fraction_numerical': 0.007536231884057971, 'mean_word_length': 3.3628318584070795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 8, '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': '623234', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1124, 'n_words': 245}