Alegra

A ruby client for connecting to Alegra's API.

Please check the official API documentation here

Installation

Add this line to your application's Gemfile:

gem 'alegra'

And then execute:

$ bundle install 

Or install it yourself as:

$ gem install alegra

Usage


require 'alegra'
client = Alegra::Client.new('youremail@test.com', 'your-private-token')

Contacts

You can list all your contacts:

client.contacts.list()

Get a specific contact by id:

client.contacts.find(1)

And you can create a contact as well:

params = {
  name: 'Alan Britho'
}
client.contacts.create(params)

You can update this contact too:

params = {
  name: 'Sinc Hompas'
}
client.contacts.update(1, params)

Or delete it, as follows:

client.contacts.delete(1)

Items

You can list all your items:

client.items.list()

Get a specific item by id:

client.items.find(1)

And you can create an item as well:

params = {
  name: 'a new item',
  price: 1500
}
client.items.create(params)

You can update this item too:

params = {
  name: 'A better name!',
}
client.items.update(1, params)

Or delete it, as follows:

client.items.delete(1)

Invoices

You can get all invoices:

client.invoices.list()

Or get a specific invoice by id:

client.invoices.find(1) # the parameter is the inovice id

Also you are able to create a new invoice, as follows:

params = {
          date: '2016-10-12',
          due_date: '2016-10-12',
          client: 1,
          items: [
                    {
                        id: 1,
                        price: 40,
                        quantity: 5
                    },
                    {
                        id: 2,
                        description: 'Brown leather wallet',
                        price: 80,
                        discount: 10,
                        tax: [
                                {
                                    id: 3,
                                }
                             ],
                        quantity: 1
                    }
                  ],
          account_number: 1234,
          payment_method: 'cash',
          stamp: {
            generate_stamp: true
          },
        }

client.invoices.create(params)

Update that invoice:

params = { observations: 'This invoice was updated!'}
client.invoices.update(1, params)

Send that invoice by email:

params = { emails: ['your.email@alegra.com', 'another.eail@algra.com'], send_copy_to_user: true, invoice_type: 'copy'}
client.invoices.send_by_email(1, params)

Development

This gem is under construction and I'm writing it as I would like to use it. However, if you have any recommendation is well received.

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/degzcs/alegra. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Contributors

  • Diego Gomez