Module: Fattura24::Api
- Defined in:
- lib/fattura24/api/client.rb,
lib/fattura24/api/response.rb more...
Defined Under Namespace
Classes: Response
Constant Summary collapse
- API_HOST =
This library uses fattura24.com v0.3 apis. Check their docs here.
'https://www.app.fattura24.com/api/v0.3'
Class Method Summary collapse
-
.get_file(id) ⇒ Object
Donwloads a pdf file for an existing document.
-
.get_numerator ⇒ Object
Gets numerator list.
-
.get_pdc ⇒ Object
Gets ‘piano dei conti’ Returns a Response object.
-
.get_product(options = {}) ⇒ Object
Gets a list of products.
-
.get_template ⇒ Object
Gets a list of document templates.
-
.request(path, body = {}) ⇒ Object
Performs a generic request on the api endpoint using Ruby’s Net::HTTP.
-
.save_customer(data = {}) ⇒ Object
Saves a customer in your contact list.
-
.save_document(data = {}) ⇒ Object
Use this to create documents.
-
.save_item(data = {}) ⇒ Object
Creates a credit.
-
.test_key ⇒ Object
Tests validity of your api key.
Class Method Details
permalink .get_file(id) ⇒ Object
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.
71 72 73 74 75 |
# 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 |
permalink .get_numerator ⇒ Object
Gets numerator list. Returns a Response object.
60 61 62 |
# File 'lib/fattura24/api/client.rb', line 60 def self.get_numerator request('/GetNumerator') end |
permalink .get_pdc ⇒ Object
Gets ‘piano dei conti’ Returns a Response object.
53 54 55 |
# File 'lib/fattura24/api/client.rb', line 53 def self.get_pdc request('/GetPdc') end |
permalink .get_product(options = {}) ⇒ Object
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.
85 86 87 88 |
# File 'lib/fattura24/api/client.rb', line 85 def self.get_product( = {}) validate_params(, %i[code category]) request('/GetProduct', ) end |
permalink .get_template ⇒ Object
Gets a list of document templates. Returns a Response object.
46 47 48 |
# File 'lib/fattura24/api/client.rb', line 46 def self.get_template request('/GetTemplate') end |
permalink .request(path, body = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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)) = { use_ssl: uri.scheme == 'https' } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end Response.new(response) end |
permalink .save_customer(data = {}) ⇒ Object
97 98 99 100 101 |
# File 'lib/fattura24/api/client.rb', line 97 def self.save_customer(data = {}) request('/SaveCustomer', { xml: hash_to_xml(data) }) end |
permalink .save_document(data = {}) ⇒ Object
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.
111 112 113 114 115 |
# File 'lib/fattura24/api/client.rb', line 111 def self.save_document(data = {}) request('/SaveDocument', { xml: hash_to_xml(data) }) end |
permalink .save_item(data = {}) ⇒ Object
122 123 124 125 126 |
# File 'lib/fattura24/api/client.rb', line 122 def self.save_item(data = {}) request('/SaveItem', { xml: hash_to_xml(data) }) end |
permalink .test_key ⇒ Object
Tests validity of your api key. Returns a Response object.
37 38 39 |
# File 'lib/fattura24/api/client.rb', line 37 def self.test_key request('/TestKey') end |