facturapi_ruby 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/facturapi_ruby.gemspec +27 -0
- data/lib/facturapi_ruby/configuration.rb +9 -0
- data/lib/facturapi_ruby/constants.rb +104 -0
- data/lib/facturapi_ruby/customers.rb +14 -0
- data/lib/facturapi_ruby/files.rb +21 -0
- data/lib/facturapi_ruby/http_client.rb +60 -0
- data/lib/facturapi_ruby/invoices.rb +14 -0
- data/lib/facturapi_ruby/version.rb +3 -0
- data/lib/facturapi_ruby.rb +17 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f51d73101163590d01463d5607e6c789f9fe935d8916e7d41b57420aefd9522
|
4
|
+
data.tar.gz: 93da5448c4d3550803309b16c9121ba3ca83a9f2cf235b8c6abe303df9e46666
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01061da5a449923da87b678819d62b5a7f96feca9a0024cdbc858d29ff426a792b11bf545e340a4daae4aefcba1b7d4a5b0caf12af4b4828ad5cd4853aea03f5
|
7
|
+
data.tar.gz: 8860e62a973e98f6a17cf87d34ebdc241457f06c26af834238f9a0de4a1feed42f0c88dfab018394a8610afcce7ff9737aed438a30a41da2f5b8fd5551363faf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at diegollams@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
facturapi_ruby (1.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
facturapi_ruby!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Diego Llamas Velasco
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# FacturapiRuby
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/facturapi_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'facturapi_ruby'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install facturapi_ruby
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Invoices
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
begin
|
28
|
+
ext_invoice = FacturapiRuby::Invoices.create(
|
29
|
+
customer: customer_id,
|
30
|
+
items: items,
|
31
|
+
payment_form: payment_form,
|
32
|
+
payment_method: payment_method,
|
33
|
+
use: use
|
34
|
+
)
|
35
|
+
rescue FacturapiRuby::FacturapiRubyError => e
|
36
|
+
puts e.data['message']
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
### Customers
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
begin
|
44
|
+
customer = FacturapiRuby::Customers.create(
|
45
|
+
legal_name: invoice_information.business_name,
|
46
|
+
email: invoice_information.email,
|
47
|
+
tax_id: invoice_information.rfc
|
48
|
+
)
|
49
|
+
client.update_column(:customer_id, customer['id'])
|
50
|
+
rescue FacturapiRuby::FacturapiRubyError => e
|
51
|
+
e.data['message']
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### Pdf
|
56
|
+
|
57
|
+
Remember to close tempfile
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
pdf = FacturapiRuby::Files.pdf(invoice_id: invoice_id)
|
61
|
+
pdf.close
|
62
|
+
```
|
63
|
+
|
64
|
+
### Xml
|
65
|
+
Remember to close tempfile
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
xml = FacturapiRuby::Files.xml(invoice_id: @invoice.ext_invoice_id)
|
69
|
+
xml.close
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
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).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/diegollams/facturapi_ruby. 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.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
Everyone interacting in the FacturapiRuby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/facturapi_ruby/blob/master/CODE_OF_CONDUCT.md).
|
89
|
+
|
90
|
+
## TODO
|
91
|
+
|
92
|
+
### Invoices
|
93
|
+
- Show
|
94
|
+
- List
|
95
|
+
- Delete
|
96
|
+
- Update
|
97
|
+
### Invoices
|
98
|
+
- Show
|
99
|
+
- List
|
100
|
+
- Delete
|
101
|
+
- Update
|
102
|
+
- Zip
|
103
|
+
### Product
|
104
|
+
- Create
|
105
|
+
- Show
|
106
|
+
- List
|
107
|
+
- Delete
|
108
|
+
- Update
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "facturapi_ruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "facturapi_ruby/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "facturapi_ruby"
|
8
|
+
spec.version = FacturapiRuby::VERSION
|
9
|
+
spec.authors = ["Diego Llamas Velasco"]
|
10
|
+
spec.email = ["diegollams@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Crea Facturas Electrónicas válidas lo más fácil posible (CFDI) https://facturapi.io}
|
13
|
+
spec.description = %q{Http client for https://facturapi.io}
|
14
|
+
spec.homepage = "https://github.com/diegollams/facturapi_ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module FacturapiRuby
|
2
|
+
PAYMENT_FORM = {
|
3
|
+
EFECTIVO: "01",
|
4
|
+
CHEQUE_NOMINATIVO: "02",
|
5
|
+
TRANSFERENCIA_ELECTRONICA: "03",
|
6
|
+
TARJETA_DE_CREDITO: "04",
|
7
|
+
MONEDERO_ELECTRONICO: "05",
|
8
|
+
DINERO_ELECTRONICO: "06",
|
9
|
+
VALES_DE_DESPENSA: "08",
|
10
|
+
DACION_EN_PAGO: "12",
|
11
|
+
SUBROGACION: "13",
|
12
|
+
CONSIGNACION: "14",
|
13
|
+
CONDONACION: "15",
|
14
|
+
COMPENSACION: "17",
|
15
|
+
NOVACION: "23",
|
16
|
+
CONFUSION: "24",
|
17
|
+
REMISION_DE_DEUDA: "25",
|
18
|
+
PRESCRIPCION_O_CADUCIDAD: "26",
|
19
|
+
A_SATISFACCION_DEL_ACREEDOR: "27",
|
20
|
+
TARJETA_DE_DEBITO: "28",
|
21
|
+
TARJETA_DE_SERVICIOS: "29",
|
22
|
+
POR_DEFINIR: "99"
|
23
|
+
}
|
24
|
+
|
25
|
+
TAX_TYPE = {
|
26
|
+
IVA: "IVA",
|
27
|
+
IEPS: "IEPS",
|
28
|
+
ISR: "ISR"
|
29
|
+
}
|
30
|
+
|
31
|
+
PAYMENT_METHOD = {
|
32
|
+
PAGO_EN_UNA_EXHIBICION: "PUE",
|
33
|
+
PAGO_EN_PARCIALIDADES_DIFERIDO: "PPD"
|
34
|
+
}
|
35
|
+
|
36
|
+
INVOICE_USE = {
|
37
|
+
ADQUISICION_MERCANCIAS: "G01",
|
38
|
+
DEVOLUCIONES_DESCUENTOS_BONIFICACIONES: "G02",
|
39
|
+
GASTOS_EN_GENERAL: "G03",
|
40
|
+
CONSTRUCCIONES: "I01",
|
41
|
+
MOBILIARIO_Y_EQUIPO_DE_OFICINA: "I02",
|
42
|
+
EQUIPO_DE_TRANSPORTE: "I03",
|
43
|
+
EQUIPO_DE_COMPUTO: "I04",
|
44
|
+
DADOS_TROQUELES_HERRAMENTAL: "I05",
|
45
|
+
COMUNICACIONES_TELEFONICAS: "I06",
|
46
|
+
COMUNICACIONES_SATELITALES: "I07",
|
47
|
+
OTRA_MAQUINARIA: "I08",
|
48
|
+
HONORARIOS_MEDICOS: "D01",
|
49
|
+
GASTOS_MEDICOS_POR_INCAPACIDAD: "D02",
|
50
|
+
GASTOS_FUNERALES: "D03",
|
51
|
+
DONATIVOS: "D04",
|
52
|
+
INTERESES_POR_CREDITOS_HIPOTECARIOS: "D05",
|
53
|
+
APORTACIONES_VOLUNTARIAS_SAR: "D06",
|
54
|
+
PRIMA_SEGUROS_GASTOS_MEDICOS: "D07",
|
55
|
+
GASTOS_TRANSPORTACION_ESCOLAR: "D08",
|
56
|
+
CUENTAS_AHORRO_PENSIONES: "D09",
|
57
|
+
SERVICIOS_EDUCATIVOS: "D10",
|
58
|
+
POR_DEFINIR: "P01"
|
59
|
+
}
|
60
|
+
|
61
|
+
INVOICE_TYPE = {
|
62
|
+
INGRESO: "I",
|
63
|
+
EGRESO: "E",
|
64
|
+
TRASLADO: "T",
|
65
|
+
NOMINA: "N",
|
66
|
+
PAGO: "P"
|
67
|
+
}
|
68
|
+
|
69
|
+
INVOICE_RELATION = {
|
70
|
+
NOTA_DE_CREDITO: "01",
|
71
|
+
NOTA_DE_DEBITO: "02",
|
72
|
+
DELOVUCION_DE_MERCANCIA: "03",
|
73
|
+
SUSTITUCION_DE_CFDI_PREVIOS: "04",
|
74
|
+
TRASLADOS_DE_MERCANCIA_FACTURADOS_PREVIAMENTE: "05",
|
75
|
+
FACTURA_POR_TRASLADOS_PREVIOS: "06",
|
76
|
+
APLICACION_DE_ANTICIPO: "07",
|
77
|
+
PAGOS_EN_PARCIALIDADES: "08",
|
78
|
+
PAGOS_DIFERIDOS: "09"
|
79
|
+
}
|
80
|
+
|
81
|
+
TAX_SYSTEM = {
|
82
|
+
GENERAL_LEY_DE_PERSONAS_MORALES: "601",
|
83
|
+
PERSONAS_MORALES_CON_FINES_NO_LUCRATIVOS: "603",
|
84
|
+
SUELDOS_Y_SALARIOS: "605",
|
85
|
+
ARRENDAMIENTO: "606",
|
86
|
+
DEMAS_INGRESOS: "608",
|
87
|
+
CONSOLIDACION: "609",
|
88
|
+
RESIDENTES_EN_EL_EXTRANJERO: "610",
|
89
|
+
INGRESOS_POR_DIVIDENDOS_SOCIOS_Y_ACCIONISTAS: "611",
|
90
|
+
PERSONAS_FISICAS_CON_ACTIVIDADES_EMPRESARIALES_Y_PROFESIONALES: "612",
|
91
|
+
INGRESOS_POR_INTERESES: "614",
|
92
|
+
SIN_OBLIGACIONES_FISCALES: "616",
|
93
|
+
SOCIEDADES_COOPERATIVAS_DE_PRODUCCION: "620",
|
94
|
+
REGIMEN_DE_INCORPORACION_FISCAL: "621",
|
95
|
+
ACTIVIDADES_AGRICOLAS_GANADERAS_SILVICOLAS_Y_PESQUERAS: "622",
|
96
|
+
OPCIONAL_PARA_GRUPOS_DE_SOCIEDADES: "623",
|
97
|
+
COORDINADOS: "624",
|
98
|
+
HIDROCARBUROS: "628",
|
99
|
+
REGIMEN_DE_ENAJENACION_O_ADQUISICION_DE_BIENES: "607",
|
100
|
+
PREFERENTES_Y_EMPRESAS_MULTINACIONALES: "629",
|
101
|
+
ENAJENACION_DE_ACCIONES_EN_BOLSA_DE_VALORES: "630",
|
102
|
+
REGIMEN_DE_LOS_INGRESOS_POR_OBTENCION_DE_PREMIOS: "615"
|
103
|
+
}
|
104
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'facturapi_ruby/http_client'
|
2
|
+
|
3
|
+
module FacturapiRuby
|
4
|
+
module Files
|
5
|
+
class << self
|
6
|
+
def pdf(options)
|
7
|
+
HttpClient.get_file(
|
8
|
+
endpoint: "/invoices/#{options[:invoice_id]}/pdf",
|
9
|
+
file_ext: '.pdf'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def xml(options)
|
14
|
+
HttpClient.get_file(
|
15
|
+
endpoint: "/invoices/#{options[:invoice_id]}/xml",
|
16
|
+
file_ext: '.xml'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module FacturapiRuby
|
6
|
+
class FacturapiRubyError < StandardError
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :data
|
12
|
+
end
|
13
|
+
|
14
|
+
module HttpClient
|
15
|
+
|
16
|
+
class << self
|
17
|
+
BASE_URL = 'https://www.facturapi.io/v1'
|
18
|
+
|
19
|
+
def get_file(options)
|
20
|
+
uri = URI(BASE_URL + options[:endpoint])
|
21
|
+
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
+
http.use_ssl = true
|
24
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
+
request.basic_auth(FacturapiRuby.configuration.api_key, '')
|
26
|
+
|
27
|
+
response = http.request(request)
|
28
|
+
file = Tempfile.open(['my', options[:file_ext]])
|
29
|
+
file.binmode
|
30
|
+
file.write(response.body)
|
31
|
+
|
32
|
+
if response.code == '200'
|
33
|
+
file
|
34
|
+
else
|
35
|
+
raise FacturapiRubyError.new(JSON.parse(response.body))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def post(options)
|
40
|
+
uri = URI(BASE_URL + options[:endpoint])
|
41
|
+
|
42
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
43
|
+
http.use_ssl = true
|
44
|
+
|
45
|
+
request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
|
46
|
+
request.body = options[:api_options].to_json
|
47
|
+
request.basic_auth(FacturapiRuby.configuration.api_key, '')
|
48
|
+
|
49
|
+
http.set_debug_output($stdout)
|
50
|
+
|
51
|
+
response = http.request(request)
|
52
|
+
if response.code == '200'
|
53
|
+
JSON.parse(response.body)
|
54
|
+
else
|
55
|
+
raise FacturapiRubyError.new(JSON.parse(response.body))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'facturapi_ruby/configuration'
|
2
|
+
require 'facturapi_ruby/constants'
|
3
|
+
require 'facturapi_ruby/customers'
|
4
|
+
require 'facturapi_ruby/files'
|
5
|
+
require 'facturapi_ruby/invoices'
|
6
|
+
require 'facturapi_ruby/version'
|
7
|
+
|
8
|
+
module FacturapiRuby
|
9
|
+
class << self
|
10
|
+
# Configuration
|
11
|
+
attr_accessor :configuration
|
12
|
+
def configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facturapi_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diego Llamas Velasco
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Http client for https://facturapi.io
|
56
|
+
email:
|
57
|
+
- diegollams@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- facturapi_ruby.gemspec
|
74
|
+
- lib/facturapi_ruby.rb
|
75
|
+
- lib/facturapi_ruby/configuration.rb
|
76
|
+
- lib/facturapi_ruby/constants.rb
|
77
|
+
- lib/facturapi_ruby/customers.rb
|
78
|
+
- lib/facturapi_ruby/files.rb
|
79
|
+
- lib/facturapi_ruby/http_client.rb
|
80
|
+
- lib/facturapi_ruby/invoices.rb
|
81
|
+
- lib/facturapi_ruby/version.rb
|
82
|
+
homepage: https://github.com/diegollams/facturapi_ruby
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.7.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Crea Facturas Electrónicas válidas lo más fácil posible (CFDI) https://facturapi.io
|
106
|
+
test_files: []
|