bsale 0.0.5
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 +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +121 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bsale.gemspec +30 -0
- data/lib/bsale.rb +16 -0
- data/lib/bsale/base.rb +18 -0
- data/lib/bsale/client.rb +24 -0
- data/lib/bsale/config.rb +23 -0
- data/lib/bsale/detail.rb +32 -0
- data/lib/bsale/dinamic_attribute.rb +7 -0
- data/lib/bsale/document.rb +86 -0
- data/lib/bsale/errors.rb +10 -0
- data/lib/bsale/payment.rb +23 -0
- data/lib/bsale/reference.rb +22 -0
- data/lib/bsale/tax.rb +33 -0
- data/lib/bsale/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0abb8b3eb0a282364247d2c370f701c3a9b0ce44
|
4
|
+
data.tar.gz: f8bfa9e17fbe0bb968be975806ad5f81d6e66bc6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c3352b3a4acd8dcb8a10225a017e110467c259d99fea2dfb675b6d761009d3c1503efca3d72ed868cfa26155b605d9f8d3cbfe2c8b1d0d1e091eba80caae14a
|
7
|
+
data.tar.gz: 4862d8db04043f13e4a78497b0227292fc39c2b3f287a2de33870811a64c64e59c3519c53b572d712697cc68b65b6351f624189c023852824c16472ee29c5bdd
|
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 developer.jimenez@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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nelson Pato Jimenez
|
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,121 @@
|
|
1
|
+
# Bsale
|
2
|
+
|
3
|
+
Unofficial Ruby client for the [BSale API](https://github.com/gmontero/API-Bsale/wiki)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bsale'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bsale
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
### Configure with you app's credentials
|
23
|
+
Create a file into `config/initializer/bsale.rb` and put this:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Bsale.configure do |config|
|
27
|
+
config.access_token = ENV['BSALE_ACCESS_TOKEN']
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Example: Create a document
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# create document
|
35
|
+
|
36
|
+
tax = Bsale::Tax.new
|
37
|
+
payments = Bsale::Payment.new({ paymentTypeId: nil, amount: nil, recordDate: nil })
|
38
|
+
client = Bsale::Client.new({ code: "1-9", city: "Santiago",
|
39
|
+
company: "Freelance SpA", municipality: "Santiago Centro",
|
40
|
+
activity: "Asesoría informatica", address: "Moneda 975" })
|
41
|
+
taxes = tax.all["items"].map {|item| item["id"] }
|
42
|
+
|
43
|
+
details = Bsale::Detail.new({ netUnitValue: 53975, quantity: 1,
|
44
|
+
taxId: "#{taxes}", comment: "el nombre del producto que voy a vender", discount: 5 })
|
45
|
+
reference = Bsale::Reference.new({ number: 123, referenceDate: Time.now.to_i,
|
46
|
+
reason: "Factura electrónica 123", codeSii: 33 })
|
47
|
+
|
48
|
+
document = Bsale::Document.new({ codeSii: 33, emissionDate: Time.now.to_i,
|
49
|
+
expirationDate: Time.now.to_i, declareSii: 0,
|
50
|
+
client: client.to_h})
|
51
|
+
document.details << details.to_h
|
52
|
+
document.references << reference.to_h
|
53
|
+
|
54
|
+
request = document.create(document.to_h)
|
55
|
+
|
56
|
+
#request return with a Hash like this:
|
57
|
+
|
58
|
+
{"href"=>"https://api.bsale.cl/v1/documents/2014.json",
|
59
|
+
"id"=>2014,
|
60
|
+
"emissionDate"=>1507680000,
|
61
|
+
"expirationDate"=>1507680000,
|
62
|
+
"generationDate"=>1507748801,
|
63
|
+
"number"=>67,
|
64
|
+
"totalAmount"=>61018.0,
|
65
|
+
"netAmount"=>51276.0,
|
66
|
+
"taxAmount"=>9742.0,
|
67
|
+
"exemptAmount"=>0.0,
|
68
|
+
"exportTotalAmount"=>0.0,
|
69
|
+
"exportNetAmount"=>0.0,
|
70
|
+
"exportTaxAmount"=>0.0,
|
71
|
+
"exportExemptAmount"=>0.0,
|
72
|
+
"commissionRate"=>0.0,
|
73
|
+
"commissionNetAmount"=>0.0,
|
74
|
+
"commissionTaxAmount"=>0.0,
|
75
|
+
"commissionTotalAmount"=>0.0,
|
76
|
+
"percentageTaxWithheld"=>0.0,
|
77
|
+
"purchaseTaxAmount"=>0.0,
|
78
|
+
"purchaseTotalAmount"=>0.0,
|
79
|
+
"address"=>"Moneda 975",
|
80
|
+
"municipality"=>"Santiago Centro",
|
81
|
+
"city"=>"Santiago",
|
82
|
+
"urlTimbre"=>nil,
|
83
|
+
"ted"=>nil,
|
84
|
+
"urlPublicView"=>"http://app2.bsale.cl/view/9970/f3b890392f70?sfd=99",
|
85
|
+
"urlPdf"=>"http://app2.bsale.cl/view/9970/f3b890392f70.pdf?sfd=99",
|
86
|
+
"urlPublicViewOriginal"=>"http://app2.bsale.cl/view/9970/f3b890392f70",
|
87
|
+
"urlPdfOriginal"=>"http://app2.bsale.cl/view/9970/f3b890392f70.pdf",
|
88
|
+
"token"=>"f3b890392f70",
|
89
|
+
"state"=>0,
|
90
|
+
"urlXml"=>nil,
|
91
|
+
"informedSii"=>2,
|
92
|
+
"responseMsgSii"=>nil,
|
93
|
+
"document_type"=>{"href"=>"https://api.bsale.cl/v1/document_types/5.json", "id"=>"5"},
|
94
|
+
"client"=>{"href"=>"https://api.bsale.cl/v1/clients/110.json", "id"=>"110"},
|
95
|
+
"office"=>{"href"=>"https://api.bsale.cl/v1/offices/1.json", "id"=>"1"},
|
96
|
+
"user"=>{"href"=>"https://api.bsale.cl/v1/users/3.json", "id"=>"3"},
|
97
|
+
"coin"=>{"href"=>"https://api.bsale.cl/v1/coins/1.json", "id"=>"1"},
|
98
|
+
"references"=>{"href"=>"https://api.bsale.cl/v1/documents/2014/references.json"},
|
99
|
+
"document_taxes"=>{"href"=>"https://api.bsale.cl/v1/documents/2014/document_taxes.json"},
|
100
|
+
"details"=>{"href"=>"https://api.bsale.cl/v1/documents/2014/details.json"},
|
101
|
+
"sellers"=>{"href"=>"https://api.bsale.cl/v1/documents/2014/sellers.json"}}
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
1. Fork it
|
108
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
109
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
110
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
111
|
+
5. Create new Pull Request
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com//bsale. 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.
|
114
|
+
|
115
|
+
## License
|
116
|
+
|
117
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
118
|
+
|
119
|
+
## Code of Conduct
|
120
|
+
|
121
|
+
Everyone interacting in the Bsale project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nelyj/bsale/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bsale"
|
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
data/bsale.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "bsale/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bsale"
|
8
|
+
spec.version = Bsale::VERSION
|
9
|
+
spec.authors = ["Nelson Patricio Jimenez"]
|
10
|
+
spec.email = ["developer.jimenez@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby Client Library for Bsale API}
|
13
|
+
spec.description = %q{Ruby Client Library for Bsale API}
|
14
|
+
spec.homepage = "https://github.com/gmontero/API-Bsale/"
|
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_dependency "pry-byebug"
|
25
|
+
spec.add_dependency "faraday", '~> 0.9'
|
26
|
+
spec.add_dependency "uri_template", '~> 0.7'
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
data/lib/bsale.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "json"
|
2
|
+
require "faraday"
|
3
|
+
require "pry"
|
4
|
+
require "bsale/config"
|
5
|
+
require "bsale/version"
|
6
|
+
require "bsale/base"
|
7
|
+
require "bsale/client"
|
8
|
+
require "bsale/document"
|
9
|
+
require "bsale/detail"
|
10
|
+
require "bsale/payment"
|
11
|
+
require "bsale/reference"
|
12
|
+
require "bsale/tax"
|
13
|
+
require "bsale/errors"
|
14
|
+
|
15
|
+
module Bsale
|
16
|
+
end
|
data/lib/bsale/base.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bsale
|
2
|
+
class Base
|
3
|
+
BASE_URL = "https://api.bsale.cl/v".freeze
|
4
|
+
|
5
|
+
def to_h(empty = true)
|
6
|
+
hash = self.instance_variables.each_with_object({}) { |v, h| h[v.to_s.delete("@")] = self.instance_variable_get(v) }
|
7
|
+
hash.delete("connection")
|
8
|
+
hash.delete_if {|k,v| v.nil? }
|
9
|
+
end
|
10
|
+
|
11
|
+
def raise_if_invalid!(resp)
|
12
|
+
raise ServerError, "Server Error" if resp.status > 499
|
13
|
+
raise NotFoundError, "Not Found" if resp.status == 404
|
14
|
+
raise UnauthorizedError, "Unauthorized request" if resp.status == 401
|
15
|
+
raise AccessForbiddenError, "Access Forbidden" if resp.status == 403
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/bsale/client.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bsale
|
2
|
+
#code: Rut del cliente (String).
|
3
|
+
#city: Ciudad del cliente (String).
|
4
|
+
#company: Razón social del cliente (String).
|
5
|
+
#municipality: Comuna del cliente (String).
|
6
|
+
#activity: Giro del cliente (String).
|
7
|
+
#address: Dirección del cliente (String).
|
8
|
+
class Client < Base
|
9
|
+
def initialize(opts = {})
|
10
|
+
set_values(attrs.merge(opts))
|
11
|
+
end
|
12
|
+
|
13
|
+
def attrs
|
14
|
+
{ code: "", city: "", company: "", municipality: "", activity: "", address: "" }
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_values(opts = {})
|
18
|
+
opts.each do |k,v|
|
19
|
+
singleton_class.send(:attr_accessor, k)
|
20
|
+
instance_variable_set("@#{k}", v)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bsale/config.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bsale
|
2
|
+
class Config
|
3
|
+
attr_accessor :access_token, :content_type, :version, :extension, :headers
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@extension = ".json".freeze
|
7
|
+
@content_type ||= 'application/json'.freeze
|
8
|
+
@version ||= '1'.freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def headers
|
12
|
+
{ 'access_token' => @access_token, 'Content-Type' => @content_type }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.config
|
17
|
+
@config ||= Config.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure(&block)
|
21
|
+
yield(config) if block_given?
|
22
|
+
end
|
23
|
+
end
|
data/lib/bsale/detail.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Bsale
|
2
|
+
#variantId: Id de la variante que indicara cual variante es la que se esta vendiendo de la variante (Integer).
|
3
|
+
#code: De forma alternativa al Id, se puede utilizar el SKU de la variante (String).
|
4
|
+
#barCode: De forma alternativa al Id, se puede utilizar el codigo de barras de la variante (String).
|
5
|
+
#netUnitValue: Valor unitario neto de la variante, este valor es sin impuestos (Float).
|
6
|
+
#quantity: Cantidad de la variante que se esta vendiendo (Integer).
|
7
|
+
#taxId: Arreglo de identificadores de los impuestos a utilizar, estos tienen que ir dentro de "[]" (String).
|
8
|
+
#comment: Descripción breve de la variante (String).
|
9
|
+
#discount: Porcentaje del descuento si se desea aplicar uno. (Float).
|
10
|
+
#
|
11
|
+
#Es muy importante que se envíen los impuestos por cada detalle, de lo contrario el documento saldrá exento.
|
12
|
+
class Detail < Base
|
13
|
+
def initialize(opts = {}, warehouse = false)
|
14
|
+
set_values(attrs(warehouse).merge(opts))
|
15
|
+
end
|
16
|
+
|
17
|
+
def attrs(option)
|
18
|
+
if option
|
19
|
+
{ variantId: 0, netUnitValue: 0, quantity: 0, taxId: "", comment: "", discount: 0 }
|
20
|
+
else
|
21
|
+
{ netUnitValue: 0, quantity: 1, taxId: "", comment: "", discount: 0 }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_values(opts = {})
|
26
|
+
opts.each do |k,v|
|
27
|
+
singleton_class.send(:attr_accessor, k)
|
28
|
+
instance_variable_set("@#{k}", v)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Bsale
|
2
|
+
# documentTypeId: Id del tipo de documento que indicara si es factura, boleta, nota de venta etc. (Integer).
|
3
|
+
# officeId: Id de la sucursal donde se emite el documento, si no es especificada el documento quedara asignado a la sucursal por defecto del sistema (Integer).
|
4
|
+
# priceListId: Id de la lista de precio utilizada por el documento, si no es especificada se utilizara la lista de precio por defecto de la sucursal (Integer).
|
5
|
+
# emissionDate: Fecha de emisión del documento, se envía en formato GMT (Integer).
|
6
|
+
# expirationDate: Fecha vencimiento del documento, se envía en formato GMT (Integer).
|
7
|
+
# declareSii: Si se desea declarar el documento al Servicio de impuestos internos se envía 1, en caso contrario un 0 (Boolean).
|
8
|
+
# codeSii(opcional): Opcionalmente puedes utilizar el parámetro codeSii en vez de documentTypeId si conoces el código tributario del documento.
|
9
|
+
# client: Bsale::Client object.to_hash
|
10
|
+
# details: Bsale::Detail object.to_hash
|
11
|
+
# payments: Bsale::Payment object.to_hash
|
12
|
+
# references: Bsale::Reference object.to_hash
|
13
|
+
# dynamicAttributes: Bsale::DinamicAttributes object.to_hash
|
14
|
+
class Document < Base
|
15
|
+
attr_accessor :limit, :offset, :version
|
16
|
+
|
17
|
+
def initialize(opts = {})
|
18
|
+
set_values(attrs.merge(opts))
|
19
|
+
@connection = Faraday.new("#{BASE_URL}#{Bsale.config.version}/")
|
20
|
+
@connection.headers = Bsale.config.headers
|
21
|
+
end
|
22
|
+
|
23
|
+
def all(opts = {})
|
24
|
+
response = @connection.get "documents#{Bsale.config.extension}"
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def summary(opts = {})
|
29
|
+
response = @connection.get "documents/summary#{Bsale.config.extension}"
|
30
|
+
JSON.parse(response.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def find(opts = {})
|
34
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
35
|
+
response = @connection.get "documents/#{opts[:id]}#{Bsale.config.extension}"
|
36
|
+
JSON.parse(response.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
def by_details(opts = {})
|
40
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
41
|
+
response = @connection.get "documents/#{opts[:id]}/details#{Bsale.config.extension}"
|
42
|
+
JSON.parse(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def by_references(opts = {})
|
46
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
47
|
+
response = @connection.get "documents/#{opts[:id]}/references#{Bsale.config.extension}"
|
48
|
+
JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def taxes(opts = {})
|
52
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
53
|
+
response = @connection.get "documents/#{opts[:id]}/document_taxes#{Bsale.config.extension}"
|
54
|
+
JSON.parse(response.body)
|
55
|
+
end
|
56
|
+
|
57
|
+
def sellers(opts = {})
|
58
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
59
|
+
response = @connection.get "documents/#{opts[:id]}/sellers#{Bsale.config.extension}"
|
60
|
+
JSON.parse(response.body)
|
61
|
+
end
|
62
|
+
|
63
|
+
def count
|
64
|
+
response = @connection.get "documents/count#{Bsale.config.extension}"
|
65
|
+
JSON.parse(response.body)
|
66
|
+
end
|
67
|
+
|
68
|
+
def create(opts = {})
|
69
|
+
response = @connection.post "documents#{Bsale.config.extension}", opts.to_json
|
70
|
+
JSON.parse(response.body)
|
71
|
+
end
|
72
|
+
|
73
|
+
def attrs
|
74
|
+
{ documentTypeId: nil, officeId: nil, emissionDate: nil, expirationDate: nil,
|
75
|
+
declareSii: nil, priceListId: nil, client: nil, details: [], payments: [],
|
76
|
+
references: [], dynamicAttributes: nil }
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_values(opts = {})
|
80
|
+
opts.each do |k,v|
|
81
|
+
singleton_class.send(:attr_accessor, k)
|
82
|
+
instance_variable_set("@#{k}", v)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/bsale/errors.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Bsale
|
2
|
+
class TransportError < StandardError; end
|
3
|
+
class ServerError < TransportError; end
|
4
|
+
class NotFoundError < ServerError; end
|
5
|
+
class AuthorizationError < ServerError; end
|
6
|
+
class UnauthorizedError < AuthorizationError; end
|
7
|
+
class AccessForbiddenError < AuthorizationError; end
|
8
|
+
class ClientError < TransportError; end
|
9
|
+
class InvalidURLError < ClientError; end
|
10
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bsale
|
2
|
+
# paymentTypeId: Id de la forma de pago utilizada en el pago del documento (Integer).
|
3
|
+
# amount: monto del pago del documento (Integer).
|
4
|
+
# recordDate: Fecha en la cual se realizo el pago del documento, se envía en formato GMT (Integer).
|
5
|
+
#
|
6
|
+
# De lo contrario Bsale detectara la forma de pago por defecto y asignara el monto total del documento a esa forma de pago.
|
7
|
+
class Payment < Base
|
8
|
+
def initialize(opts = {})
|
9
|
+
set_values(attrs.merge(opts))
|
10
|
+
end
|
11
|
+
|
12
|
+
def attrs
|
13
|
+
{ paymentTypeId: 0, amount: 0, recordDate: 0 }
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_values(opts = {})
|
17
|
+
opts.each do |k,v|
|
18
|
+
singleton_class.send(:attr_accessor, k)
|
19
|
+
instance_variable_set("@#{k}", v)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Bsale
|
2
|
+
# number: Folio del documento de referencia (String).
|
3
|
+
# referenceDate: Fecha del documento de referencia (Integer).
|
4
|
+
# reason: Razón del documento (String).
|
5
|
+
# codeSii: Código tributario del documento de referencia (Integer).
|
6
|
+
class Reference < Base
|
7
|
+
def initialize(opts = {})
|
8
|
+
set_values(attrs.merge(opts))
|
9
|
+
end
|
10
|
+
|
11
|
+
def attrs
|
12
|
+
{ number: "", referenceDate: 0, reason: "", codeSii: 0 }
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_values(opts = {})
|
16
|
+
opts.each do |k,v|
|
17
|
+
singleton_class.send(:attr_accessor, k)
|
18
|
+
instance_variable_set("@#{k}", v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/bsale/tax.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bsale
|
2
|
+
class Tax < Base
|
3
|
+
attr_accessor :limit, :offset, :version
|
4
|
+
def initialize(opts = {})
|
5
|
+
set_values(attrs.merge(opts))
|
6
|
+
@connection = Faraday.new("#{BASE_URL}#{Bsale.config.version}/")
|
7
|
+
@connection.headers = Bsale.config.headers
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(opts = {})
|
11
|
+
raise "You must need to pass an ID" if opts[:id].nil?
|
12
|
+
response = @connection.get "taxes/#{opts[:id]}#{Bsale.config.extension}"
|
13
|
+
JSON.parse(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def all(opts = {})
|
17
|
+
response = @connection.get "taxes#{Bsale.config.extension}"
|
18
|
+
JSON.parse(response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def attrs
|
22
|
+
{ id: nil, name: nil, percentage: nil, forAllProducts: nil,
|
23
|
+
ledgerAccount: nil, code: nil, state: nil }
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_values(opts = {})
|
27
|
+
opts.each do |k,v|
|
28
|
+
singleton_class.send(:attr_accessor, k)
|
29
|
+
instance_variable_set("@#{k}", v)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bsale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nelson Patricio Jimenez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry-byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uri_template
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.15'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Ruby Client Library for Bsale API
|
98
|
+
email:
|
99
|
+
- developer.jimenez@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- bsale.gemspec
|
115
|
+
- lib/bsale.rb
|
116
|
+
- lib/bsale/base.rb
|
117
|
+
- lib/bsale/client.rb
|
118
|
+
- lib/bsale/config.rb
|
119
|
+
- lib/bsale/detail.rb
|
120
|
+
- lib/bsale/dinamic_attribute.rb
|
121
|
+
- lib/bsale/document.rb
|
122
|
+
- lib/bsale/errors.rb
|
123
|
+
- lib/bsale/payment.rb
|
124
|
+
- lib/bsale/reference.rb
|
125
|
+
- lib/bsale/tax.rb
|
126
|
+
- lib/bsale/version.rb
|
127
|
+
homepage: https://github.com/gmontero/API-Bsale/
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.4.8
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Ruby Client Library for Bsale API
|
151
|
+
test_files: []
|