Quaderno-ruby is a ruby wrapper for [Quaderno API] (https://github.com/quaderno/quaderno-api).
Current version is 2.0.1 See the changelog here
To install add the following to your Gemfile:
gem 'quaderno', require: 'quaderno-ruby'To configure just add this to your initializers
Quaderno::Base.configure do |config|
config.auth_token = 'my_authenticate_token'
config.url = 'https://my_subdomain.quadernoapp.com/api/'
config.api_version = API_VERSION # Optional, defaults to the API version set in your account
end1.7.1 Breaking changes: If you are using a configuration based on versions < '1.7.1', you will notice that the old configuration no longer works, so please update your configuration or specify the 1.7.0 version.
You can get your account subdomain by grabbing it from your account url or by calling the authorization method with your personal api token.
response = Quaderno::Base.authorization 'my_authenticate_token', environment #=> Quaderno::Base
response.identity # => {"id"=>737000, "name"=>"Walter White", "email"=>"cooking@br.bd", "href"=>"https://my_subdomain.quadernoapp.com/api/"}environment is an optional argument. By passing :sandbox, you will retrieve your credentials for the sandbox environment and not for production.
This will return a hash with the information about your api url, which includes the account subdomain.
You can ping the service in order to check if it is up with:
response = Quaderno::Base.ping #=> Quaderno::Base
response.status #=> BooleanThis will return status: true if the service is up or status: false if it is not.
response = Quaderno::Base.ping #=> Quaderno::Base
response.rate_limit_info #=> { :reset=> 4, :remaining=> 0 }This will return a hash with information about the seconds until the rate limit reset and your remaining requests per minute (check the API documentation for more information).
You can also check the rate limit for each request by checking the rate_limit_info method on the response:
invoices = Quaderno::Invoice.all #=> Quaderno::Collection
invoices.rate_limit_info #=> {:reset=> 5, :remaning=>6}
invoice = Quaderno::Invoice.find INVOICE_ID #=> Quaderno::Invoice
invoice.rate_limit_info #=> {:reset=>4, :remaining=>5}
result = invoice.deliver #=> Quaderno::Base
result.rate_limit_info #=> {:reset=>3, :remaining=>4}
begin
deleted_invoice = Quaderno::Invoice.delete(ANOTHER_INVOICE_ID) #=> Quaderno::Invoice
rescue Quaderno::Exceptions::InvalidSubdomainOrToken => e
# If the exception is triggered you can check the rate limit on the raised exception
e.rate_limit_info #=> {:reset=>2, :remaining=>3}
end
deleted_invoice.rate_limit_info #=> {:reset=>2, :remaining=>3}
# etc.Quaderno-ruby parses all the json responses in human readable data, so you can access each value just like this:
contact.id
invoice.items
estimates.payments
etc. Quaderno::Contact.all #=> Arraywill return an array with all your contacts. You can also pass query strings using the attribute :q in order to filter the results by contact name. For example:
Quaderno::Contact.all(q: 'John Doe') #=> Array Quaderno::Contact.find(id) #=> Quaderno::Contactwill return the contact with the id passed as parameter.
Quaderno::Contact.retrieve(PAYMENT_GATEWAY_CUSTOMER_ID, PAYMENT_GATEWAY) #=> Quaderno::Contactwill return the contact with the customer id passed as parameter.
*Note: Quaderno::Contact.retrieve_customer has been deprecated in favor of Quaderno::Contact.retrieve
Quaderno::Contact.create(params) #=> Quaderno::Contactwill create a contact using the information of the hash passed as parameter and return an instance of Quaderno::Contact with the created contact.
Quaderno::Contact.update(id, params) #=> Quaderno::Contactwill update the specified contact with the data of the hash passed as second parameter.
Quaderno::Contact.delete(id) #=> Quaderno::Contactwill delete the contact with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Contact with the deleted attribute set to true will be returned.
Quaderno::Item.all #=> Arraywill return an array with all your items.
Quaderno::Item.find(id) #=> Quaderno::Itemwill return the items with the id passed as parameter.
Quaderno::Item.create(params) #=> Quaderno::Itemwill create an item using the information of the hash passed as parameter and return an instance of Quaderno::Item with the created contact.
Quaderno::Item.update(id, params) #=> Quaderno::Itemwill update the specified item with the data of the hash passed as second parameter.
Quaderno::Item.delete(id) #=> Quaderno::Itemwill delete the item with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Item with the deleted attribute set to true will be returned.
Quaderno::Invoice.all #=> Arraywill return an array with all your invoices. You can also pass query strings using the attribute :q in order to filter the results by contact name, :state to filter by state or :date to filter by date
Quaderno::Invoice.find(id) #=> Quaderno::Invoicewill return the invoice with the id passed as parameter.
Quaderno::Invoice.retrieve(PAYMENT_GATEWAY_TRANSACTION_ID, PAYMENT_GATEWAY) #=> Quaderno::Invoicewill return the invoice with the transaction id passed as parameter.
Quaderno::Invoice.create(params) #=> Quaderno::Invoicewill create an invoice using the information of the hash passed as parameter.
Quaderno::Invoice.update(id, params) #=> Quaderno::Invoicewill update the specified invoice with the data of the hash passed as second parameter.
Quaderno::Invoice.delete(id) #=> Quaderno::Invoicewill delete the invoice with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Item with the deleted attribute set to true will be returned.
###Adding or removing a payment In order to add a payment you will need the Invoice instance you want to update.
invoice = Quaderno::Invoice.find(invoice_id)
invoice.add_payment(params) #=> Quaderno::PaymentWhere params is a hash with the payment information. The method will return an instance of Quaderno::Payment wich contains the information of the payment.
In order to remove a payment you will need the Invoice instance you want to update.
invoice = Quaderno::Invoice.find(invoice_id)
invoice.remove_payment(payment_id) #=> BooleanIn order to deliver the invoice to the default recipient you will need the invoice you want to send.
invoice = Quaderno::Invoice.find(invoice_id)
result = invoice.deliver #=> Quaderno::Base
result.success #=> Boolean Quaderno::Credit.all #=> Arraywill return an array with all your credit notes. You can also pass query strings using the attribute :q in order to filter the results by contact name, :state to filter by state or :date to filter by date
Quaderno::Credit.find(id) #=> Quaderno::Creditwill return the credit with the id passed as parameter.
Quaderno::Credit.retrieve(PAYMENT_GATEWAY_TRANSACTION_ID, PAYMENT_GATEWAY) #=> Quaderno::Creditwill return the credit note with the transaction id passed as parameter.
Quaderno::Credit.create(invoice_id: 42) #=> Quaderno::Creditwill create a credit from the invoice specified in the parameter.
Quaderno::Credit.update(id, params) #=> Quaderno::Creditwill update the specified credit with the data of the hash passed as second parameter.
Quaderno::Credit.delete(id) #=> Quaderno::Creditwill delete the credit with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Credit with the deleted attribute set to true will be returned.
In order to add a payment you will need the Credit instance you want to update.
credit = Quaderno::Credit.find(credit_id)
credit.add_payment(params) #=> Quaderno::PaymentWhere params is a hash with the payment information. The method will return an instance of Quaderno::Payment wich contains the information of the payment.
In order to remove a payment you will need the Credit instance you want to update.
credit = Quaderno::Credit.find(credit_id)
credit.remove_payment(payment_id) #=> Quaderno::PaymentIf the deletion was successful, an instance of Quaderno::Payment with the deleted attribute set to true will be returned.
In order to deliver the credit to the default recipient you will need the credit you want to send.
credit = Quaderno::Credit.find(credit_id)
result = credit.deliver #=> Quaderno::Base
result.success #=> Boolean Quaderno::Estimate.all #=> Arraywill return an array with all your estimates.
Quaderno::Estimate.find(id) #=> Quaderno::Estimatewill return the estimate with the id passed as parameter.
Quaderno::Estimate.create(params) #=> Quaderno::Estimatewill create an estimate using the information of the hash passed as parameter.
Quaderno::Estimate.update(id, params)will update the specified estimate with the data of the hash passed as second parameter.
Quaderno::Estimate.delete(id) #=> Quaderno::Estimatewill delete the estimate with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Contact with the deleted attribute set to true will be returned.
###Adding or removing a payment In order to add a payment you will need the estimate you want to update.
estimate = Quaderno::Estimate.find(estimate_id)
estimate.add_payment(params) #=> Quaderno::PaymentWhere params is a hash with the payment information. The method will return an instance of Quaderno::Payment wich contains the information of the payment.
In order to remove a payment you will need the estimate you want to update.
estimate = Quaderno::Estimate.find(estimate_id)
estimate.remove_payment(payment_id) #=> BooleanIn order to deliver the estimate to the default recipient you will need the estimate you want to send.
estimate = Quaderno::Estimate.find(estimate_id)
result = estimate.deliver #=> Quaderno::Base
result.success #=> Boolean Quaderno::Expense.all #=> Arraywill return an array with all your expenses. You can also pass query strings using the attribute :q in order to filter the results by contact name, :state to filter by state or :date to filter by date.
Quaderno::Expense.find(id) #=> Quaderno::Expensewill return the expense with the id passed as parameter.
Quaderno::Expense.create(params) #=> Quaderno::Expensewill create an expense using the information of the hash passed as parameter and return an instance of Quaderno::Expense with the created expense.
Quaderno::Expense.update(id, params) #=> Quaderno::Expensewill update the specified expense with the data of the hash passed as second parameter.
Quaderno::Expense.delete(id) #=> Quaderno::Expensewill delete the expense with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Expense with the deleted attribute set to true will be returned.
Quaderno::Recurring.all #=> Arraywill return an array with all your recurring notes. You can also pass query strings using the attribute :q in order to filter the results by contact name, :state to filter by state or :date to filter by date
Quaderno::Recurring.find(id) #=> Quaderno::Recurringwill return the recurring with the id passed as parameter.
Quaderno::Recurring.create(params) #=> Quaderno::Recurringwill create a recurring using the information of the hash passed as parameter.
Quaderno::Recurring.update(id, params) #=> Quaderno::Recurringwill update the specified recurring with the data of the hash passed as second parameter.
Quaderno::Recurring.delete(id) #=> Quaderno::Recurringwill delete the recurring with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Recurring with the deleted attribute set to true will be returned.
Quaderno::Webhook.all #=> Arraywill return an array with all the webhooks you have subscribed.
Quaderno::Webhook.find(id) #=> Quaderno::Webhookwill return the webhook with the id passed as parameter.
Quaderno::Webhook.create(params) #=> Quaderno::Webhookwill create a webhook using the information of the hash passed as parameter and return an instance of Quaderno::Webhook with the created webhook.
Quaderno::Webhook.update(id, params) #=> Quaderno::Webhookwill update the specified webhook with the data of the hash passed as second parameter.
Quaderno::Webhook.delete(id) #=> Quaderno::Webhookwill delete the webhook with the id passed as parameter. If the deletion was successful, an instance of Quaderno::Webhook with the deleted attribute set to true will be returned.
Quaderno::Tax.calculate(params) #=> Quaderno::Taxwill calculate the taxes applied for a customer based on the data pased as parameters.
country = 'IE'
tax_id = 'IE6388047V'
result = Quaderno::Tax.validate_tax_id(country, tax_id) #=> Quaderno::Tax
result.valid #=> Boolean or nilwill validate the tax ID or business number for the specified country.
Quaderno::Evidence.create(params) #=> Quaderno::Evidencewill create an evidence based on the data pased as parameters.
Quaderno::CheckoutSession.all #=> Arraywill return an array with all the checkout sessions in your account.
Quaderno::CheckoutSession.find(id) #=> Quaderno::CheckoutSessionwill return the checkout session with the id passed as parameter.
Quaderno::CheckoutSession.create(params) #=> Quaderno::CheckoutSessionwill create a checkout session using the information of the hash passed as parameter and return an instance of Quaderno::CheckoutSession with the created checout session.
Quaderno::CheckoutSession.update(id, params) #=> Quaderno::CheckoutSessionwill update the specified checkout session with the data of the hash passed as second parameter.
Quaderno::CheckoutSession.delete(id) #=> Quaderno::CheckoutSessionwill delete the checkout session with the id passed as parameter. If the deletion was successful, an instance of Quaderno::CheckoutSession with the deleted attribute set to true will be returned.
Quaderno::ReportRequest.all #=> Arraywill return an array with all your report requests.
Quaderno::ReportRequest.find(id) #=> Quaderno::ReportRequestwill return the report request with the id passed as parameter.
Quaderno::ReportRequest.create(params) #=> Quaderno::ReportRequestwill create a report request using the information of the hash passed as parameter and return an instance of Quaderno::ReportRequest with the created report request.
Quaderno-ruby exceptions raise depending on the type of error:
Quaderno::Exceptions::UnsupportedApiVersion # Raised when the API version set is not supported.
Quaderno::Exceptions::InvalidSubdomainOrToken # Raised when the credentials are wrong, missing or do not match the permission for some object.
Quaderno::Exceptions::InvalidID # Raised when the requested resource by ID does not exist in the account context.
Quaderno::Exceptions::ThrottleLimitExceeded # Raised when the throttle limit is exceeded.
Quaderno::Exceptions::RateLimitExceeded # Raised when the rate limit is exceeded.
Quaderno::Exceptions::HasAssociatedDocuments # Raised when trying to delete a contact with associated documents.
Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid # Raised if the format of the request is right but some validations failed. You can JSON parse the exception message to get which field triggered the exception. For example: '{"errors":{"vat_number":["is not a valid German vat number"]}}'All those exceptions inherit from Quaderno::Exceptions::BaseException.
Whenever you call the all method on one of the classes, the result will be a Quaderno::Collection. For example:
collection = Quaderno::Contact.all
collection.class #=> Quaderno::Collection
collection.has_more? #=> true
collection.next_page #=> another instance ofThe next_page method is an abstraction for the created_before parameter, which you may also use with the all method.
collection = Quaderno::Contact.all
Quaderno::Contact.all(created_before: collection.last.id)You can also use the limit parameter to determine how many results to retrieve. Its default is 25, and Quaderno will cap the limit at 100.
collection = Quaderno::Contact.all(limit: 50)
collection.length #=> 50If you are managing multiple accounts you may need a thread-safe way to configure the credentials. You can do it by passing the credentials on each request:
Quaderno::Invoice.all(
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)
Quaderno::Invoice.find(INVOICE_ID,
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)
Quaderno::Invoice.update(INVOICE_ID,
po_number: '12345',
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)
invoice = Quaderno::Invoice.find(INVOICE_ID,
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)
invoice.add_payment(params) # Credentials are already stored on the Quaderno::Invoice instance from the first request
invoice = Quaderno::Invoice.find(INVOICE_ID,
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)
invoice.remove_payment(PAYMENT_ID) # Credentials are already stored on the Quaderno::Invoice instance from the first request
Quaderno::Invoice.delete(INVOICE_ID,
api_url: 'https://my_subdomain.quadernoapp.com/api/',
auth_token: 'my_authenticate_token'
)Remember this is only a ruby wrapper for the original API. If you want more information about the API itself, head to the original API documentation.
(The MIT License)
Copyright © 2013-2015 Quaderno
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.