alegra 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alegra/client.rb +11 -1
- data/lib/alegra/contacts.rb +43 -0
- data/lib/alegra/invoices.rb +33 -0
- data/lib/alegra/request.rb +27 -0
- data/lib/alegra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8449e5cbf7915fbc40fd7774552e0fae7a87ef6c
|
4
|
+
data.tar.gz: 3310cdab9187dbee1cd746c5cfced9bb18a13d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c701feb6d7ce8938cab5102505033a169d4fca79c6e765b0d123aabef0aeb2c7f67e21f4ce1a26518a13bab9006ab6e6c6d8c7e8f808172e419105a09217e9
|
7
|
+
data.tar.gz: e5a41d8a8f9f0500c75677288daae2047dcdcb779f17d24767f02fad102d7b4454f4d8bc0ced8e049ecf441023193845fea52642758dfad03a06b765eb448aa1
|
data/lib/alegra/client.rb
CHANGED
@@ -19,6 +19,16 @@ module Alegra
|
|
19
19
|
request.post(url, params)
|
20
20
|
end
|
21
21
|
|
22
|
+
def put(url, params={})
|
23
|
+
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
24
|
+
request.put(url, params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(url, params={})
|
28
|
+
request = Alegra::Request.new(@setup.host, @setup.path, @setup.token)
|
29
|
+
request.delete(url, params)
|
30
|
+
end
|
31
|
+
|
22
32
|
def invoices
|
23
33
|
Alegra::Invoices.new(self)
|
24
34
|
end
|
@@ -27,4 +37,4 @@ module Alegra
|
|
27
37
|
Alegra::Contacts.new(self)
|
28
38
|
end
|
29
39
|
end
|
30
|
-
end
|
40
|
+
end
|
data/lib/alegra/contacts.rb
CHANGED
@@ -20,10 +20,53 @@ module Alegra
|
|
20
20
|
|
21
21
|
# @param params [ Hash ]
|
22
22
|
# - name [ String ]
|
23
|
+
# - identification [ String ]
|
24
|
+
# - email [ String ]
|
25
|
+
# - phone_primary [ String ]
|
26
|
+
# - phone_secondary [ String ]
|
27
|
+
# - fax [ String ]
|
28
|
+
# - mobile [ String ]
|
29
|
+
# - observations [ String ]
|
30
|
+
# - ignore_repeated [ Boolean ]
|
31
|
+
# - price_list [ Hash ]
|
32
|
+
# - seller [ Hash ]
|
33
|
+
# - term [ Hash ]
|
34
|
+
# - type [ Array ]
|
35
|
+
# - address [ Hash ]
|
36
|
+
# - internal_contacts [ Array ]
|
23
37
|
# @return [ Hash ]
|
24
38
|
def create(params)
|
25
39
|
_params = params.deep_camel_case_lower_keys
|
26
40
|
client.post('contacts', _params)
|
27
41
|
end
|
42
|
+
|
43
|
+
# @param id [ Integer ]
|
44
|
+
# @param params [ Hash ]
|
45
|
+
# - name [ String ]
|
46
|
+
# - identification [ String ]
|
47
|
+
# - email [ String ]
|
48
|
+
# - phone_primary [ String ]
|
49
|
+
# - phone_secondary [ String ]
|
50
|
+
# - fax [ String ]
|
51
|
+
# - mobile [ String ]
|
52
|
+
# - observations [ String ]
|
53
|
+
# - ignore_repeated [ Boolean ]
|
54
|
+
# - price_list [ Hash ]
|
55
|
+
# - seller [ Hash ]
|
56
|
+
# - term [ Hash ]
|
57
|
+
# - type [ Array ]
|
58
|
+
# - address [ Hash ]
|
59
|
+
# - internal_contacts [ Array ]
|
60
|
+
# @return [ Hash ]
|
61
|
+
def update(id, params)
|
62
|
+
_params = params.deep_camel_case_lower_keys
|
63
|
+
client.put("contacts/#{ id }", _params)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param id [ Integer ]
|
67
|
+
# @return [ Hash ]
|
68
|
+
def delete(id)
|
69
|
+
client.delete("contacts/#{ id }")
|
70
|
+
end
|
28
71
|
end
|
29
72
|
end
|
data/lib/alegra/invoices.rb
CHANGED
@@ -39,6 +39,39 @@ module Alegra
|
|
39
39
|
_params = params.deep_camel_case_lower_keys
|
40
40
|
client.post('invoices', _params)
|
41
41
|
end
|
42
|
+
|
43
|
+
# Creates a invoice
|
44
|
+
# @param params [ Hash ]
|
45
|
+
# - date [ String ]
|
46
|
+
# - due_date [ String ]
|
47
|
+
# - price_list [ Array ]
|
48
|
+
# - currency [ Array ]
|
49
|
+
# - payments [ Array ]
|
50
|
+
# - client [ Integer ] or [ Hash ]
|
51
|
+
# - items [ Array ]
|
52
|
+
# - observations [ Array ]
|
53
|
+
# - anotations [ Array ]
|
54
|
+
# - terms_conditions [ Array ]
|
55
|
+
# - status [ String ]
|
56
|
+
# - number_template [ String ]
|
57
|
+
# - retenctions [ Array ]
|
58
|
+
# - seller [ String ]
|
59
|
+
# @return [ Hash ]
|
60
|
+
def update(id, params)
|
61
|
+
_params = params.deep_camel_case_lower_keys
|
62
|
+
client.put("invoices/#{ id }", _params)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @param id [ Integer ]
|
66
|
+
# @param params [ Hash ]
|
67
|
+
# - emails [ Array ]
|
68
|
+
# - send_copy_to_user [ Boolean ]
|
69
|
+
# - invoiceType [ String ]
|
70
|
+
# @return [ Hash ]
|
71
|
+
def send_by_email(id, params)
|
72
|
+
_params = params.deep_camel_case_lower_keys
|
73
|
+
client.post("invoices/#{ id }/email", _params)
|
74
|
+
end
|
42
75
|
end
|
43
76
|
end
|
44
77
|
|
data/lib/alegra/request.rb
CHANGED
@@ -33,6 +33,33 @@ module Alegra
|
|
33
33
|
return JSON.parse(response.body)
|
34
34
|
end
|
35
35
|
|
36
|
+
def put(url, params={})
|
37
|
+
params = JSON.generate(params)
|
38
|
+
response = @session.put do |req|
|
39
|
+
req.url "#{ @path }#{ url }"
|
40
|
+
req.headers['Content-Type'] = 'application/json'
|
41
|
+
req.headers['Accept'] = 'application/json'
|
42
|
+
req.headers['Authorization'] = "Basic #{ @token }"
|
43
|
+
req.body = params
|
44
|
+
end
|
45
|
+
cast_error(response) unless (response.status == 200 || response.status == 201)
|
46
|
+
return JSON.parse(response.body)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def delete(url, params={})
|
51
|
+
params = JSON.generate(params)
|
52
|
+
response = @session.delete do |req|
|
53
|
+
req.url "#{ @path }#{ url }"
|
54
|
+
req.headers['Content-Type'] = 'application/json'
|
55
|
+
req.headers['Accept'] = 'application/json'
|
56
|
+
req.headers['Authorization'] = "Basic #{ @token }"
|
57
|
+
req.body = params
|
58
|
+
end
|
59
|
+
cast_error(response) unless (response.status == 200 || response.status == 201)
|
60
|
+
return JSON.parse(response.body)
|
61
|
+
end
|
62
|
+
|
36
63
|
def cast_error(response)
|
37
64
|
message = response.body.empty? ? response.body : JSON.parse(response.body)['message']
|
38
65
|
error_map = {
|
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.1.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: 2016-10-
|
11
|
+
date: 2016-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|