Pina
Simple client for Fantozzi REST API.
Installation
Add this line to your application's Gemfile:
gem 'pina'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pina
Docker dev setup
To open development environment in docker:
- install prerequisites
gem install docker-sync
- run
docker volume create --name=gem_store_235
docker-sync start
docker-compose run web bash
Fantozzi API coverage
Resource | All | Find | Find_by | Where | Create | Update | Delete |
---|---|---|---|---|---|---|---|
Contacts | o | o | o | o | o | o | - |
DocumentPairing | o | - | - | - | - | - | - |
MyBankAccount | o | o | - | o | o | o | - |
PettyCashDisburstment | o | o | - | - | - | - | - |
PettyCashIncome | o | o | - | - | - | - | - |
ProcessedDocument | o | o | - | o | - | - | o |
PurchaseInvoice | o | o | - | o | o | o | - |
Receivable | o | o | - | o | - | - | - |
SalesInvoice | o | o | - | o | o | o | - |
SalesOrder | o | o | - | o | - | - | - |
StatProcessedDocument | o | o | - | o | - | - | - |
UploadedDocument | o | o | - | o | o | o | - |
UploadedDocumentPairing | - | - | - | - | o | - | - |
Resources not mentioned = resources not covered.
Usage
Before you start using Pina you have to configure it.
Pina.configure do |config|
config.email = 'your_email@domain.com'
config.tenant = 'your tenant database name'
config.api_token = 'your secret token'
end
Optionally, you can configure Pina to run against other than production instance of Fantozzi:
Pina.configure do |config|
config.api_host = 'localhost:3000'
config.use_ssl = true | false # defaults to true
end
Now you can start querying REST API.
Contacts
All contacts
Pina::Contact.all
Gets all contacts from your database. Results are paginated and you can access first, next or previous page like this:
contacts = Pina::Contact.all
contacts.next_page
contacts = Pina::Contact.all
contacts.previous_page
contacts.first_page
Fetching specific contact
Pina::Contact.find('contact_name')
Create new contact
contact = Pina::Models::Contact.new
Pina::Contact.create(contact)
Update existing contact
contact = Pina::Contact.find('existing')
contact.email = 'brand_new@email.com'
Pina::Contact.update('existing', contact)
Document pairings
All document pairings
Pina::DocumentPairing.all
Gets all document pairings from your database. Results are paginated and you can access first, next or previous page like this:
pairings = Pina::DocumentPairing.all
pairings.next_page
pairings = Pina::DocumentPairing.all
pairings.previous_page
pairings.first_page
Sales Invoices
All sales invoices
Pina::SalesInvoice.all
Gets all sales invocies from your database. Results are paginated and you can access first, next or previous page like this:
invoices = Pina::SalesInvoice.all
invoices.next_page
invoices = Pina::SalesInvoice.all
invoices.previous_page
invoices.first_page
Fetching specific sales invoice
Pina::SalesInvoice.find(invoice_id)
Create new sales invoice
invoice = Pina::Models::SalesInvoice.new
Pina::SalesInvoice.create(invoice)
Update existing sales invoice
invoice = Pina::SalesInvoice.find(2016000001)
invoice.status = :confirmed
Pina::SalesInvoice.update(2016000001, invoice)
Sales Orders
All sales orders
Pina::SalesOrder.all
Gets all sales orders from your database. Results are paginated and you can access first, next or previous page like this:
orders = Pina::SalesOrder.all
orders.next_page
orders = Pina::SalesOrder.all
orders.previous_page
orders.first_page
Fetching specific sales order
Pina::SalesOrder.find(order_id)
Petty Cash Disburstments
All petty cash disburstments
Pina::PettyCashDisburstment.all
Fetching specific petty cash disburstment
Pina::PettyCashDisburstment.find(gid)
Petty Cash Incomes
All petty cash incomes
Pina::PettyCashIncome.all
Fetching specific petty cash income
Pina::PettyCashIncome.find(gid)
Processed Documents
All processed documents
Pina::ProcessedDocument.all
Gets all processed documents from your database. Results are paginated and you can access first, next or previous page like this:
documents = Pina::ProcessedDocument.all
documents.next_page
documents = Pina::ProcessedDocument.all
documents.previous_page
documents.first_page
Fetching specific processed document
Pina::ProcessedDocument.find(gid)
Deleting specific processed document
Pina::ProcessedDocument.delete(gid)
Purchase Invoices
All purchase invoices
Pina::PurchaseInvoice.all
Gets all purchase invocies from your database. Results are paginated and you can access first, next or previous page like this:
invoices = Pina::PurchaseInvoice.all
invoices.next_page
invoices = Pina::PurchaseInvoice.all
invoices.previous_page
invoices.first_page
Fetching specific purchase invoice
Pina::PurchaseInvoice.find(invoice_id)
Create new purchase invoice
invoice = Pina::Models::PurchaseInvoice.new
Pina::PurchaseInvoice.create(invoice)
Update existing purchase invoice
invoice = Pina::PurchaseInvoice.find(2016000001)
invoice.type = :penalty
Pina::PurchaseInvoice.update(2016000001, invoice)
Receivables
All receivables
Pina::Receivable.all
Gets all receivables from your database. Results are paginated and you can access first, next or previous page like this:
receivables = Pina::Receivable.all
receivables.next_page
invoices = Pina::Receivable.all
invoices.previous_page
invoices.first_page
Fetching specific receivable
Pina::Receivable.find(invoice_id)
Stat Processed Documents
All stat processed documents
Pina::StatProcessedDocument.all
Gets all stat processed documents from your database. Results are paginated and you can access first, next or previous page like this:
stats = Pina::StatProcessedDocument.all
stats.next_page
stats = Pina::StatProcessedDocument.all
stats.previous_page
stats.first_page
Fetching specific stat processed document
Pina::StatProcessedDocument.find(gid)
MyBankAccounts
All my bank accoutns
Pina::MyBankAccount.all
Gets all bank accounts from your database. Results are paginated and you can access first, next or previous page like this:
bank_accounts = Pina::MyBankAccount.all
bank_accounts.next_page
bank_accounts = Pina::MyBankAccount.all
bank_accounts.previous_page
bank_accounts.first_page
Fetching specific bank account
Pina::MyBankAccount.find('csob_czk')
This ID you can find under attribute bank_account_id
Create new MyBankAccount
params = {
bank_account: 'XXXXXXXXX/XXXX',
currency_id: 'CZK',
bank_account_id: 'XXXX'
}
bank_account = Pina::Models::MyBankAccount.new(params)
Pina::MyBankAccount.create(bank_account)
Update existing bank account
bank_account = Pina::MyBankAccount.find('existing')
bank_account.download_type = 'none'
Pina::MyBankAccount.update('existing', bank_account)
UploadedDocuments
All Uploaded documents
Pina::UploadedDocument.all
Gets all uploaded documents from your database. Results are paginated and you can access first, next or previous page like this:
uploaded_documents = Pina::UploadedDocument.all
uploaded_documents.next_page
uploaded_documents = Pina::UploadedDocument.all
uploaded_documents.previous_page
uploaded_documents.first_page
Fetching specific uploaded document (by ID)
Pina::UploadedDocument.find(1)
Update existing uploaded document
uploaded_document = Pina::UploadedDocument.find(1)
uploaded_document.state = 'processed'
Pina::UploadedDocument.update(1, uploaded_document)
UploadedDocumentPairing
Pair uploaded document with a book-keeping document
Pina::UploadedDocumentPairing.create(uploaded_document_id: 1,
document_pairable_type: 'purchase_invoice',
document_pairable_id: 201700001)
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Testing
Create .env file with following variables in it:
EMAIL
TENANT
API_TOKEN
and fill them with appropriate values.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pina.
License
The gem is available as open source under the terms of the MIT License.