poseidon-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +9 -0
- data/lib/poseidon-api/version.rb +5 -0
- data/lib/poseidon-api.rb +152 -0
- data/poseidon-api.gemspec +25 -0
- data/test/fixtures/vcr_cassetes/failed_login.yml +48 -0
- data/test/fixtures/vcr_cassetes/success_login.yml +51 -0
- data/test/fixtures/vcr_cassetes/valid_invoice.yml +108 -0
- data/test/test_poseidon_api.rb +60 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Maximiliano Dello Russo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Poseidon::Api
|
2
|
+
|
3
|
+
Cliente para interactuar con la API del sistema Poseidon.
|
4
|
+
|
5
|
+
## Instalación
|
6
|
+
|
7
|
+
Agregar la siguiente linea a su Gemfile:
|
8
|
+
|
9
|
+
gem 'poseidon-api'
|
10
|
+
|
11
|
+
Y luego ejecutar:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
O instalar directamente:
|
16
|
+
|
17
|
+
$ gem install poseidon-api
|
18
|
+
|
19
|
+
## Modo de uso
|
20
|
+
|
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
|
+
Retorna un booleano que indica si pudo o no emitir la factura.
|
27
|
+
|
28
|
+
En caso de no emitir la factura se pueden verificar los errores utilizando el método 'errors'
|
29
|
+
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/poseidon-api.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
require "poseidon-api/version"
|
2
|
+
require 'json'
|
3
|
+
require 'curb'
|
4
|
+
|
5
|
+
# Cliente para interactuar con la API del sistema poseidon.
|
6
|
+
#
|
7
|
+
# Ejemplo:
|
8
|
+
#
|
9
|
+
# api = Poseidon::API(url: 'http://poseidon-url.com', user: 'user@test.com', password: '12345')
|
10
|
+
# invoice = Poseidon::Invoice.new ...
|
11
|
+
# ...
|
12
|
+
# emitted = api.emit_invoice(invoice)
|
13
|
+
#
|
14
|
+
# Retorna un booleano que indica si pudo o no emitir la factura.
|
15
|
+
#
|
16
|
+
# En caso de no emitir la factura se pueden verificar los errores utilizando el método 'errors'
|
17
|
+
#
|
18
|
+
module Poseidon
|
19
|
+
class API
|
20
|
+
|
21
|
+
attr_reader :token, :errors
|
22
|
+
|
23
|
+
# El constructor requiere los atributos:
|
24
|
+
#
|
25
|
+
# + url: URL de la aplicación Poseidon.
|
26
|
+
# + user: Identificador del usuario poseidon que ingresa (email).
|
27
|
+
# + password: Contraseña de acceso.
|
28
|
+
# + version: Versión de la API a utilizar.
|
29
|
+
#
|
30
|
+
def initialize(properties)
|
31
|
+
@service_url = properties[:url]
|
32
|
+
@user = properties[:user]
|
33
|
+
@password = properties[:password]
|
34
|
+
@errors = []
|
35
|
+
@version = properties[:version] || 'v1'
|
36
|
+
end
|
37
|
+
|
38
|
+
def login
|
39
|
+
json = { :email => @user, :password => @password }.to_json
|
40
|
+
curl = post(token_uri, json)
|
41
|
+
if curl.response_code == 200
|
42
|
+
response = JSON.parse(curl.body_str)
|
43
|
+
@token = response['token']
|
44
|
+
return true
|
45
|
+
else
|
46
|
+
response = JSON.parse(curl.body_str)
|
47
|
+
@errors << response['error']
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def emit_invoice(invoice)
|
53
|
+
login if @token.nil?
|
54
|
+
curl = post(facturas_uri, invoice.to_json)
|
55
|
+
status_code = curl.response_code
|
56
|
+
# TODO analizar que sucede si hay un token pero la petición retorna error 401 (unauthorized)
|
57
|
+
# Debería volver a pedirse un token y reintentar?
|
58
|
+
if curl.response_code == 201 # created
|
59
|
+
return true
|
60
|
+
else
|
61
|
+
response = JSON.parse(curl.body_str)
|
62
|
+
@errors.clear << response['error']
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def hello
|
68
|
+
'world'
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def post(uri, json)
|
74
|
+
c = Curl.post(uri, json) do |curl|
|
75
|
+
curl.headers['Content-Type'] = 'application/json'
|
76
|
+
end
|
77
|
+
#c.perform
|
78
|
+
c
|
79
|
+
end
|
80
|
+
|
81
|
+
def api_uri
|
82
|
+
"#{@service_url}/api/#{@version}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def token_uri
|
86
|
+
"#{api_uri}/tokens"
|
87
|
+
end
|
88
|
+
|
89
|
+
def facturas_uri
|
90
|
+
"#{api_uri}/facturas.json?auth_token=#{@token}"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
class Invoice
|
97
|
+
attr_accessor :date, :sale_point, :number, :client, :details
|
98
|
+
|
99
|
+
def initialize(attrs)
|
100
|
+
@date = attrs[:date] || Date.now
|
101
|
+
@sale_point = attrs[:sale_point]
|
102
|
+
@number = attrs[:number]
|
103
|
+
@client = attrs[:client]
|
104
|
+
@details = []
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_hash
|
108
|
+
{ factura: {
|
109
|
+
fecha: @date,
|
110
|
+
sale_point: @sale_point,
|
111
|
+
numero: @number,
|
112
|
+
cliente: @client.to_hash,
|
113
|
+
detalles: @details.map { |detail| detail.to_hash }
|
114
|
+
}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def to_json
|
119
|
+
to_hash.to_json
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class Client
|
124
|
+
attr_accessor :name, :cuit, :iva_condition_id
|
125
|
+
|
126
|
+
def initialize(attrs)
|
127
|
+
@name = attrs[:name]
|
128
|
+
@cuit = attrs[:cuit]
|
129
|
+
@iva_condition_id = attrs[:iva_condition_id]
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_hash
|
133
|
+
{ razonsocial: @name, cuit_number: @cuit, condicioniva_id: @iva_condition_id }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class Detail
|
138
|
+
attr_accessor :amount, :unit_price, :description, :iva_rate
|
139
|
+
|
140
|
+
def initialize(attrs)
|
141
|
+
@amount = attrs[:amount]
|
142
|
+
@unit_price = attrs[:unit_price]
|
143
|
+
@description = attrs[:description]
|
144
|
+
@iva_rate = attrs[:iva_rate]
|
145
|
+
end
|
146
|
+
|
147
|
+
def to_hash
|
148
|
+
{ cantidad: @amount, preciounitario: @unit_price, descripcion: @description, tasaiva: @iva_rate }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'poseidon-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "poseidon-api"
|
8
|
+
gem.version = Poseidon::Api::VERSION
|
9
|
+
gem.authors = ["Maximiliano Dello Russo"]
|
10
|
+
gem.email = ["maxidr@gmail.com"]
|
11
|
+
gem.description = %q{An API to interact with the Poseidon system}
|
12
|
+
gem.summary = %q{API client for Poseidon system}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('protest', '0.4.0')
|
21
|
+
gem.add_development_dependency('vcr', '2.4.0')
|
22
|
+
gem.add_development_dependency('webmock', '1.9.3')
|
23
|
+
gem.add_dependency('curb', '0.8.3')
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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":""}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 401
|
15
|
+
message: !binary |-
|
16
|
+
VW5hdXRob3JpemVkIA==
|
17
|
+
headers:
|
18
|
+
!binary "Q29udGVudC1UeXBl":
|
19
|
+
- !binary |-
|
20
|
+
YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
|
21
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
22
|
+
- !binary |-
|
23
|
+
bm8tY2FjaGU=
|
24
|
+
!binary "WC1VYS1Db21wYXRpYmxl":
|
25
|
+
- !binary |-
|
26
|
+
SUU9RWRnZQ==
|
27
|
+
!binary "WC1SdW50aW1l":
|
28
|
+
- !binary |-
|
29
|
+
MC40MjU4NDI=
|
30
|
+
!binary "U2VydmVy":
|
31
|
+
- !binary |-
|
32
|
+
V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
|
33
|
+
!binary "RGF0ZQ==":
|
34
|
+
- !binary |-
|
35
|
+
U2F0LCAwMiBNYXIgMjAxMyAxMzoxMjoxMSBHTVQ=
|
36
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
37
|
+
- !binary |-
|
38
|
+
NDM=
|
39
|
+
!binary "Q29ubmVjdGlvbg==":
|
40
|
+
- !binary |-
|
41
|
+
S2VlcC1BbGl2ZQ==
|
42
|
+
body:
|
43
|
+
encoding: ASCII-8BIT
|
44
|
+
string: !binary |-
|
45
|
+
eyJlcnJvciI6IkVtYWlsIG8gcGFzc3dvcmQgaW52XHUwMGUxbGlkb3MifQ==
|
46
|
+
http_version:
|
47
|
+
recorded_at: Sat, 02 Mar 2013 13:12:11 GMT
|
48
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,51 @@
|
|
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
|
+
IjJhZjAzZDgwMmZiM2U1YTFiZWZkMmNkNWE4ZDY1MjM1Ig==
|
24
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
25
|
+
- !binary |-
|
26
|
+
bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
|
27
|
+
!binary "WC1VYS1Db21wYXRpYmxl":
|
28
|
+
- !binary |-
|
29
|
+
SUU9RWRnZQ==
|
30
|
+
!binary "WC1SdW50aW1l":
|
31
|
+
- !binary |-
|
32
|
+
MC40NDA2OTg=
|
33
|
+
!binary "U2VydmVy":
|
34
|
+
- !binary |-
|
35
|
+
V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
|
36
|
+
!binary "RGF0ZQ==":
|
37
|
+
- !binary |-
|
38
|
+
U2F0LCAwMiBNYXIgMjAxMyAxMzoxMjoxMSBHTVQ=
|
39
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
40
|
+
- !binary |-
|
41
|
+
MzI=
|
42
|
+
!binary "Q29ubmVjdGlvbg==":
|
43
|
+
- !binary |-
|
44
|
+
S2VlcC1BbGl2ZQ==
|
45
|
+
body:
|
46
|
+
encoding: ASCII-8BIT
|
47
|
+
string: !binary |-
|
48
|
+
eyJ0b2tlbiI6InlOem81MUt1Zk12ZXRabmVvN2NEIn0=
|
49
|
+
http_version:
|
50
|
+
recorded_at: Sat, 02 Mar 2013 13:12:11 GMT
|
51
|
+
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
|
+
IjJhZjAzZDgwMmZiM2U1YTFiZWZkMmNkNWE4ZDY1MjM1Ig==
|
24
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
25
|
+
- !binary |-
|
26
|
+
bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
|
27
|
+
!binary "WC1VYS1Db21wYXRpYmxl":
|
28
|
+
- !binary |-
|
29
|
+
SUU9RWRnZQ==
|
30
|
+
!binary "WC1SdW50aW1l":
|
31
|
+
- !binary |-
|
32
|
+
MC4zNDUwMTI=
|
33
|
+
!binary "U2VydmVy":
|
34
|
+
- !binary |-
|
35
|
+
V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
|
36
|
+
!binary "RGF0ZQ==":
|
37
|
+
- !binary |-
|
38
|
+
U2F0LCAwMiBNYXIgMjAxMyAxMzoxMDo1MCBHTVQ=
|
39
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
40
|
+
- !binary |-
|
41
|
+
MzI=
|
42
|
+
!binary "Q29ubmVjdGlvbg==":
|
43
|
+
- !binary |-
|
44
|
+
S2VlcC1BbGl2ZQ==
|
45
|
+
body:
|
46
|
+
encoding: ASCII-8BIT
|
47
|
+
string: !binary |-
|
48
|
+
eyJ0b2tlbiI6InlOem81MUt1Zk12ZXRabmVvN2NEIn0=
|
49
|
+
http_version:
|
50
|
+
recorded_at: Sat, 02 Mar 2013 13:10:50 GMT
|
51
|
+
- request:
|
52
|
+
method: post
|
53
|
+
uri: http://localhost:3000/api/v1/facturas.json?auth_token=yNzo51KufMvetZneo7cD
|
54
|
+
body:
|
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}]}}'
|
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
|
+
aHR0cDovL2xvY2FsaG9zdDozMDAwL2NsaWVudGVzLzE0L2ZhY3R1cmFzLzMy
|
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
|
+
MS4yMDk1ODQ=
|
82
|
+
!binary "U2VydmVy":
|
83
|
+
- !binary |-
|
84
|
+
V0VCcmljay8xLjMuMSAoUnVieS8xLjkuMy8yMDEyLTA0LTIwKQ==
|
85
|
+
!binary "RGF0ZQ==":
|
86
|
+
- !binary |-
|
87
|
+
U2F0LCAwMiBNYXIgMjAxMyAxMzoxMDo1MSBHTVQ=
|
88
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
89
|
+
- !binary |-
|
90
|
+
MQ==
|
91
|
+
!binary "Q29ubmVjdGlvbg==":
|
92
|
+
- !binary |-
|
93
|
+
S2VlcC1BbGl2ZQ==
|
94
|
+
!binary "U2V0LUNvb2tpZQ==":
|
95
|
+
- !binary |-
|
96
|
+
X3Bvc2VpZG9uX3Nlc3Npb249QkFoN0Iwa2lHWGRoY21SbGJpNTFjMlZ5TG5W
|
97
|
+
elpYSXVhMlY1QmpvR1JWUmJDRWtpQ1ZWelpYSUdPd0JHV3dacEJra2lJaVF5
|
98
|
+
WVNReE1DUkNOMjVGTkZwTE1VOUljbk13V2xwT2JVeENaazVQQmpzQVZFa2lE
|
99
|
+
M05sYzNOcGIyNWZhV1FHT3dCR0lpVTNZalZpTUdOaU5HWmtNak16TXpJM09H
|
100
|
+
UXhPVGcyTXpGaE1UZzJZbUl4WWclM0QlM0QtLWM3MzA4OWM2MjMwMDAzNDFl
|
101
|
+
NzVlYWIyOWNlZmE0YzA0MWU0YTYzZjU7IHBhdGg9LzsgSHR0cE9ubHk=
|
102
|
+
body:
|
103
|
+
encoding: ASCII-8BIT
|
104
|
+
string: !binary |-
|
105
|
+
IA==
|
106
|
+
http_version:
|
107
|
+
recorded_at: Sat, 02 Mar 2013 13:10:51 GMT
|
108
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'protest'
|
2
|
+
require 'poseidon-api'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
VCR.configure do |c|
|
6
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassetes'
|
7
|
+
c.hook_into :webmock
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def valid_properties
|
12
|
+
{ :user => 'lmpetek@gmail.com', :password => '123456', url: 'http://localhost:3000' }
|
13
|
+
end
|
14
|
+
|
15
|
+
def login
|
16
|
+
api = Poseidon::API.new(valid_properties)
|
17
|
+
api.login
|
18
|
+
api
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_invoice
|
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)
|
24
|
+
[ { amount: 10, unit_price: 15.50, description: 'detalle', iva_rate: 21.0 },
|
25
|
+
{ amount: 8, unit_price: 35.0, description: 'detalle', iva_rate: 21.0 } ].each do |params|
|
26
|
+
invoice.details << Poseidon::Detail.new(params)
|
27
|
+
end
|
28
|
+
invoice
|
29
|
+
end
|
30
|
+
|
31
|
+
Protest.describe('api') do
|
32
|
+
|
33
|
+
test 'success login' do
|
34
|
+
VCR.use_cassette('success_login') do
|
35
|
+
api = Poseidon::API.new(valid_properties)
|
36
|
+
assert api.login
|
37
|
+
assert api.errors.empty?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'failed login' do
|
42
|
+
VCR.use_cassette('failed_login') do
|
43
|
+
properties = valid_properties.clone
|
44
|
+
properties[:password] = ''
|
45
|
+
api = Poseidon::API.new(properties)
|
46
|
+
assert api.login == false
|
47
|
+
assert !api.errors.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'emit invoice successul' do
|
52
|
+
VCR.use_cassette('valid_invoice') do
|
53
|
+
api = Poseidon::API.new(valid_properties)
|
54
|
+
result = api.emit_invoice(generate_invoice)
|
55
|
+
assert result
|
56
|
+
assert api.errors.empty?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poseidon-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maximiliano Dello Russo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: protest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: vcr
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.4.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.9.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.9.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: curb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.8.3
|
78
|
+
description: An API to interact with the Poseidon system
|
79
|
+
email:
|
80
|
+
- maxidr@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/poseidon-api.rb
|
91
|
+
- lib/poseidon-api/version.rb
|
92
|
+
- poseidon-api.gemspec
|
93
|
+
- test/fixtures/vcr_cassetes/failed_login.yml
|
94
|
+
- test/fixtures/vcr_cassetes/success_login.yml
|
95
|
+
- test/fixtures/vcr_cassetes/valid_invoice.yml
|
96
|
+
- test/test_poseidon_api.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses: []
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.8.25
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: API client for Poseidon system
|
121
|
+
test_files:
|
122
|
+
- test/fixtures/vcr_cassetes/failed_login.yml
|
123
|
+
- test/fixtures/vcr_cassetes/success_login.yml
|
124
|
+
- test/fixtures/vcr_cassetes/valid_invoice.yml
|
125
|
+
- test/test_poseidon_api.rb
|
126
|
+
has_rdoc:
|