alegra 0.1.2.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile +3 -1
- data/README.md +165 -17
- data/alegra.gemspec +8 -9
- data/bin/console +16 -2
- data/lib/alegra/bank_accounts.rb +21 -0
- data/lib/alegra/categories.rb +11 -0
- data/lib/alegra/client.rb +43 -12
- data/lib/alegra/company.rb +12 -0
- data/lib/alegra/contacts.rb +21 -16
- data/lib/alegra/invoices.rb +24 -17
- data/lib/alegra/items.rb +3 -9
- data/lib/alegra/journals.rb +25 -0
- data/lib/alegra/payments.rb +70 -0
- data/lib/alegra/record.rb +9 -0
- data/lib/alegra/request.rb +50 -30
- data/lib/alegra/response.rb +1 -1
- data/lib/alegra/setup.rb +1 -1
- data/lib/alegra/users.rb +15 -0
- data/lib/alegra/version.rb +1 -1
- metadata +37 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3fa2da362476c72c6570864ecd2c5515da43397835d85ab2d32cb66e7f5a2191
|
4
|
+
data.tar.gz: 8b3d7fe929ecb25a180559a7d3ff73e3124b4c691342c2777b2c2f95f9b7231e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30132d66010ea6b67b215c0625d154bf981d5676411a8876508d7ee441f22ab2babcf2a00dab3ae083b024ac0fb14d34bc76c1560aeb4a1a9bab1a7ad6826569
|
7
|
+
data.tar.gz: '068d64aa6e41c66886d53e1d779ccade60a008236af7db598249457ea768694dbf03001d8802c39e25e7eb1b2e4e77ffcadf6cb840d92521b1538d9ae863bd69'
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Alegra
|
2
|
+
[![Build Status](https://travis-ci.org/degzcs/alegra.svg?branch=master)](https://travis-ci.org/degzcs/alegra)
|
2
3
|
|
3
|
-
A ruby client for connecting to [Alegra](http://www.alegra.com)'s API.
|
4
|
+
A ruby client for connecting to [Alegra](http://www.alegra.com)'s API.
|
4
5
|
|
5
|
-
Please check the official API documentation [here](http://developer.alegra.com/)
|
6
|
+
Please check the official API documentation [here](http://developer.alegra.com/)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -14,7 +15,7 @@ gem 'alegra'
|
|
14
15
|
|
15
16
|
And then execute:
|
16
17
|
|
17
|
-
$ bundle install
|
18
|
+
$ bundle install
|
18
19
|
|
19
20
|
Or install it yourself as:
|
20
21
|
|
@@ -51,7 +52,7 @@ client.contacts.create(params)
|
|
51
52
|
```
|
52
53
|
|
53
54
|
You can update this contact too:
|
54
|
-
```ruby
|
55
|
+
```ruby
|
55
56
|
params = {
|
56
57
|
name: 'Sinc Hompas'
|
57
58
|
}
|
@@ -59,7 +60,7 @@ client.contacts.update(1, params)
|
|
59
60
|
```
|
60
61
|
|
61
62
|
Or delete it, as follows:
|
62
|
-
```ruby
|
63
|
+
```ruby
|
63
64
|
client.contacts.delete(1)
|
64
65
|
```
|
65
66
|
|
@@ -87,7 +88,7 @@ client.items.create(params)
|
|
87
88
|
```
|
88
89
|
|
89
90
|
You can update this item too:
|
90
|
-
```ruby
|
91
|
+
```ruby
|
91
92
|
params = {
|
92
93
|
name: 'A better name!',
|
93
94
|
}
|
@@ -95,14 +96,14 @@ client.items.update(1, params)
|
|
95
96
|
```
|
96
97
|
|
97
98
|
Or delete it, as follows:
|
98
|
-
```ruby
|
99
|
+
```ruby
|
99
100
|
client.items.delete(1)
|
100
101
|
```
|
101
102
|
|
102
|
-
### Invoices
|
103
|
+
### Invoices
|
103
104
|
|
104
105
|
You can get all invoices:
|
105
|
-
```ruby
|
106
|
+
```ruby
|
106
107
|
client.invoices.list()
|
107
108
|
```
|
108
109
|
|
@@ -147,7 +148,7 @@ client.invoices.create(params)
|
|
147
148
|
```
|
148
149
|
|
149
150
|
Update that invoice:
|
150
|
-
```ruby
|
151
|
+
```ruby
|
151
152
|
params = { observations: 'This invoice was updated!'}
|
152
153
|
client.invoices.update(1, params)
|
153
154
|
```
|
@@ -157,11 +158,151 @@ Send that invoice by email:
|
|
157
158
|
params = { emails: ['your.email@alegra.com', 'another.eail@algra.com'], send_copy_to_user: true, invoice_type: 'copy'}
|
158
159
|
client.invoices.send_by_email(1, params)
|
159
160
|
```
|
161
|
+
|
162
|
+
### Payments
|
163
|
+
|
164
|
+
You can get all payments:
|
165
|
+
```ruby
|
166
|
+
client.payments.list()
|
167
|
+
```
|
168
|
+
|
169
|
+
Or get a specific payment by id:
|
170
|
+
```ruby
|
171
|
+
client.payments.find(1) # the parameter is the payment id
|
172
|
+
```
|
173
|
+
|
174
|
+
Also you are able to create a new payments, as follows:
|
175
|
+
```ruby
|
176
|
+
params = {
|
177
|
+
date: "2015-12-13",
|
178
|
+
invoices: [
|
179
|
+
{
|
180
|
+
id: 6,
|
181
|
+
amount: 150
|
182
|
+
},
|
183
|
+
{
|
184
|
+
id: 200,
|
185
|
+
amount: 500
|
186
|
+
}
|
187
|
+
],
|
188
|
+
bank_account: 1
|
189
|
+
}
|
190
|
+
|
191
|
+
client.payments.create(params)
|
192
|
+
```
|
193
|
+
### Company
|
194
|
+
|
195
|
+
You can get the company:
|
196
|
+
```ruby
|
197
|
+
client.company.find
|
198
|
+
```
|
199
|
+
|
200
|
+
Also you can update it, as follows:
|
201
|
+
```ruby
|
202
|
+
params = { website: 'nominapp.com' }
|
203
|
+
|
204
|
+
client.company.update(params)
|
205
|
+
```
|
206
|
+
|
207
|
+
### Users
|
208
|
+
|
209
|
+
You can get the users:
|
210
|
+
```ruby
|
211
|
+
client.users.list
|
212
|
+
```
|
213
|
+
|
214
|
+
Also you can retrive a specific user by doing:
|
215
|
+
```ruby
|
216
|
+
client.users.find(1)
|
217
|
+
```
|
218
|
+
|
219
|
+
Lastly you can retrive the current user, as follows:
|
220
|
+
```ruby
|
221
|
+
client.users.find_current
|
222
|
+
```
|
223
|
+
|
224
|
+
### Categories
|
225
|
+
|
226
|
+
You can get all the categories on the client account like this:
|
227
|
+
```ruby
|
228
|
+
client.categories.list #this will retrieve the tree format by default
|
229
|
+
```
|
230
|
+
Or if you prefer the plain format from the Alegra API just pass it as a paramater:
|
231
|
+
```ruby
|
232
|
+
client.categories.list(format: 'plain')
|
233
|
+
```
|
234
|
+
You can also retrive a specific category, as follows:
|
235
|
+
```ruby
|
236
|
+
client.categories.find('5047')
|
237
|
+
```
|
238
|
+
|
239
|
+
### BankAccounts
|
240
|
+
|
241
|
+
To retrive all bank accounts:
|
242
|
+
```ruby
|
243
|
+
client.bank_accounts.list
|
244
|
+
```
|
245
|
+
Or get a specific bank_account by id:
|
246
|
+
```ruby
|
247
|
+
client.bank_accounts.find(2)
|
248
|
+
```
|
249
|
+
Also you are able to create a new bank accounts, as follows:
|
250
|
+
```ruby
|
251
|
+
params = { name: 'test',
|
252
|
+
type: 'bank',
|
253
|
+
initial_balance: '100000',
|
254
|
+
initial_balance_date: '2020-02-25' }
|
255
|
+
|
256
|
+
client.bank_accounts.create(params)
|
257
|
+
```
|
258
|
+
And to create a bank transfer between accounts:
|
259
|
+
```ruby
|
260
|
+
params = { id_destination: 4, # 4 is the destination bank_account_id
|
261
|
+
amount: 100000,
|
262
|
+
date: '2020-02-25' }
|
263
|
+
client.bank_accounts.transfer(7, params) # 7 is the origin bank_account_id
|
264
|
+
```
|
265
|
+
|
266
|
+
### Journals
|
267
|
+
|
268
|
+
To retrive all existing journals:
|
269
|
+
```ruby
|
270
|
+
client.journals.list
|
271
|
+
```
|
272
|
+
Or get a specif journal by `:id`:
|
273
|
+
```ruby
|
274
|
+
client.journals.find(191)
|
275
|
+
```
|
276
|
+
You can create journals too, as follows:
|
277
|
+
```ruby
|
278
|
+
params = { date: Date.today.strftime("%Y-%m-%d"),
|
279
|
+
client: '416',
|
280
|
+
entries: [{ id: '5009', debit: 3_000_000 },
|
281
|
+
{ id: '5048', credit: 4_250_660 },
|
282
|
+
{ id: '5008', debit: 755_000 },
|
283
|
+
{ id: '5010', debit: 495_660 }] }
|
284
|
+
|
285
|
+
client.journals.create(params)
|
286
|
+
```
|
287
|
+
Or update them like this:
|
288
|
+
```ruby
|
289
|
+
params = { client: '416'
|
290
|
+
entries: [{ id: '5009', debit: 3_000_000 },
|
291
|
+
{ id: '5048', credit: 4_150_660 },
|
292
|
+
{ id: '5008', debit: 655_000 },
|
293
|
+
{ id: '5010', debit: 495_660 }] }
|
294
|
+
|
295
|
+
client.journals.update(193, params) # Where 193 is the :id of the journal in Alegra
|
296
|
+
```
|
297
|
+
Lastly you can delete journals, by doing the following:
|
298
|
+
```ruby
|
299
|
+
client.journals.delete(193, params) # Where 193 is the :id of the journal in Alegra
|
300
|
+
```
|
160
301
|
## Development
|
161
302
|
|
162
|
-
This gem is under construction and I'm writing it
|
303
|
+
This gem is under construction and I'm writing it with the goal that it will easy to use. However, if you have any recommendation is well received.
|
163
304
|
|
164
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
305
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
165
306
|
|
166
307
|
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](https://rubygems.org).
|
167
308
|
|
@@ -169,11 +310,18 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
169
310
|
|
170
311
|
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](http://contributor-covenant.org) code of conduct.
|
171
312
|
|
172
|
-
##
|
313
|
+
## TODO
|
314
|
+
The next endpoints are pending:
|
173
315
|
|
174
|
-
|
175
|
-
|
176
|
-
|
316
|
+
- Estimates
|
317
|
+
- Number templates
|
318
|
+
- Retentions
|
319
|
+
- Sellers
|
320
|
+
- payments
|
321
|
+
- cancel payment(void)
|
322
|
+
- open payment convert https://developer.alegra.com/docs/convertir-pago-a-abierto
|
323
|
+
- Add attachment https://developer.alegra.com/docs/adjuntar-archivos-a-pagos
|
177
324
|
|
178
|
-
|
325
|
+
## License
|
179
326
|
|
327
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/alegra.gemspec
CHANGED
@@ -21,13 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
|
31
|
-
spec.
|
32
|
-
spec.add_dependency "json", "~> 1.7"
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
|
+
spec.add_dependency 'faraday', '~> 0.17.0'
|
26
|
+
spec.add_development_dependency 'jazz_fingers', '~> 5.0'
|
27
|
+
spec.add_dependency 'json', '~> 2.2'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
30
|
+
spec.add_development_dependency 'vcr', '~> 5.0'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 3.7'
|
33
32
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'alegra'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,19 @@ require "alegra"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
+
def reload!(print = true)
|
14
|
+
puts 'Reloading ...' if print
|
15
|
+
# Main project directory.
|
16
|
+
root_dir = File.expand_path('..', __dir__)
|
17
|
+
# Directories within the project that should be reloaded.
|
18
|
+
reload_dirs = %w{lib}
|
19
|
+
# Loop through and reload every file in all relevant project directories.
|
20
|
+
reload_dirs.each do |dir|
|
21
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
22
|
+
end
|
23
|
+
# Return true when complete.
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
13
27
|
require "irb"
|
14
28
|
IRB.start
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Alegra
|
2
|
+
class BankAccounts < Alegra::Record
|
3
|
+
def list(options = { format: :formated })
|
4
|
+
client.get('bank-accounts', {}, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id, options = { format: :formated })
|
8
|
+
client.get("bank-accounts/#{id}", {}, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(params, options = { format: :formated })
|
12
|
+
params = params.deep_camel_case_lower_keys
|
13
|
+
client.post('bank-accounts', params, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def transfer(id, params, options = { format: :formated })
|
17
|
+
params = params.deep_camel_case_lower_keys
|
18
|
+
client.post("bank-accounts/#{id}/transfer", params, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Alegra
|
2
|
+
class Categories < Alegra::Record
|
3
|
+
def list(params = {}, options = { format: :formated })
|
4
|
+
client.get('categories', params, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id, options = { format: :formated })
|
8
|
+
client.get("categories/#{id}", {}, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/alegra/client.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'alegra/setup'
|
2
2
|
require 'alegra/request'
|
3
|
+
require 'alegra/record'
|
3
4
|
require 'alegra/invoices'
|
4
5
|
require 'alegra/contacts'
|
5
6
|
require 'alegra/items'
|
7
|
+
require 'alegra/payments'
|
8
|
+
require 'alegra/company'
|
9
|
+
require 'alegra/users'
|
10
|
+
require 'alegra/categories'
|
11
|
+
require 'alegra/bank_accounts'
|
12
|
+
require 'alegra/journals'
|
6
13
|
|
7
14
|
module Alegra
|
8
15
|
class Client
|
@@ -10,36 +17,60 @@ module Alegra
|
|
10
17
|
@setup = Alegra::Setup.new(username, apikey, debug)
|
11
18
|
end
|
12
19
|
|
13
|
-
def get(url, params={})
|
20
|
+
def get(url, params = {}, options = { format: :formated })
|
14
21
|
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
15
|
-
request.get(url, params)
|
22
|
+
request.get(url, params, options)
|
16
23
|
end
|
17
24
|
|
18
|
-
def post(url, params={})
|
25
|
+
def post(url, params = {}, options = { format: :formated })
|
19
26
|
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
20
|
-
request.post(url, params)
|
27
|
+
request.post(url, params, options)
|
21
28
|
end
|
22
29
|
|
23
|
-
def put(url, params={})
|
30
|
+
def put(url, params={}, options = { format: :formated })
|
24
31
|
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
25
|
-
request.put(url, params)
|
32
|
+
request.put(url, params, options)
|
26
33
|
end
|
27
34
|
|
28
|
-
def delete(url, params={})
|
35
|
+
def delete(url, params={}, options = { format: :formated })
|
29
36
|
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
30
|
-
request.delete(url, params)
|
31
|
-
end
|
32
|
-
|
33
|
-
def invoices
|
34
|
-
Alegra::Invoices.new(self)
|
37
|
+
request.delete(url, params, options)
|
35
38
|
end
|
36
39
|
|
37
40
|
def contacts
|
38
41
|
Alegra::Contacts.new(self)
|
39
42
|
end
|
40
43
|
|
44
|
+
def invoices
|
45
|
+
Alegra::Invoices.new(self)
|
46
|
+
end
|
47
|
+
|
41
48
|
def items
|
42
49
|
Alegra::Items.new(self)
|
43
50
|
end
|
51
|
+
|
52
|
+
def payments
|
53
|
+
Alegra::Payments.new(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
def company
|
57
|
+
Alegra::Company.new(self)
|
58
|
+
end
|
59
|
+
|
60
|
+
def users
|
61
|
+
Alegra::Users.new(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def categories
|
65
|
+
Alegra::Categories.new(self)
|
66
|
+
end
|
67
|
+
|
68
|
+
def bank_accounts
|
69
|
+
Alegra::BankAccounts.new(self)
|
70
|
+
end
|
71
|
+
|
72
|
+
def journals
|
73
|
+
Alegra::Journals.new(self)
|
74
|
+
end
|
44
75
|
end
|
45
76
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Alegra
|
2
|
+
class Company < Alegra::Record
|
3
|
+
def find(options = { format: :formated })
|
4
|
+
client.get('company', {}, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(params, options = { format: :formated })
|
8
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
9
|
+
client.put('company', sanitize_params, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/alegra/contacts.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
module Alegra
|
2
|
-
class Contacts
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(client)
|
6
|
-
@client = client
|
7
|
-
end
|
8
|
-
|
9
|
-
# @param id [ Interger ]
|
2
|
+
class Contacts < Alegra::Record
|
3
|
+
# @param id [ Integer ]
|
10
4
|
# @return [ Hash ]
|
11
5
|
def find(id)
|
12
6
|
client.get("contacts/#{ id }")
|
13
7
|
end
|
14
8
|
|
15
9
|
# Returs all contacts
|
10
|
+
# @param params [ Hash ]
|
11
|
+
# - start [ Integer ]
|
12
|
+
# - limit [ Integer ]
|
13
|
+
# - order_direction [ String ]
|
14
|
+
# - order_field [ string ]
|
15
|
+
# - query [ String ]
|
16
|
+
# - type [ Integer ]
|
17
|
+
# - metadata [ Boolean ]
|
18
|
+
# - name [ String ]
|
19
|
+
# - identification [ String ]
|
16
20
|
# @return [ Array ]
|
17
|
-
def list()
|
18
|
-
client.get('contacts')
|
21
|
+
def list(params = {})
|
22
|
+
client.get('contacts', params)
|
19
23
|
end
|
20
24
|
|
21
25
|
# @param params [ Hash ]
|
@@ -36,8 +40,8 @@ module Alegra
|
|
36
40
|
# - internal_contacts [ Array ]
|
37
41
|
# @return [ Hash ]
|
38
42
|
def create(params)
|
39
|
-
|
40
|
-
client.post('contacts',
|
43
|
+
params = params.deep_camel_case_lower_keys
|
44
|
+
client.post('contacts', params)
|
41
45
|
end
|
42
46
|
|
43
47
|
# @param id [ Integer ]
|
@@ -59,14 +63,15 @@ module Alegra
|
|
59
63
|
# - internal_contacts [ Array ]
|
60
64
|
# @return [ Hash ]
|
61
65
|
def update(id, params)
|
62
|
-
|
63
|
-
client.put("contacts/#{
|
66
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
67
|
+
client.put("contacts/#{id}", sanitize_params)
|
68
|
+
|
64
69
|
end
|
65
70
|
|
66
71
|
# @param id [ Integer ]
|
67
72
|
# @return [ Hash ]
|
68
73
|
def delete(id)
|
69
|
-
client.delete("contacts/#{
|
74
|
+
client.delete("contacts/#{id}")
|
70
75
|
end
|
71
76
|
end
|
72
|
-
end
|
77
|
+
end
|
data/lib/alegra/invoices.rb
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
module Alegra
|
2
|
-
class Invoices
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(client)
|
6
|
-
@client = client
|
7
|
-
end
|
8
|
-
|
9
|
-
# @param id [ Interger ]
|
2
|
+
class Invoices < Alegra::Record
|
3
|
+
# @param id [ Integer ]
|
10
4
|
# @return [ Hash ]
|
11
5
|
def find(id)
|
12
|
-
client.get("invoices/#{
|
6
|
+
client.get("invoices/#{id}")
|
13
7
|
end
|
14
8
|
|
15
9
|
# Returs all invoices
|
10
|
+
# @param params [ Hash ]
|
11
|
+
# - start [ Integer ]
|
12
|
+
# - limit [ Integer ]
|
13
|
+
# - order_direction [ String ]
|
14
|
+
# - order_field [ string ]
|
15
|
+
# - metadata [ Boolean ]
|
16
|
+
# - id [ Integer ]
|
17
|
+
# - date [ String ]
|
18
|
+
# - due_date [ String ]
|
19
|
+
# - status [ String ]
|
20
|
+
# - client_name [ String ]
|
21
|
+
# - client_identification [ String ]
|
22
|
+
# - number_template_full_number
|
16
23
|
# @return [ Array ]
|
17
|
-
def list()
|
18
|
-
client.get('invoices')
|
24
|
+
def list(params = {})
|
25
|
+
client.get('invoices', params)
|
19
26
|
end
|
20
27
|
|
21
28
|
# Creates a invoice
|
@@ -36,8 +43,8 @@ module Alegra
|
|
36
43
|
# - seller [ String ]
|
37
44
|
# @return [ Hash ]
|
38
45
|
def create(params)
|
39
|
-
|
40
|
-
client.post('invoices',
|
46
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
47
|
+
client.post('invoices', sanitize_params)
|
41
48
|
end
|
42
49
|
|
43
50
|
# Creates a invoice
|
@@ -58,8 +65,8 @@ module Alegra
|
|
58
65
|
# - seller [ String ]
|
59
66
|
# @return [ Hash ]
|
60
67
|
def update(id, params)
|
61
|
-
|
62
|
-
client.put("invoices/#{
|
68
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
69
|
+
client.put("invoices/#{id}", sanitize_params)
|
63
70
|
end
|
64
71
|
|
65
72
|
# @param id [ Integer ]
|
@@ -69,8 +76,8 @@ module Alegra
|
|
69
76
|
# - invoiceType [ String ]
|
70
77
|
# @return [ Hash ]
|
71
78
|
def send_by_email(id, params)
|
72
|
-
|
73
|
-
client.post("invoices/#{
|
79
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
80
|
+
client.post("invoices/#{id}/email", sanitize_params)
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
data/lib/alegra/items.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
module Alegra
|
2
|
-
class Items
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(client)
|
6
|
-
@client = client
|
7
|
-
end
|
8
|
-
|
9
|
-
# @param id [ Interger ]
|
2
|
+
class Items < Alegra::Record
|
3
|
+
# @param id [ Integer ]
|
10
4
|
# @return [ Hash ]
|
11
5
|
def find(id)
|
12
6
|
client.get("items/#{ id }")
|
@@ -53,4 +47,4 @@ module Alegra
|
|
53
47
|
client.delete("items/#{ id }")
|
54
48
|
end
|
55
49
|
end
|
56
|
-
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Alegra
|
2
|
+
class Journals < Alegra::Record
|
3
|
+
def find(id)
|
4
|
+
client.get("journals/#{id}")
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(params = {})
|
8
|
+
client.get('journals', params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(params)
|
12
|
+
params = params.deep_camel_case_lower_keys
|
13
|
+
client.post('journals', params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, params)
|
17
|
+
params = params.deep_camel_case_lower_keys
|
18
|
+
client.put("journals/#{id}", params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(id)
|
22
|
+
client.delete("journals/#{id}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Alegra
|
2
|
+
class Payments < Alegra::Record
|
3
|
+
# @param id [ Integer ]
|
4
|
+
# @return [ Hash ]
|
5
|
+
def find(id)
|
6
|
+
client.get("payments/#{id}")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returs all payments
|
10
|
+
# @param params [ Hash ]
|
11
|
+
# - start [ Integer ]
|
12
|
+
# - limit [ Integer ]
|
13
|
+
# - order_direction [ String ]
|
14
|
+
# - order_field [ string ]
|
15
|
+
# - type [ Integer ]
|
16
|
+
# - metadata [ Boolean ]
|
17
|
+
# - id [ Integer ]
|
18
|
+
# @return [ Array ]
|
19
|
+
def list(params = {})
|
20
|
+
client.get('payments', params)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a payment
|
24
|
+
# @param params [ Hash ]
|
25
|
+
# - date [ String ]
|
26
|
+
# - bank_account [ Integer ] or [ Hash ]
|
27
|
+
# - payment_method [ String ]
|
28
|
+
# - observations [ String ]
|
29
|
+
# - anotation [ String ]
|
30
|
+
# - type [ String ]
|
31
|
+
# - client [ Integer ] or [ Hash ]
|
32
|
+
# - invoices [ Array ]
|
33
|
+
# - bills [ Array ]
|
34
|
+
# - categories [ Array ]
|
35
|
+
# - retentions [ Array ]
|
36
|
+
# - currency [ Array ]
|
37
|
+
# @return [ Hash ]
|
38
|
+
def create(params)
|
39
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
40
|
+
client.post('payments', sanitize_params)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update a payment
|
44
|
+
# @param id [ Integer ]
|
45
|
+
# @param params [ Hash ]
|
46
|
+
# - date [ String ]
|
47
|
+
# - bank_account [ Integer ] or [ Hash ]
|
48
|
+
# - payment_method [ String ]
|
49
|
+
# - observations [ String ]
|
50
|
+
# - anotation [ String ]
|
51
|
+
# - type [ String ]
|
52
|
+
# - client [ Integer ] or [ Hash ]
|
53
|
+
# - invoices [ Array ]
|
54
|
+
# - bills [ Array ]
|
55
|
+
# - categories [ Array ]
|
56
|
+
# - retentions [ Array ]
|
57
|
+
# - currency [ Array ]
|
58
|
+
# @return [ Hash ]
|
59
|
+
def update(id, params)
|
60
|
+
sanitize_params = params.deep_camel_case_lower_keys
|
61
|
+
client.put("payments/#{id}", sanitize_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param id [ Integer ]
|
65
|
+
# @return [ Hash ]
|
66
|
+
def delete(id)
|
67
|
+
client.delete("payments/#{id}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/alegra/request.rb
CHANGED
@@ -9,32 +9,31 @@ module Alegra
|
|
9
9
|
@session = Faraday.new url: host
|
10
10
|
end
|
11
11
|
|
12
|
-
def get(url, params={})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
def get(url, params = {}, options = { format: :formated })
|
13
|
+
params = URI.encode_www_form(params)
|
14
|
+
|
15
|
+
response = @session.get do |req|
|
16
|
+
req.url "#{@path}#{url}?#{params}"
|
17
|
+
req.headers['Content-Type'] = 'application/json'
|
18
|
+
req.headers['Accept'] = 'application/json'
|
19
|
+
req.headers['Authorization'] = "Basic #{@token}"
|
20
|
+
end
|
21
|
+
response_of_request(response, options)
|
22
22
|
end
|
23
23
|
|
24
|
-
def post(url, params={})
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
return Alegra::Response.new(response.body).call
|
24
|
+
def post(url, params = {}, options = { format: :formated })
|
25
|
+
params = JSON.generate(params)
|
26
|
+
response = @session.post do |req|
|
27
|
+
req.url "#{ @path }#{ url }"
|
28
|
+
req.headers['Content-Type'] = 'application/json'
|
29
|
+
req.headers['Accept'] = 'application/json'
|
30
|
+
req.headers['Authorization'] = "Basic #{ @token }"
|
31
|
+
req.body = params
|
32
|
+
end
|
33
|
+
response_of_request(response, options)
|
35
34
|
end
|
36
35
|
|
37
|
-
def put(url, params={})
|
36
|
+
def put(url, params={}, options = { format: :formated })
|
38
37
|
params = JSON.generate(params)
|
39
38
|
response = @session.put do |req|
|
40
39
|
req.url "#{ @path }#{ url }"
|
@@ -43,12 +42,10 @@ module Alegra
|
|
43
42
|
req.headers['Authorization'] = "Basic #{ @token }"
|
44
43
|
req.body = params
|
45
44
|
end
|
46
|
-
|
47
|
-
return Alegra::Response.new(response.body).call
|
45
|
+
response_of_request(response, options)
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
|
-
def delete(url, params={})
|
48
|
+
def delete(url, params={}, options = { format: :formated })
|
52
49
|
params = JSON.generate(params)
|
53
50
|
response = @session.delete do |req|
|
54
51
|
req.url "#{ @path }#{ url }"
|
@@ -57,12 +54,28 @@ module Alegra
|
|
57
54
|
req.headers['Authorization'] = "Basic #{ @token }"
|
58
55
|
req.body = params
|
59
56
|
end
|
60
|
-
|
61
|
-
return Alegra::Response.new(response.body).call
|
57
|
+
response_of_request(response, options)
|
62
58
|
end
|
63
59
|
|
64
|
-
|
60
|
+
private
|
61
|
+
|
62
|
+
def response_of_request(response, options = { format: :formated })
|
63
|
+
cast_error(response, options) unless response.status == 200 || response.status == 201
|
64
|
+
|
65
|
+
raise_invalid_format options[:format]
|
66
|
+
|
67
|
+
return response if options[:format] == :raw
|
68
|
+
|
69
|
+
Alegra::Response.new(response.body).call
|
70
|
+
end
|
71
|
+
|
72
|
+
def cast_error(response, options = { format: :formated })
|
73
|
+
raise_invalid_format options[:format]
|
74
|
+
|
75
|
+
return response if options[:format] == :raw
|
76
|
+
|
65
77
|
message = response.body.empty? ? response.body : Alegra::Response.new(response.body).call['message']
|
78
|
+
|
66
79
|
error_map = {
|
67
80
|
500 => 'Sever error! Something were wrong in the server.',
|
68
81
|
400 => "Bad request!, #{ message }",
|
@@ -74,5 +87,12 @@ module Alegra
|
|
74
87
|
}
|
75
88
|
raise StandardError, "Status: #{ response.status }. Error: #{ error_map[response.status] }"
|
76
89
|
end
|
90
|
+
|
91
|
+
def raise_invalid_format(format)
|
92
|
+
return if %i[formated raw].include?(format)
|
93
|
+
return if format.nil?
|
94
|
+
|
95
|
+
raise StandardError, "#{format} is not a valid format, valid_formats[:formated, :raw]"
|
96
|
+
end
|
77
97
|
end
|
78
|
-
end
|
98
|
+
end
|
data/lib/alegra/response.rb
CHANGED
data/lib/alegra/setup.rb
CHANGED
data/lib/alegra/users.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Alegra
|
2
|
+
class Users < Alegra::Record
|
3
|
+
def list(options = { format: :formated })
|
4
|
+
client.get('users', {}, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id, options = { format: :formated })
|
8
|
+
client.get("users/#{id}", {}, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_current(options = { format: :formated })
|
12
|
+
client.get('users/self', {}, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/alegra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alegra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,112 +16,112 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: 0.17.0
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.17.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: jazz_fingers
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '5.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '2.2'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '13.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '13.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.9.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.9.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: vcr
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0
|
104
|
-
type: :
|
103
|
+
version: '5.0'
|
104
|
+
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0
|
110
|
+
version: '5.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
118
|
-
type: :
|
117
|
+
version: '3.7'
|
118
|
+
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '3.7'
|
125
125
|
description: Gem to wrap Alegra API. This is unofficial gem (until now)
|
126
126
|
email:
|
127
127
|
- diego.f.gomez.pardo@gmail.com
|
@@ -141,14 +141,21 @@ files:
|
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
143
|
- lib/alegra.rb
|
144
|
+
- lib/alegra/bank_accounts.rb
|
145
|
+
- lib/alegra/categories.rb
|
144
146
|
- lib/alegra/client.rb
|
147
|
+
- lib/alegra/company.rb
|
145
148
|
- lib/alegra/contacts.rb
|
146
149
|
- lib/alegra/formatters/underscore_formatter.rb
|
147
150
|
- lib/alegra/invoices.rb
|
148
151
|
- lib/alegra/items.rb
|
152
|
+
- lib/alegra/journals.rb
|
153
|
+
- lib/alegra/payments.rb
|
154
|
+
- lib/alegra/record.rb
|
149
155
|
- lib/alegra/request.rb
|
150
156
|
- lib/alegra/response.rb
|
151
157
|
- lib/alegra/setup.rb
|
158
|
+
- lib/alegra/users.rb
|
152
159
|
- lib/alegra/utilities/array.rb
|
153
160
|
- lib/alegra/utilities/hash.rb
|
154
161
|
- lib/alegra/utilities/string.rb
|
@@ -173,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
180
|
version: '0'
|
174
181
|
requirements: []
|
175
182
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.7.3
|
177
184
|
signing_key:
|
178
185
|
specification_version: 4
|
179
186
|
summary: Gem to wrap Alegra API.
|