poseidon-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p392
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --markup-provider=redcarpet
2
+ --markup=markdown
3
+ --charset=utf-8
4
+
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Jenkins Build Status](http://www.apslabs.com.ar/jenkins/job/poseidon-api/badge/icon)](http://www.apslabs.com.ar/jenkins/job/poseidon-api/)
2
+ [![Travis Build Status](https://travis-ci.org/apslab/poseidon-api.png)](https://travis-ci.org/apslab/poseidon-api)
3
+
4
+
1
5
  # Poseidon::Api
2
6
 
3
7
  Cliente para interactuar con la API del sistema Poseidon.
@@ -18,15 +22,37 @@ O instalar directamente:
18
22
 
19
23
  ## Modo de uso
20
24
 
21
- api = Poseidon::API(url: 'http://poseidon-url.com', user: 'user@test.com', password: '12345')
22
- invoice = Poseidon::Invoice.new ...
23
- ...
24
- emitted = api.emit_invoice(invoice)
25
+
26
+ ### Factura para clientes
27
+
28
+ ```ruby
29
+ api = Poseidon::API(url: 'http://poseidon-url.com', user: 'user@test.com', password: '12345')
30
+ invoice = Poseidon::Invoice.new(date: Date.today, sale_point: 1, number: 189122)
31
+ invoice.client = Poseidon::Client.new(name: 'Los alamos', cuit: 20243234221, iva_condition_id: 1)
32
+ invoice.details << Poseidon::Detail.new(amount: 10, unit_price: 15.50, description: 'Carpetas oficio', iva_rate: 21.0)
33
+ invoice.details << Poseidon::Detail.new(amount: 4, unit_price: 35.0, description: 'Carpetas plastificada', iva_rate: 21.0)
34
+ emitted = api.emit_invoice(invoice)
35
+ ```
25
36
 
26
37
  Retorna un booleano que indica si pudo o no emitir la factura.
27
38
 
28
39
  En caso de no emitir la factura se pueden verificar los errores utilizando el método 'errors'
29
40
 
41
+ ### Factura de proveedores
42
+
43
+ ```ruby
44
+ api = Poseidon::API(url: 'http://poseidon-url.com', user: 'user@test.com', password: '12345')
45
+ invoice = Poseidon::Invoice.new(date: Date.today, sale_point: 1, number: 189122)
46
+ invoice.supplier = Poseidon::Supplier.new(name: 'Los alamos', cuit: 20243234221, iva_condition_id: 1)
47
+ invoice.details << Poseidon::Detail.new(amount: 10, unit_price: 15.50, description: 'Carpetas oficio', iva_rate: 21.0)
48
+ invoice.details << Poseidon::Detail.new(amount: 4, unit_price: 35.0, description: 'Carpetas plastificada', iva_rate: 21.0)
49
+ emitted = api.emit_invoice(invoice)
50
+ ```
51
+
52
+ ## Links
53
+
54
+ + RDoc: http://rubydoc.info/github/apslab/poseidon-api/master/frames
55
+ + Source: https://github.com/apslab/poseidon-api
30
56
 
31
57
  ## Contributing
32
58
 
data/lib/poseidon-api.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "poseidon-api/version"
2
3
  require 'json'
3
4
  require 'curb'
@@ -15,10 +16,27 @@ require 'curb'
15
16
  #
16
17
  # En caso de no emitir la factura se pueden verificar los errores utilizando el método 'errors'
17
18
  #
19
+ # ## Factura de proveedores
20
+ #
21
+ # En caso de querer registrar la factura de un proveedor se procede a cargar el método supplier de invoice.
22
+ #
23
+ # Ejemplo:
24
+ #
25
+ # api = ....
26
+ # invoice = Poseidon::Invoice.new ...
27
+ # invoice.supplier = Poseidon::Supplier.new(name: ....
28
+ # ...
29
+ # ...
30
+ # emitted = api.emit_invoice(invoice)
31
+ #
18
32
  module Poseidon
19
33
  class API
20
34
 
21
- attr_reader :token, :errors
35
+ attr_reader :token
36
+
37
+ # Retorna los errores si falló la invocación de alguno de los
38
+ # métodos.
39
+ attr_reader :errors
22
40
 
23
41
  # El constructor requiere los atributos:
24
42
  #
@@ -35,6 +53,11 @@ module Poseidon
35
53
  @version = properties[:version] || 'v1'
36
54
  end
37
55
 
56
+ # Obtiene un token para poder utilizar los servicios
57
+ #
58
+ # Retorna true o false
59
+ #
60
+ # Si ocurre un error se pueden obtener los detalles a través del método "errors"
38
61
  def login
39
62
  json = { :email => @user, :password => @password }.to_json
40
63
  curl = post(token_uri, json)
@@ -49,6 +72,10 @@ module Poseidon
49
72
  end
50
73
  end
51
74
 
75
+ # Emite una factura a través del sistema Poseidon
76
+ #
77
+ # Retorna true o false
78
+ #
52
79
  def emit_invoice(invoice)
53
80
  login if @token.nil?
54
81
  curl = post(facturas_uri, invoice.to_json)
@@ -64,10 +91,6 @@ module Poseidon
64
91
  end
65
92
  end
66
93
 
67
- def hello
68
- 'world'
69
- end
70
-
71
94
  private
72
95
 
73
96
  def post(uri, json)
@@ -93,36 +116,69 @@ module Poseidon
93
116
  end
94
117
 
95
118
 
119
+ # Información de la factura a emitir
96
120
  class Invoice
97
- attr_accessor :date, :sale_point, :number, :client, :details
121
+ attr_accessor :date, :sale_point, :number, :client, :details, :supplier
98
122
 
123
+ # Atributos para construir:
124
+ #
125
+ # + date
126
+ # + sale_point
127
+ # + number
128
+ # + client: a Poseidon::Client instance
129
+ # + supplier: a Poseidon::Supplier instance
130
+ #
99
131
  def initialize(attrs)
100
132
  @date = attrs[:date] || Date.now
101
133
  @sale_point = attrs[:sale_point]
102
134
  @number = attrs[:number]
103
135
  @client = attrs[:client]
136
+ @supplier = attrs[:supplier]
104
137
  @details = []
138
+ # TODO: debe ocurrir una excepción si no se indica client o supplier
105
139
  end
106
140
 
107
141
  def to_hash
108
- { factura: {
142
+ hash = {
143
+ factura: {
109
144
  fecha: @date,
110
145
  sale_point: @sale_point,
111
146
  numero: @number,
112
- cliente: @client.to_hash,
113
147
  detalles: @details.map { |detail| detail.to_hash }
114
148
  }
115
149
  }
150
+ add_supplier_or_client(hash)
116
151
  end
117
152
 
118
153
  def to_json
119
154
  to_hash.to_json
120
155
  end
156
+
157
+ private
158
+
159
+ def add_supplier_or_client(hash)
160
+ if @client
161
+ hash[:factura][:cliente] = @client.to_hash
162
+ end
163
+
164
+ if @supplier
165
+ hash[:factura][:proveedor] = @supplier.to_hash
166
+ end
167
+
168
+ hash
169
+ end
170
+
121
171
  end
122
172
 
123
173
  class Client
124
174
  attr_accessor :name, :cuit, :iva_condition_id
125
175
 
176
+ # Atributos necesario para la construcción:
177
+ #
178
+ # + name
179
+ # + cuit
180
+ # + iva_condition_id
181
+ #
126
182
  def initialize(attrs)
127
183
  @name = attrs[:name]
128
184
  @cuit = attrs[:cuit]
@@ -134,9 +190,36 @@ module Poseidon
134
190
  end
135
191
  end
136
192
 
193
+ class Supplier
194
+ attr_accessor :name, :cuit, :iva_condition_id
195
+
196
+ # Atributos necesario para la construcción:
197
+ #
198
+ # + name
199
+ # + cuit
200
+ # + iva_condition_id
201
+ #
202
+ def initialize(attrs)
203
+ @name = attrs[:name]
204
+ @cuit = attrs[:cuit]
205
+ @iva_condition_id = attrs[:iva_condition_id]
206
+ end
207
+
208
+ def to_hash
209
+ { razonsocial: @name, cuit: @cuit.to_s, condicioniva_id: @iva_condition_id }
210
+ end
211
+ end
212
+
137
213
  class Detail
138
214
  attr_accessor :amount, :unit_price, :description, :iva_rate
139
215
 
216
+ # Attributos necesarios para la construcción:
217
+ #
218
+ # + amount
219
+ # + unit_price
220
+ # + description
221
+ # + iva_rate
222
+ #
140
223
  def initialize(attrs)
141
224
  @amount = attrs[:amount]
142
225
  @unit_price = attrs[:unit_price]
@@ -1,5 +1,5 @@
1
1
  module Poseidon
2
2
  module Api
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/poseidon-api.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["maxidr@gmail.com"]
11
11
  gem.description = %q{An API to interact with the Poseidon system}
12
12
  gem.summary = %q{API client for Poseidon system}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/apslab/poseidon-api"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -26,13 +26,13 @@ http_interactions:
26
26
  SUU9RWRnZQ==
27
27
  !binary "WC1SdW50aW1l":
28
28
  - !binary |-
29
- MC40MjU4NDI=
29
+ MC45Mjk0MjY=
30
30
  !binary "U2VydmVy":
31
31
  - !binary |-
32
- V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
32
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
33
33
  !binary "RGF0ZQ==":
34
34
  - !binary |-
35
- U2F0LCAwMiBNYXIgMjAxMyAxMzoxMjoxMSBHTVQ=
35
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTozNiBHTVQ=
36
36
  !binary "Q29udGVudC1MZW5ndGg=":
37
37
  - !binary |-
38
38
  NDM=
@@ -44,5 +44,5 @@ http_interactions:
44
44
  string: !binary |-
45
45
  eyJlcnJvciI6IkVtYWlsIG8gcGFzc3dvcmQgaW52XHUwMGUxbGlkb3MifQ==
46
46
  http_version:
47
- recorded_at: Sat, 02 Mar 2013 13:12:11 GMT
47
+ recorded_at: Tue, 30 Apr 2013 02:31:36 GMT
48
48
  recorded_with: VCR 2.4.0
@@ -20,7 +20,7 @@ http_interactions:
20
20
  YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
21
21
  !binary "RXRhZw==":
22
22
  - !binary |-
23
- IjJhZjAzZDgwMmZiM2U1YTFiZWZkMmNkNWE4ZDY1MjM1Ig==
23
+ IjU2NmNmNjdmYTI1MWIwOGUyMmJiZWU5YWM2YTIwOTBlIg==
24
24
  !binary "Q2FjaGUtQ29udHJvbA==":
25
25
  - !binary |-
26
26
  bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
@@ -29,13 +29,13 @@ http_interactions:
29
29
  SUU9RWRnZQ==
30
30
  !binary "WC1SdW50aW1l":
31
31
  - !binary |-
32
- MC40NDA2OTg=
32
+ MS40NDI3MTE=
33
33
  !binary "U2VydmVy":
34
34
  - !binary |-
35
- V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
35
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
36
36
  !binary "RGF0ZQ==":
37
37
  - !binary |-
38
- U2F0LCAwMiBNYXIgMjAxMyAxMzoxMjoxMSBHTVQ=
38
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTozNSBHTVQ=
39
39
  !binary "Q29udGVudC1MZW5ndGg=":
40
40
  - !binary |-
41
41
  MzI=
@@ -45,7 +45,7 @@ http_interactions:
45
45
  body:
46
46
  encoding: ASCII-8BIT
47
47
  string: !binary |-
48
- eyJ0b2tlbiI6InlOem81MUt1Zk12ZXRabmVvN2NEIn0=
48
+ eyJ0b2tlbiI6InJ6Z3dpc3NFMUpLWVVFRGtlNXNTIn0=
49
49
  http_version:
50
- recorded_at: Sat, 02 Mar 2013 13:12:11 GMT
50
+ recorded_at: Tue, 30 Apr 2013 02:31:35 GMT
51
51
  recorded_with: VCR 2.4.0
@@ -20,7 +20,7 @@ http_interactions:
20
20
  YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
21
21
  !binary "RXRhZw==":
22
22
  - !binary |-
23
- IjJhZjAzZDgwMmZiM2U1YTFiZWZkMmNkNWE4ZDY1MjM1Ig==
23
+ IjU2NmNmNjdmYTI1MWIwOGUyMmJiZWU5YWM2YTIwOTBlIg==
24
24
  !binary "Q2FjaGUtQ29udHJvbA==":
25
25
  - !binary |-
26
26
  bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
@@ -29,13 +29,13 @@ http_interactions:
29
29
  SUU9RWRnZQ==
30
30
  !binary "WC1SdW50aW1l":
31
31
  - !binary |-
32
- MC4zNDUwMTI=
32
+ MC44MTg3NTY=
33
33
  !binary "U2VydmVy":
34
34
  - !binary |-
35
- V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
35
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
36
36
  !binary "RGF0ZQ==":
37
37
  - !binary |-
38
- U2F0LCAwMiBNYXIgMjAxMyAxMzoxMDo1MCBHTVQ=
38
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTozNiBHTVQ=
39
39
  !binary "Q29udGVudC1MZW5ndGg=":
40
40
  - !binary |-
41
41
  MzI=
@@ -45,16 +45,16 @@ http_interactions:
45
45
  body:
46
46
  encoding: ASCII-8BIT
47
47
  string: !binary |-
48
- eyJ0b2tlbiI6InlOem81MUt1Zk12ZXRabmVvN2NEIn0=
48
+ eyJ0b2tlbiI6InJ6Z3dpc3NFMUpLWVVFRGtlNXNTIn0=
49
49
  http_version:
50
- recorded_at: Sat, 02 Mar 2013 13:10:50 GMT
50
+ recorded_at: Tue, 30 Apr 2013 02:31:36 GMT
51
51
  - request:
52
52
  method: post
53
- uri: http://localhost:3000/api/v1/facturas.json?auth_token=yNzo51KufMvetZneo7cD
53
+ uri: http://localhost:3000/api/v1/facturas.json?auth_token=rzgwissE1JKYUEDke5sS
54
54
  body:
55
55
  encoding: UTF-8
56
- string: ! '{"factura":{"fecha":"2013-03-02","sale_point":1,"numero":5428551,"cliente":{"razonsocial":"Los
57
- alerces","cuit_number":20233119354,"condicioniva_id":1},"detalles":[{"cantidad":10,"preciounitario":15.5,"descripcion":"detalle","tasaiva":21.0},{"cantidad":8,"preciounitario":35.0,"descripcion":"detalle","tasaiva":21.0}]}}'
56
+ string: ! '{"factura":{"fecha":"2013-04-29","sale_point":1,"numero":7508177,"detalles":[{"cantidad":10,"preciounitario":15.5,"descripcion":"detalle","tasaiva":21.0},{"cantidad":8,"preciounitario":35.0,"descripcion":"detalle","tasaiva":21.0}],"cliente":{"razonsocial":"Los
57
+ alerces","cuit_number":20233119354,"condicioniva_id":1}}}'
58
58
  headers:
59
59
  Content-Type:
60
60
  - application/json
@@ -66,7 +66,7 @@ http_interactions:
66
66
  headers:
67
67
  !binary "TG9jYXRpb24=":
68
68
  - !binary |-
69
- aHR0cDovL2xvY2FsaG9zdDozMDAwL2NsaWVudGVzLzE0L2ZhY3R1cmFzLzMy
69
+ aHR0cDovL2xvY2FsaG9zdDozMDAwL2NsaWVudGVzLzE4L2ZhY3R1cmFzLzI4
70
70
  !binary "Q29udGVudC1UeXBl":
71
71
  - !binary |-
72
72
  YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
@@ -78,13 +78,13 @@ http_interactions:
78
78
  SUU9RWRnZQ==
79
79
  !binary "WC1SdW50aW1l":
80
80
  - !binary |-
81
- MS4yMDk1ODQ=
81
+ NS4yOTA5NTI=
82
82
  !binary "U2VydmVy":
83
83
  - !binary |-
84
- V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
84
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
85
85
  !binary "RGF0ZQ==":
86
86
  - !binary |-
87
- U2F0LCAwMiBNYXIgMjAxMyAxMzoxMDo1MSBHTVQ=
87
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTo0MiBHTVQ=
88
88
  !binary "Q29udGVudC1MZW5ndGg=":
89
89
  - !binary |-
90
90
  MQ==
@@ -94,15 +94,15 @@ http_interactions:
94
94
  !binary "U2V0LUNvb2tpZQ==":
95
95
  - !binary |-
96
96
  X3Bvc2VpZG9uX3Nlc3Npb249QkFoN0Iwa2lHWGRoY21SbGJpNTFjMlZ5TG5W
97
- elpYSXVhMlY1QmpvR1JWUmJDRWtpQ1ZWelpYSUdPd0JHV3dacEJra2lJaVF5
98
- WVNReE1DUkNOMjVGTkZwTE1VOUljbk13V2xwT2JVeENaazVQQmpzQVZFa2lE
99
- M05sYzNOcGIyNWZhV1FHT3dCR0lpVTNZalZpTUdOaU5HWmtNak16TXpJM09H
100
- UXhPVGcyTXpGaE1UZzJZbUl4WWclM0QlM0QtLWM3MzA4OWM2MjMwMDAzNDFl
101
- NzVlYWIyOWNlZmE0YzA0MWU0YTYzZjU7IHBhdGg9LzsgSHR0cE9ubHk=
97
+ elpYSXVhMlY1QmpvR1JWUmJDRWtpQ1ZWelpYSUdPd0JHV3dacEVFa2lJaVF5
98
+ WVNReE1DUk9TR05VVTFsb1VYRXpTV3hyU2xNMWJEVlRSa2gxQmpzQVZFa2lE
99
+ M05sYzNOcGIyNWZhV1FHT3dCR0lpVmpORFV5TURobE5HVXdOMkpqWWpBek4y
100
+ WTNNVE0zTTJGbFlUQXpPR1F3TnclM0QlM0QtLWVhMTU4ZWJiOTZkMWQ1ODkw
101
+ MDgxZmRkY2EwMTBmNGU3NTIyNTc5ZTg7IHBhdGg9LzsgSHR0cE9ubHk=
102
102
  body:
103
103
  encoding: ASCII-8BIT
104
104
  string: !binary |-
105
105
  IA==
106
106
  http_version:
107
- recorded_at: Sat, 02 Mar 2013 13:10:51 GMT
107
+ recorded_at: Tue, 30 Apr 2013 02:31:42 GMT
108
108
  recorded_with: VCR 2.4.0
@@ -0,0 +1,108 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/api/v1/tokens
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"email":"lmpetek@gmail.com","password":"123456"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: !binary |-
16
+ T0sg
17
+ headers:
18
+ !binary "Q29udGVudC1UeXBl":
19
+ - !binary |-
20
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
21
+ !binary "RXRhZw==":
22
+ - !binary |-
23
+ IjU2NmNmNjdmYTI1MWIwOGUyMmJiZWU5YWM2YTIwOTBlIg==
24
+ !binary "Q2FjaGUtQ29udHJvbA==":
25
+ - !binary |-
26
+ bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
27
+ !binary "WC1VYS1Db21wYXRpYmxl":
28
+ - !binary |-
29
+ SUU9RWRnZQ==
30
+ !binary "WC1SdW50aW1l":
31
+ - !binary |-
32
+ MC44MjU2OTY=
33
+ !binary "U2VydmVy":
34
+ - !binary |-
35
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
36
+ !binary "RGF0ZQ==":
37
+ - !binary |-
38
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTo0MyBHTVQ=
39
+ !binary "Q29udGVudC1MZW5ndGg=":
40
+ - !binary |-
41
+ MzI=
42
+ !binary "Q29ubmVjdGlvbg==":
43
+ - !binary |-
44
+ S2VlcC1BbGl2ZQ==
45
+ body:
46
+ encoding: ASCII-8BIT
47
+ string: !binary |-
48
+ eyJ0b2tlbiI6InJ6Z3dpc3NFMUpLWVVFRGtlNXNTIn0=
49
+ http_version:
50
+ recorded_at: Tue, 30 Apr 2013 02:31:43 GMT
51
+ - request:
52
+ method: post
53
+ uri: http://localhost:3000/api/v1/facturas.json?auth_token=rzgwissE1JKYUEDke5sS
54
+ body:
55
+ encoding: UTF-8
56
+ string: ! '{"factura":{"fecha":"2013-04-29","sale_point":1,"numero":411452,"detalles":[{"cantidad":10,"preciounitario":15.5,"descripcion":"detalle","tasaiva":21.0},{"cantidad":8,"preciounitario":35.0,"descripcion":"detalle","tasaiva":21.0}],"proveedor":{"razonsocial":"Los
57
+ alerces","cuit":"20233119354","condicioniva_id":1}}}'
58
+ headers:
59
+ Content-Type:
60
+ - application/json
61
+ response:
62
+ status:
63
+ code: 201
64
+ message: !binary |-
65
+ Q3JlYXRlZCA=
66
+ headers:
67
+ !binary "TG9jYXRpb24=":
68
+ - !binary |-
69
+ aHR0cDovL2xvY2FsaG9zdDozMDAwL3N1cHBsaWVycy84L2ZhY3R1cmFzLzM0
70
+ !binary "Q29udGVudC1UeXBl":
71
+ - !binary |-
72
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
73
+ !binary "Q2FjaGUtQ29udHJvbA==":
74
+ - !binary |-
75
+ bm8tY2FjaGU=
76
+ !binary "WC1VYS1Db21wYXRpYmxl":
77
+ - !binary |-
78
+ SUU9RWRnZQ==
79
+ !binary "WC1SdW50aW1l":
80
+ - !binary |-
81
+ MS4xNDc5MjQ=
82
+ !binary "U2VydmVy":
83
+ - !binary |-
84
+ V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEzLTAyLTIyKQ==
85
+ !binary "RGF0ZQ==":
86
+ - !binary |-
87
+ VHVlLCAzMCBBcHIgMjAxMyAwMjozMTo0NCBHTVQ=
88
+ !binary "Q29udGVudC1MZW5ndGg=":
89
+ - !binary |-
90
+ MQ==
91
+ !binary "Q29ubmVjdGlvbg==":
92
+ - !binary |-
93
+ S2VlcC1BbGl2ZQ==
94
+ !binary "U2V0LUNvb2tpZQ==":
95
+ - !binary |-
96
+ X3Bvc2VpZG9uX3Nlc3Npb249QkFoN0Iwa2lHWGRoY21SbGJpNTFjMlZ5TG5W
97
+ elpYSXVhMlY1QmpvR1JWUmJDRWtpQ1ZWelpYSUdPd0JHV3dacEVFa2lJaVF5
98
+ WVNReE1DUk9TR05VVTFsb1VYRXpTV3hyU2xNMWJEVlRSa2gxQmpzQVZFa2lE
99
+ M05sYzNOcGIyNWZhV1FHT3dCR0lpVXlOREpqTWpJeE0yUTVOemRoTVdWa05t
100
+ TTFNREE0WkdabE0yRXpZalpqTUElM0QlM0QtLWJlZTE2MGEwNmRlZDI5NjNm
101
+ NjUwYjc1YTkwNmM5ODRhNzQ3OWVmYmY7IHBhdGg9LzsgSHR0cE9ubHk=
102
+ body:
103
+ encoding: ASCII-8BIT
104
+ string: !binary |-
105
+ IA==
106
+ http_version:
107
+ recorded_at: Tue, 30 Apr 2013 02:31:44 GMT
108
+ recorded_with: VCR 2.4.0
@@ -18,9 +18,16 @@ def login
18
18
  api
19
19
  end
20
20
 
21
- def generate_invoice
21
+ def generate_invoice(type)
22
22
  invoice = Poseidon::Invoice.new(date: Date.today, sale_point: 1, number: Random.rand(1..9999999))
23
- invoice.client = Poseidon::Client.new(name: 'Los alerces', cuit: 20233119354, iva_condition_id: 1)
23
+ if type == :client
24
+ invoice.client = Poseidon::Client.new(name: 'Los alerces', cuit: 20233119354, iva_condition_id: 1)
25
+ end
26
+
27
+ if type == :supplier
28
+ invoice.supplier = Poseidon::Supplier.new(name: 'Los alerces', cuit: 20233119354, iva_condition_id: 1)
29
+ end
30
+
24
31
  [ { amount: 10, unit_price: 15.50, description: 'detalle', iva_rate: 21.0 },
25
32
  { amount: 8, unit_price: 35.0, description: 'detalle', iva_rate: 21.0 } ].each do |params|
26
33
  invoice.details << Poseidon::Detail.new(params)
@@ -48,13 +55,23 @@ Protest.describe('api') do
48
55
  end
49
56
  end
50
57
 
51
- test 'emit invoice successul' do
52
- VCR.use_cassette('valid_invoice') do
58
+ test 'emit invoice for client successful' do
59
+ VCR.use_cassette('valid_client_invoice') do
53
60
  api = Poseidon::API.new(valid_properties)
54
- result = api.emit_invoice(generate_invoice)
55
- assert result
61
+ result = api.emit_invoice(generate_invoice(:client))
62
+ puts api.errors
63
+ assert result, api.errors
56
64
  assert api.errors.empty?
57
65
  end
58
66
  end
59
67
 
68
+ test 'emit invoice for supplier successful' do
69
+ VCR.use_cassette('valid_supplier_invoice') do
70
+ api = Poseidon::API.new(valid_properties)
71
+ result = api.emit_invoice(generate_invoice(:supplier))
72
+ assert result
73
+ assert api.errors.empty?
74
+ end
75
+ end
76
+
60
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poseidon-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: protest
@@ -83,6 +83,8 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
+ - .ruby-version
87
+ - .yardopts
86
88
  - Gemfile
87
89
  - LICENSE.txt
88
90
  - README.md
@@ -92,9 +94,10 @@ files:
92
94
  - poseidon-api.gemspec
93
95
  - test/fixtures/vcr_cassetes/failed_login.yml
94
96
  - test/fixtures/vcr_cassetes/success_login.yml
95
- - test/fixtures/vcr_cassetes/valid_invoice.yml
97
+ - test/fixtures/vcr_cassetes/valid_client_invoice.yml
98
+ - test/fixtures/vcr_cassetes/valid_supplier_invoice.yml
96
99
  - test/test_poseidon_api.rb
97
- homepage: ''
100
+ homepage: https://github.com/apslab/poseidon-api
98
101
  licenses: []
99
102
  post_install_message:
100
103
  rdoc_options: []
@@ -106,21 +109,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
109
  - - ! '>='
107
110
  - !ruby/object:Gem::Version
108
111
  version: '0'
112
+ segments:
113
+ - 0
114
+ hash: 3683816868212074486
109
115
  required_rubygems_version: !ruby/object:Gem::Requirement
110
116
  none: false
111
117
  requirements:
112
118
  - - ! '>='
113
119
  - !ruby/object:Gem::Version
114
120
  version: '0'
121
+ segments:
122
+ - 0
123
+ hash: 3683816868212074486
115
124
  requirements: []
116
125
  rubyforge_project:
117
- rubygems_version: 1.8.25
126
+ rubygems_version: 1.8.23
118
127
  signing_key:
119
128
  specification_version: 3
120
129
  summary: API client for Poseidon system
121
130
  test_files:
122
131
  - test/fixtures/vcr_cassetes/failed_login.yml
123
132
  - test/fixtures/vcr_cassetes/success_login.yml
124
- - test/fixtures/vcr_cassetes/valid_invoice.yml
133
+ - test/fixtures/vcr_cassetes/valid_client_invoice.yml
134
+ - test/fixtures/vcr_cassetes/valid_supplier_invoice.yml
125
135
  - test/test_poseidon_api.rb
126
- has_rdoc: