Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
AllCops:
Exclude:
- 'doc/'
- 'coverage/'
- 'pkg/'
- 'tmp/'

Metrics/CyclomaticComplexity:
Severity: error
Max: 8

Metrics/LineLength:
Max: 110
Severity: error

Metrics/ClassLength:
Max: 150
Severity: error

Metrics/MethodLength:
Max: 15
Severity: error

Metrics/ParameterLists:
Max: 5
Severity: error

Metrics/PerceivedComplexity:
Max: 10
Severity: error

Lint/EndAlignment:
AlignWith: variable

Lint/UselessAssignment:
Severity: error

Lint/ShadowingOuterLocalVariable:
Severity: convention

Style/CaseEquality:
Enabled: false

Style/Documentation:
Enabled: false
Severity: error

Style/IfUnlessModifier:
MaxLineLength: 80

Style/GuardClause:
MinBodyLength: 3

Style/Lambda:
Enabled: false

Style/EmptyLinesAroundBody:
Enabled: false

Style/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true

Style/ClassAndModuleChildren:
Enabled: false

Style/AndOr:
EnforcedStyle: conditionals

# This one is usefull for class attr_*
Style/TrivialAccessors:
AllowDSLWriters: true

Style/AlignParameters:
EnforcedStyle: with_fixed_indentation

Style/AlignHash:
EnforcedHashRocketStyle: key
EnforcedLastArgumentHashStyle: always_ignore

Style/ModuleFunction:
Enabled: false

Style/RegexpLiteral:
# The maximum number of (escaped) slashes that a slash-delimited regexp is
# allowed to have. If there are more slashes, a %r regexp shall be used.
MaxSlashes: 0

Style/FormatString:
Enabled: false

Style/SingleLineBlockParams:
Enabled: false

Style/CaseIndentation:
IndentWhenRelativeTo: end

Style/PredicateName:
Severity: error

Style/IndentHash:
EnforcedStyle: consistent

Style/MultilineBlockChain:
Severity: error

Lint/AssignmentInCondition:
Enabled: false

Style/Alias:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SpaceInsideBlockBraces:
SpaceBeforeBlockParameters: true

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%i': '[]'
'%w': '[]'
'%W': '[]'
'%': '{}'

Style/CollectionMethods:
PreferredMethods:
reduce: inject
collect: map
collect!: 'map!'
detect: find
detect!: 'find!'
find_all: select
find_all!: 'select!'

Style/DoubleNegation:
Severity: error

Style/SignalException:
EnforcedStyle: only_raise

Style/DotPosition:
EnforcedStyle: trailing

Style/SingleLineMethods:
AllowIfMethodIsEmpty: true

# It doesnt handle cases when we want to align multiple methods call into a table like
Style/SingleSpaceBeforeFirstArg:
Enabled: false

# replaces $1 x Regexp.last_match[1]
Style/PerlBackrefs:
Enabled: false

# There are valid cases (eg. Date.parse(date) rescue nil)
Style/RescueModifier:
Enabled: false

Style/Blocks:
Severity: error
Exclude:
- '**/spec/**/*_spec.rb'
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.2
bundler_args: --without test
branches:
only:
- master
script:
- bundle exec rspec spec
- bundle exec rubocop
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ source 'http://rubygems.org'
group :test do
gem 'guard-rspec', '~> 2.4.0'
gem 'rb-fsevent', '~> 0.9.1'
gem 'debugger', '~> 1.3.0'
end

gemspec
gemspec
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ guard 'rspec', cli: '--color --format nested' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
end
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bravo
# Bravo
![Travis status](https://travis-ci.org/leanucci/bravo.png)
[![Gem Version](https://badge.fury.io/rb/bravo.png)](http://badge.fury.io/rb/bravo)
[![Code Climate](https://codeclimate.com/repos/5292a01e89af7e473304513a/badges/4a29fbaff3d74a23e634/gpa.png)](https://codeclimate.com/repos/5292a01e89af7e473304513a/feed)
Expand Down Expand Up @@ -53,20 +53,23 @@ Bravo no asume valores por defecto, por lo cual hay que configurar de forma expl

Ejemplo de configuración tomado del spec_helper de Bravo:

```ruby

require 'bravo'
require 'bravo'

Bravo.pkey = 'spec/fixtures/certs/pkey'
Bravo.cert = 'spec/fixtures/certs/cert.crt'
Bravo.cuit = '20287740027'
Bravo.sale_point = '0002'
Bravo.default_concepto = 'Productos y Servicios'
Bravo.default_documento = 'CUIT'
Bravo.default_moneda = :peso
Bravo.own_iva_cond = :responsable_inscripto
Bravo.verbose = 'true'
Bravo.openssl_bin = '/usr/local/Cellar/openssl/1.0.1e/bin/openssl'
Bravo::AuthData.environment = :test
Bravo.pkey = 'spec/fixtures/certs/pkey'
Bravo.cert = 'spec/fixtures/certs/cert.crt'
Bravo.cuit = '20287740027'
Bravo.sale_point = '0002'
Bravo.default_concepto = 'Productos y Servicios'
Bravo.default_documento = 'CUIT'
Bravo.default_moneda = :peso
Bravo.own_iva_cond = :responsable_inscripto
Bravo.verbose = 'true'
Bravo.openssl_bin = '/usr/local/Cellar/openssl/1.0.1e/bin/openssl'
Bravo::AuthData.environment = :test

```

### Emisión de comprobantes

Expand All @@ -88,18 +91,21 @@ Luego de configurar Bravo, autorizamos una factura:

Código de ejemplo para la configuración anterior:

```ruby

bill = Bravo::Bill.new

factura = Bravo::Bill.new
bill.net = 100.00 # el neto de la factura, total para Consumidor final
bill.aliciva_id = 2010 # define la alicuota de iva a utilizar, ver archivo constants.
bill.iva_cond = :consumidor_final # la condición ante el iva del comprador
bill.concepto = 'Servicios' # concepto de la factura
bill.invoice_type = :invoice # el tipo de comprobante a emitir, en este caso factura.

factura.net = 100.00 # el neto de la factura, total para Consumidor final
factura.aliciva_id = 2 # define la alicuota de iva a utilizar, ver archivo constants.
factura.iva_cond = :consumidor_final # la condición ante el iva del comprador
factura.concepto = 'Servicios' # concepto de la factura
factura.invoice_type = :invoice # el tipo de comprobante a emitir, en este caso factura.
bill.authorize

bill.authorize
bill.response.cae # contiene el cae para este comprobante.

bill.response.cae # contiene el cae para este comprobante.
```

## TODO list

Expand Down
2 changes: 1 addition & 1 deletion autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Autotest.add_discovery { "rspec2" } #added according to rspec2 book
Autotest.add_discovery { "rspec2" } # added according to rspec2 book
25 changes: 15 additions & 10 deletions bin/bravo
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
# -*- encoding: utf-8 -*-

require 'thor'

# base module
module Bravo
# Bravo executable for certificate request generation
#
class Bravo < Thor

desc 'gencsr', 'Crea el Certificate Signature Request'
method_option :bin, type: :string, required: true, desc: 'El path completo al binario de openssl'
method_option :pkey, type: :string, desc: 'Path a una clave privada preexistente. Si se omite, se crea una clave en --out'
method_option :sn, type: :string, required: true, desc: 'Nombre del servidor. Sin uso práctico, es requerido por AFIP'
method_option :cn, type: :string, required: true, desc: 'Nombre de la compañía. Sin uso práctico, es requerido por AFIP'
method_option :cuit, type: :numeric, required: true, desc: 'Número de CUIT sin guiones. Ejemplo: 20876543217'
method_option :out, type: :string, default: 'bravo-certs', desc: 'Directorio de destino para los archivos creados. Si se omite, se crea el directorio bravo-certs en pwd'
method_option :pkey, type: :string,
desc: 'Path a una clave privada preexistente. Si se omite, se crea una clave en --out'
method_option :sn, type: :string, required: true,
desc: 'Nombre del servidor. Sin uso práctico, es requerido por AFIP'
method_option :cn, type: :string, required: true,
desc: 'Nombre de la compañía. Sin uso práctico, es requerido por AFIP'
method_option :cuit, type: :numeric, required: true,
desc: 'Número de CUIT sin guiones. Ejemplo: 20876543217'
method_option :out, type: :string, default: 'bravo-certs',
desc: 'Directorio de destino para los archivos creados. Default: "./bravo-certs"'

# Certificate Signature Request wrapper for bravo.
#
Expand All @@ -28,7 +32,7 @@ module Bravo
cuit = options[:cuit]
out = options[:out]

Dir.mkdir(out) unless File.exists?(out)
Dir.mkdir(out) unless File.exist?(out)

out_path = "#{ Dir.pwd }/#{ out }/"

Expand All @@ -45,9 +49,10 @@ module Bravo
end

protected

# Creates a new private key
#
def create_pkey(bin,out_path)
def create_pkey(bin, out_path)
say('Creando pkey', :cyan)
`#{ bin } genrsa -out #{ out_path }pkey 1024`
say('Hecho!\n\n', :green)
Expand All @@ -56,4 +61,4 @@ module Bravo
end

Bravo.start
end
end
29 changes: 15 additions & 14 deletions bravo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ Gem::Specification.new do |gem|
gem.version = Bravo::VERSION
gem.authors = ["Leandro Marcucci"]
gem.email = ["[email protected]"]
gem.description = %q{Adaptador para el Web Service de Facturacion Electrónica de AFIP}
gem.summary = %q{Adaptador WSFE}
gem.description = 'Adaptador para el Web Service de Facturacion Electrónica de AFIP'
gem.summary = 'Adaptador WSFE'
gem.homepage = "https://github.com/leanucci/bravo#readme"
gem.date = %q(2011-03-14)
gem.date = '2011-03-14'

gem.files = `git ls-files`.split($/)
gem.files = `git ls-files`.split($RS)
gem.files.reject! { |f| f.include? 'vcr' }
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib", "bin"]
gem.require_paths = %w[lib bin]

gem.add_runtime_dependency(%q<savon>, ["~> 2.3.0"])
gem.add_runtime_dependency(%q<thor>, ["~> 0.17.0"])
gem.add_runtime_dependency(%{savon}, ["~> 2.8.1"])
gem.add_runtime_dependency(%{thor}, ["~> 0.17"])

gem.add_development_dependency(%q<rspec>, ["~> 2.14.0"])
gem.add_development_dependency(%q<rspec-mocks>, ["~> 2.14.0"])
gem.add_development_dependency(%q<rake>, ["~> 10.0.0"])
gem.add_development_dependency(%q<vcr>, ["~> 2.4.0"])
gem.add_development_dependency(%q<simplecov>, ["~> 0.7.0"])
gem.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
gem.add_development_dependency(%{rspec}, ["~> 2.14.0"])
gem.add_development_dependency(%{rspec-mocks}, ["~> 2.14.0"])
gem.add_development_dependency(%{rake}, ["~> 10.0.0"])
gem.add_development_dependency(%{vcr}, ["~> 2.4.0"])
gem.add_development_dependency(%{simplecov}, ["~> 0.7.0"])
gem.add_development_dependency(%{fakeweb}, ["~> 1.3.0"])
gem.add_development_dependency(%{rubocop}, ["~> 0.26.1"])
end
3 changes: 1 addition & 2 deletions examples/invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Let's issue a Factura for 1200 ARS to a Responsable Inscripto
bill_a = Bravo::Bill.new(iva_condition: :responsable_inscripto, net: 1200, invoice_type: :invoice)
bill_a.document_number = '30710151543'
bill_a.document_number = '30710151543'
bill_a.document_type = 'CUIT'
bill_a.authorize

Expand All @@ -33,4 +33,3 @@
puts "Authorization result = #{ bill_b.authorized? }"
puts "Authorization response."
pp bill_b.response

Loading