Pennylane Ruby Library
The Pennylane Ruby library provides convenient access to the Pennylane API from applications written in the Ruby language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Pennylane API.
It only works with the buys and sales API.
It was inspired by the Stripe Ruby library.
Documentation
See the Pennylane API docs.
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add pennylane
If bundler is not being used to manage dependencies, install the gem by executing:
gem 'pennylane'
For Rails app :
Pennylane.api_key = Rails.application.credentials.dig(:pennylane, :api_key)
$ EDITOR=vim bin/rails credentials:edit
pennylane:
api_key: 'x0fd....'
Requirements
Ruby 2.3+.
Usage
The library needs to be configured with your account's token api which is available in your Pennylane Settings. Set Pennylane.api_key
to its value:
require 'pennylane'
Pennylane.api_key = 'x0fd....'
Pennylane::Customer.list
Pennylane::Customer.list(filter: [{field: 'name', operator: 'eq', value: 'Apple'}], page: 2)
Pennylane::Customer.retrieve('38a1f19a-256d-4692-a8fe-0a16403f59ff')
cus = Pennylane::Customer.retrieve('38a1f19a-256d-4692-a8fe-0a16403f59ff')
cus.update(name: 'Apple Inc')
Pennylane::Customer.create customer_type: 'company', name: 'Tesla', address: '4 rue du faubourg', postal_code: '75008', city: 'Paris', country_alpha2: 'FR'
CustomerInvoices (API Doc)
Pennylane::CustomerInvoice.create(
create_customer: true,
create_products: true,
invoice: {
date: '2021-01-01',
deadline: '2021-01-31',
customer: {
name: 'Tesla',
customer_type: 'company',
address: '4 rue du faubourg',
postal_code: '75001',
city: 'Paris',
country_alpha2: 'FR',
emails: ['stephane@tesla.com'] },
line_items: [
{
description: 'Consulting',
quantity: 1,
unit_price: 1000
}
]
}
)
Pennylane::CustomerInvoice.list
invoice = Pennylane::CustomerInvoice.retrieve('38a1f19a-256d-4692-a8fe-0a16403f59ff')
invoice.finalize
invoice.send_by_email
invoice.mark_as_paid
credit_note = Pennylane::CustomerInvoice.retrieve('some-credit-note-id')
Pennylane::CustomerInvoice.links(invoice.quote_group_uuid, credit_note.quote_group_uuid)
Pennylane::CustomerInvoice.import(file: Util.file(File.expand_path('../fixtures/files/invoice.pdf', __FILE__)),
create_customer: true,
invoice: { date: Date.today, deadline: Date.today >> 1,
customer: {
name: 'Tesla',
customer_type: 'company',
address: '4 rue du faubourg',
postal_code: '75001',
city: 'Paris',
country_alpha2: 'FR',
emails: ['stephane@tesla.com'] },
line_items: [
{
description: 'Consulting',
quantity: 1,
unit_price: 1000
}
]
}
)
Pennylane::Supplier.create(name: 'Apple Inc', address: '4 rue du faubourg', postal_code: '75008', city: 'Paris', country_alpha2: 'FR')
Pennylane::Supplier.retrieve('supplier_id')
Pennylane::Supplier.list
Pennylane::Product.create(label: 'Macbook Pro', unit: 'piece', price: 2_999, vat_rate: 'FR_200', currency: 'EUR')
Pennylane::Product.list
product = Pennylane::Product.retrieve('product_id')
product.update(label: 'Macbook Pro 2021')
Pennylane::Category.create(name: 'IT')
Pennylane::Category.retrieve('category_id')
Pennylane::Category.list
category = Pennylane::Category.retrieve('category_id')
category.update(name: 'IT Services')
CategoryGroups (API Doc)
Pennylane::CategoryGroup.list
Per-request api key
For apps that need to use multiple keys during the lifetime of a process. it's also possible to set a per-request key:
require "pennylane"
Pennylane::Customer.list(
{},
{
api_key: 'x1fa....'
}
)
Pennylane::Customer.retrieve(
'38a1f19a-256d-4692-a8fe-0a16403f59ff',
{
api_key: 'x1fa....'
}
)
Accessing resource properties
Both indexer and accessors can be used to retrieve values of resource properties.
customer = Pennylane::Customer.retrieve('customer_id')
puts customer['name']
puts customer.name
Test mode
Pennylane provide a test environment. You can use the library with your test token api by setting the Pennylane.api_key
to its value.
Development
bundle install
bundle exec rake test
Resources implemented so far :
CUSTOMER INVOICING
- Customer Invoices ✅
- Estimates 🚧
- Billing Subscriptions 🚧
REFERENTIALS
- Customers ✅
- Suppliers ✅
- Categories ✅
- CategoryGroups ✅
- Products ✅
- Plan Items 🚧
- Enums 🚧
SUPPLIER INVOICING
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sbounmy/pennylane. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Pennylane project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.