module Fattura24::Api

Constants

API_HOST

This library uses fattura24.com v0.3 apis. Check their docs here.

Public Class Methods

get_file(id) click to toggle source

Donwloads a pdf file for an existing document. Requires an existing document id, throws MissingInput when passing a nil id. Returns a Response object: refer to it's documentation to detect a binary file and instruction to save it to disk.

# File lib/fattura24/api/client.rb, line 71
def self.get_file(id)
  raise(Fattura24::MissingInput, 'You need to provide an id') unless id

  request('/GetFile', { docId: id })
end
get_numerator() click to toggle source

Gets numerator list. Returns a Response object.

# File lib/fattura24/api/client.rb, line 60
def self.get_numerator
  request('/GetNumerator')
end
get_pdc() click to toggle source

Gets 'piano dei conti' Returns a Response object.

# File lib/fattura24/api/client.rb, line 53
def self.get_pdc
  request('/GetPdc')
end
get_product(options = {}) click to toggle source

Gets a list of products. You can pass a Hash containing a code or category to filter your existing products by them. Throws a InvalidParams when passing an hash containing unrecognized options. Returns a Response object.

# File lib/fattura24/api/client.rb, line 85
def self.get_product(options = {})
  validate_params(options, %i[code category])
  request('/GetProduct', options)
end
get_template() click to toggle source

Gets a list of document templates. Returns a Response object.

# File lib/fattura24/api/client.rb, line 46
def self.get_template
  request('/GetTemplate')
end
request(path, body = {}) click to toggle source

Performs a generic request on the api endpoint using Ruby's Net::HTTP. All the other api methods call this one. Parameter path should always be prepended with '/'. Body will default to an empty hash. Returns a Response object.

# File lib/fattura24/api/client.rb, line 19
def self.request(path, body = {})
  raise Fattura24::MissingApiKey unless Fattura24.configuration.api_key

  uri = URI.parse("#{API_HOST}#{path}")
  request = Net::HTTP::Post.new(uri)
  request.set_form_data(inject_api_key(body))

  req_options = { use_ssl: uri.scheme == 'https' }
  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
    http.request(request)
  end

  Response.new(response)
end
save_customer(data = {}) click to toggle source

Saves a customer in your contact list. Any nil parameter will be deeply removed by using the crush utility. Returns a Response object.

# File lib/fattura24/api/client.rb, line 97
def self.save_customer(data = {})
  request('/SaveCustomer', {
    xml: hash_to_xml(data)
  })
end
save_document(data = {}) click to toggle source

Use this to create documents. Pass a hash with the data, check the README file for examples. Use DocumentType enums to specify document type. Any nil parameter will be deeply removed by using the crush utility. Returns a Response object.

# File lib/fattura24/api/client.rb, line 111
def self.save_document(data = {})
  request('/SaveDocument', {
    xml: hash_to_xml(data)
  })
end
save_item(data = {}) click to toggle source

Creates a credit. Any nil parameter will be deeply removed by using the crush utility. Returns a Response object.

# File lib/fattura24/api/client.rb, line 122
def self.save_item(data = {})
  request('/SaveItem', {
    xml: hash_to_xml(data)
  })
end
test_key() click to toggle source

Tests validity of your api key. Returns a Response object.

# File lib/fattura24/api/client.rb, line 37
def self.test_key
  request('/TestKey')
end