bling-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35eb4fc8d36b57254cc475b118ad6fb1def04d73
4
+ data.tar.gz: 6379367b675a18de7c5a0333ec19f2ca384972e0
5
+ SHA512:
6
+ metadata.gz: 26abf36ce543e12bb4cf59aa89947624eee709ee530b568ffa08303329ca2b32d6f37db7866554ad0234c2b42b928801c9c0e2ba94fc72374e5455b154aa1252
7
+ data.tar.gz: 1a39b3780d78b06b235892ec93cb9e7045455a941dc1f8cebbd1987e05441c92cc35f6c581c00d16e8fc1dc4dce9417cc7401326866d224462eafa9ececb6a58
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bling (0.0.1)
5
+ httparty (~> 0.13.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionpack (4.1.8)
11
+ actionview (= 4.1.8)
12
+ activesupport (= 4.1.8)
13
+ rack (~> 1.5.2)
14
+ rack-test (~> 0.6.2)
15
+ actionview (4.1.8)
16
+ activesupport (= 4.1.8)
17
+ builder (~> 3.1)
18
+ erubis (~> 2.7.0)
19
+ activesupport (4.1.8)
20
+ i18n (~> 0.6, >= 0.6.9)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 1.1)
25
+ builder (3.2.2)
26
+ diff-lcs (1.2.5)
27
+ erubis (2.7.0)
28
+ httparty (0.13.3)
29
+ json (~> 1.8)
30
+ multi_xml (>= 0.5.2)
31
+ i18n (0.6.11)
32
+ json (1.8.1)
33
+ minitest (5.5.0)
34
+ multi_xml (0.5.5)
35
+ rack (1.5.2)
36
+ rack-test (0.6.2)
37
+ rack (>= 1.0)
38
+ railties (4.1.8)
39
+ actionpack (= 4.1.8)
40
+ activesupport (= 4.1.8)
41
+ rake (>= 0.8.7)
42
+ thor (>= 0.18.1, < 2.0)
43
+ rake (10.3.2)
44
+ rspec-core (3.1.7)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-expectations (3.1.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-mocks (3.1.3)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-rails (3.1.0)
52
+ actionpack (>= 3.0)
53
+ activesupport (>= 3.0)
54
+ railties (>= 3.0)
55
+ rspec-core (~> 3.1.0)
56
+ rspec-expectations (~> 3.1.0)
57
+ rspec-mocks (~> 3.1.0)
58
+ rspec-support (~> 3.1.0)
59
+ rspec-support (3.1.2)
60
+ thor (0.19.1)
61
+ thread_safe (0.3.4)
62
+ tzinfo (1.2.2)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bling!
70
+ rake (~> 10.3.2)
71
+ rspec-rails (~> 3.1.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Luciano Sousa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ bling-ruby
2
+ ==========
3
+
4
+ Configuração
5
+ ============
6
+
7
+ Crie um arquivo em: config/initializers/bling.rb com o seguinte conteúdo:
8
+
9
+ Bling.setup do |config|
10
+ config.apikey = 'sua-chave-aqui'
11
+ end
12
+
13
+
14
+ Contribuições
15
+ =============
16
+
17
+ Fork, crie um pull request e receba nosso muito obrigado pela ajuda!
18
+
19
+ Licença
20
+ =======
21
+
22
+ MIT. See LICENSE.txt for further details.
23
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bling.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bling-ruby'
3
+ s.version = '0.0.1'
4
+ s.date = '2014-12-16'
5
+ s.description = "The smartest integration with Bling system"
6
+ s.summary = "The official Bling library"
7
+ s.authors = ["Luciano Sousa"]
8
+ s.email = ['ls@lucianosousa.net']
9
+ s.homepage = 'https://github.com/organisys/bling-ruby'
10
+ s.license = 'MIT'
11
+
12
+ s.files = `git ls-files`.split($/)
13
+ s.require_paths = ["lib"]
14
+
15
+ s.add_dependency "httparty", '~> 0.13.3'
16
+ s.add_development_dependency "rake", '~> 10.3.2'
17
+ s.add_development_dependency "rspec-rails", '~> 3.1.0'
18
+ end
data/lib/bling/base.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "rubygems"
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+ require 'active_support/deprecation'
4
+
5
+ #
6
+ # Base: Configurações gerais e métodos que são utilizados em mais de uma classe
7
+
8
+ module Bling
9
+ extend self
10
+
11
+ # URL padrão para requisições no servidor Bling
12
+ API_URL = "https://bling.com.br/Api/v2"
13
+
14
+ # Variável que contém API Key
15
+ mattr_accessor :apikey
16
+
17
+ # Carrega arquivo de inicialização com configurações gerais
18
+ def self.setup
19
+ yield self
20
+ end
21
+
22
+ def show_data(param)
23
+ if param["erros"]
24
+ if param["erros"]["cod"] == 14
25
+ []
26
+ end
27
+ else
28
+ param
29
+ end
30
+ end
31
+
32
+ class MissingApiKeyError < StandardError; end
33
+ end
34
+
35
+ class Object
36
+ def blank?
37
+ respond_to?(:empty?) ? empty? : !self
38
+ end
39
+ end
40
+
@@ -0,0 +1,105 @@
1
+ require 'httparty'
2
+
3
+ #
4
+ # Nota Fiscal: Mantém notas fiscais
5
+
6
+ module Bling
7
+ class NotaFiscal
8
+ include HTTParty
9
+
10
+ base_uri "#{API_URL}"
11
+
12
+ class << self
13
+ # Busca por uma nota fiscal através de numero e número de série
14
+ #
15
+ # Parâmetros:
16
+ #
17
+ # numero - (opcional)
18
+ #
19
+ # serie - (opcional)
20
+
21
+ def nota_fiscal(attributes = {})
22
+ numero = attributes[:numero].to_s
23
+ serie = attributes[:serie].to_s
24
+
25
+ full_data = self.send(:get, "/notafiscal/#{numero}/#{serie}/json", { query: { apikey: Bling.apikey } } )
26
+ full_data["retorno"]["notasfiscais"]
27
+ end
28
+
29
+ # Listagem de notas fiscais
30
+ #
31
+ # Parâmetros:
32
+ #
33
+ # page - parâmetro para paginação (opcional)
34
+ #
35
+ # data_emissao - filtro para data de emissão da nota fiscal (opcional)
36
+ #
37
+ # data_emissao_from - filtro para data de emissão da nota fiscal (opcional)
38
+ #
39
+ # data_emissao_to - para data de emissão da nota fiscal (deve ser utilizado sempre com o atributo 'data_emissao_from') (opcional)
40
+ #
41
+ # situacao - veja em [http://bling.com.br/manuais.bling.php?p=manuais.api2#getNotasFiscais] as possíveis situações (opcional)
42
+
43
+ def notas_fiscais(attributes = {})
44
+ page_number = attributes[:page]
45
+ page = "/page=#{page_number}" if page_number
46
+
47
+ filters = set_filters(attributes)
48
+
49
+ full_data = self.send(:get, "/notasfiscais#{page}/json", { query: { apikey: Bling.apikey, filters: filters } } )
50
+
51
+ show_data(full_data["retorno"])
52
+ end
53
+
54
+ # Salva uma nota fiscal
55
+ #
56
+ # Parâmetros:
57
+ #
58
+ # xml - Path para XML
59
+
60
+ def salvar_nota_fiscal(attributes = {})
61
+ xml = attributes[:xml]
62
+
63
+ full_data = self.send(:post, '/notafiscal/json', { query: { apikey: Bling.apikey, xml: xml } } )
64
+ full_data["retorno"]["notasfiscais"]
65
+ end
66
+
67
+ # Salva e retorna os dados de uma nota fiscal
68
+ #
69
+ # Parâmetros:
70
+ #
71
+ # number - número da nota fiscal
72
+ #
73
+ # serie - número de série da nota fiscal
74
+ #
75
+ # send_mail - true/false (opcional)
76
+
77
+ def salvar_consultar_nota_fiscal(attributes = {})
78
+ number = attributes[:number].to_s
79
+ serie = attributes[:serie].to_s
80
+ send_email = attributes[:send_email]
81
+
82
+ full_data = self.send(:post, '/notafiscal/json', { query: { apikey: Bling.apikey, number: number, serie: serie, sendEmail: send_email } } )
83
+ full_data["retorno"]["notasfiscais"]
84
+ end
85
+
86
+ private
87
+
88
+ def set_filters attributes
89
+ data_emissao_from = attributes[:data_emissao_from]
90
+ data_emissao_to = attributes[:data_emissao_to]
91
+ situacao = attributes[:situacao]
92
+ filters = ""
93
+
94
+ if data_emissao_from && data_emissao_to
95
+ filters << "dataEmissao[#{data_emissao_from} TO #{data_emissao_to}]"
96
+ end
97
+
98
+ filters << ";" if filters.match(/dataEmissao/) && situacao
99
+ filters << "situacao[#{situacao}]" if situacao
100
+ filters
101
+ end
102
+ end
103
+ end
104
+ end
105
+
@@ -0,0 +1,29 @@
1
+ require 'httparty'
2
+
3
+ #
4
+ # Nota Serviço: Mantém notas de serviço
5
+
6
+ module Bling
7
+ class NotaServico
8
+ include HTTParty
9
+
10
+ base_uri "#{API_URL}"
11
+
12
+ class << self
13
+
14
+ # Salva uma nota de serviço
15
+ #
16
+ # Parâmetros:
17
+ #
18
+ # xml - Path para XML
19
+
20
+ def salvar_nota_servico(attributes = {})
21
+ xml = attributes[:xml]
22
+
23
+ full_data = self.send(:post, '/notaservico/json', { query: { apikey: Bling.apikey, xml: xml } } )
24
+ full_data["retorno"]["notasservico"]
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,59 @@
1
+ require 'httparty'
2
+
3
+ #
4
+ # Pedido: Mantém pedidos
5
+
6
+ module Bling
7
+ class Pedido
8
+ include HTTParty
9
+
10
+ base_uri "#{API_URL}"
11
+
12
+ class << self
13
+
14
+ # Busca por um pedido
15
+ #
16
+ # Parâmetros:
17
+ #
18
+ # xml - Path para XML
19
+
20
+ def pedido(attributes = {})
21
+ numero = attributes[:numero].to_s
22
+
23
+ full_data = self.send(:get, "/pedido/#{numero}/json", { query: { apikey: Bling.apikey } } )
24
+ full_data["retorno"]["pedidos"]
25
+ end
26
+
27
+ # Lista pedidos do sistema
28
+ #
29
+ # Parâmetros:
30
+ #
31
+ # page - parâmetro para paginação (opcional)
32
+
33
+ def pedidos(attributes = {})
34
+ page_number = attributes[:page]
35
+ page = "/page=#{page_number}" if page_number
36
+
37
+ full_data = self.send(:get, "/pedidos#{page}/json", { query: { apikey: Bling.apikey } } )
38
+ full_data["retorno"]["pedidos"]
39
+ end
40
+
41
+ # Salva um pedido
42
+ #
43
+ # Parâmetros:
44
+ #
45
+ # xml - Path para XML
46
+ #
47
+ # gera_nfe - true/false (opcional)
48
+
49
+ def salvar_pedido(attributes = {})
50
+ xml = attributes[:xml]
51
+ gerar_nfe = attributes[:gerar_nfe].to_s
52
+
53
+ full_data = self.send(:post, "/pedido/json", { query: { apikey: Bling.apikey, xml: xml, gerarnfe: gerar_nfe } } )
54
+ full_data["retorno"]["pedidos"]
55
+ end
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,85 @@
1
+ require 'httparty'
2
+
3
+ #
4
+ # Produto: Mantém produtos
5
+
6
+ module Bling
7
+ class Produto
8
+ include HTTParty
9
+
10
+ base_uri "#{API_URL}"
11
+
12
+ class << self
13
+
14
+ #
15
+ # Atualiza um produto
16
+ #
17
+ # Parâmetros:
18
+ #
19
+ # xml - Path para XML
20
+
21
+ def atualiza_produto(attributes = {})
22
+ xml = attributes[:xml]
23
+
24
+ full_data = self.send(:post, '/produto/json', { query: { apikey: Bling.apikey, xml: xml } } )
25
+ full_data["retorno"]["produtos"]
26
+ end
27
+
28
+ # Deleta um produto
29
+ #
30
+ # Parâmetros:
31
+ #
32
+ # codigo - código do produto
33
+
34
+ def deletar_produto(attributes = {})
35
+ codigo = attributes[:codigo].to_s
36
+
37
+ full_data = self.send(:delete, "/produto/#{codigo}", { body: { apikey: Bling.apikey } } )
38
+ full_data["retorno"]["produtos"]["produto"]
39
+ end
40
+
41
+ # Busca por um produto
42
+ #
43
+ # Parâmetros:
44
+ #
45
+ # codigo - código do produto
46
+
47
+ def produto(attributes = {})
48
+ codigo = attributes[:codigo].to_s
49
+
50
+ full_data = self.send(:get, "/produto/#{codigo}/json", { query: { apikey: Bling.apikey } } )
51
+ full_data["retorno"]["produtos"]
52
+ end
53
+
54
+ # Listagem de produtos
55
+ #
56
+ # Parâmetros
57
+ #
58
+ # estoque - parâmetro para incluir estoque atual no retorno (opcional)
59
+ #
60
+ # page - parâmetro para paginação (opcional)
61
+
62
+ def produtos(attributes = {})
63
+ page_number = attributes[:page]
64
+ page = "/page=#{page_number}" if page_number
65
+
66
+ full_data = self.send(:get, "/produtos#{page}/json", { query: { apikey: Bling.apikey } } )
67
+ full_data["retorno"]["produtos"]
68
+ end
69
+
70
+ # Salva um produto
71
+ #
72
+ # Parâmetros:
73
+ #
74
+ # xml - Path para XML
75
+
76
+ def salvar_produto(attributes = {})
77
+ xml = attributes[:xml]
78
+
79
+ full_data = self.send(:post, '/produto/json', { query: { apikey: Bling.apikey, xml: xml } } )
80
+ full_data["retorno"]["produtos"]
81
+ end
82
+ end
83
+ end
84
+ end
85
+
data/lib/bling.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'bling/base'
2
+ require 'bling/nota_fiscal'
3
+ require 'bling/nota_servico'
4
+ require 'bling/pedido'
5
+ require 'bling/produto'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bling-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luciano Sousa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.3
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.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.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.1.0
55
+ description: The smartest integration with Bling system
56
+ email:
57
+ - ls@lucianosousa.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - VERSION
68
+ - bling.gemspec
69
+ - lib/bling.rb
70
+ - lib/bling/base.rb
71
+ - lib/bling/nota_fiscal.rb
72
+ - lib/bling/nota_servico.rb
73
+ - lib/bling/pedido.rb
74
+ - lib/bling/produto.rb
75
+ homepage: https://github.com/organisys/bling-ruby
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: The official Bling library
99
+ test_files: []