jamef-api 0.5.0

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
+ SHA256:
3
+ metadata.gz: a6a5bc6535af08ff3f56688f241fd357c9073aa0841b1fd59e2531863aaab68e
4
+ data.tar.gz: c13f9cc33f5de8d3b8f88a8192624dc3dd0ff9b1f743abb69f3cf33f4f659ab7
5
+ SHA512:
6
+ metadata.gz: a80c2f89e7184841a279e85680f8335ae70baf4ae9ccec9b588fb5a207eb271d2253931e1c40efe363c524ca9a122d4432186b3260f335a2f2bf33c1572f2f2d
7
+ data.tar.gz: 2782cd8e5f46a94b321cd1e8d7e9e4dc5c5bd07fed4c669adb0d250446f99f360f083d73d02edc12f084cd7b7fdb857bf4018195581ef314c9253f942cfc61ec
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jamef.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jamef-api (0.5.0)
5
+ activemodel
6
+ activesupport
7
+ rest-client
8
+ savon (~> 2.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (5.2.0)
14
+ activesupport (= 5.2.0)
15
+ activesupport (5.2.0)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ akami (1.3.1)
21
+ gyoku (>= 0.4.0)
22
+ nokogiri
23
+ builder (3.2.3)
24
+ coderay (1.1.2)
25
+ concurrent-ruby (1.0.5)
26
+ diff-lcs (1.3)
27
+ domain_name (0.5.20180417)
28
+ unf (>= 0.0.5, < 1.0.0)
29
+ ffi (1.9.23)
30
+ formatador (0.2.5)
31
+ guard (2.14.2)
32
+ formatador (>= 0.2.4)
33
+ listen (>= 2.7, < 4.0)
34
+ lumberjack (>= 1.0.12, < 2.0)
35
+ nenv (~> 0.1)
36
+ notiffany (~> 0.0)
37
+ pry (>= 0.9.12)
38
+ shellany (~> 0.0)
39
+ thor (>= 0.18.1)
40
+ guard-compat (1.2.1)
41
+ guard-rspec (4.7.3)
42
+ guard (~> 2.1)
43
+ guard-compat (~> 1.1)
44
+ rspec (>= 2.99.0, < 4.0)
45
+ gyoku (1.3.1)
46
+ builder (>= 2.1.2)
47
+ http-cookie (1.0.3)
48
+ domain_name (~> 0.5)
49
+ httpi (2.4.3)
50
+ rack
51
+ socksify
52
+ i18n (1.0.1)
53
+ concurrent-ruby (~> 1.0)
54
+ listen (3.1.5)
55
+ rb-fsevent (~> 0.9, >= 0.9.4)
56
+ rb-inotify (~> 0.9, >= 0.9.7)
57
+ ruby_dep (~> 1.2)
58
+ lumberjack (1.0.13)
59
+ method_source (0.9.0)
60
+ mime-types (3.1)
61
+ mime-types-data (~> 3.2015)
62
+ mime-types-data (3.2016.0521)
63
+ mini_portile2 (2.3.0)
64
+ minitest (5.11.3)
65
+ nenv (0.3.0)
66
+ netrc (0.11.0)
67
+ nokogiri (1.8.2)
68
+ mini_portile2 (~> 2.3.0)
69
+ nori (2.6.0)
70
+ notiffany (0.1.1)
71
+ nenv (~> 0.1)
72
+ shellany (~> 0.0)
73
+ pry (0.11.3)
74
+ coderay (~> 1.1.0)
75
+ method_source (~> 0.9.0)
76
+ rack (2.0.4)
77
+ rake (10.5.0)
78
+ rb-fsevent (0.10.3)
79
+ rb-inotify (0.9.10)
80
+ ffi (>= 0.5.0, < 2)
81
+ rest-client (2.0.2)
82
+ http-cookie (>= 1.0.2, < 2.0)
83
+ mime-types (>= 1.16, < 4.0)
84
+ netrc (~> 0.8)
85
+ rspec (3.7.0)
86
+ rspec-core (~> 3.7.0)
87
+ rspec-expectations (~> 3.7.0)
88
+ rspec-mocks (~> 3.7.0)
89
+ rspec-core (3.7.1)
90
+ rspec-support (~> 3.7.0)
91
+ rspec-expectations (3.7.0)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.7.0)
94
+ rspec-mocks (3.7.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.7.0)
97
+ rspec-support (3.7.1)
98
+ ruby_dep (1.5.0)
99
+ savon (2.12.0)
100
+ akami (~> 1.2)
101
+ builder (>= 2.1.2)
102
+ gyoku (~> 1.2)
103
+ httpi (~> 2.3)
104
+ nokogiri (>= 1.8.1)
105
+ nori (~> 2.4)
106
+ wasabi (~> 3.4)
107
+ shellany (0.0.1)
108
+ socksify (1.7.1)
109
+ thor (0.20.0)
110
+ thread_safe (0.3.6)
111
+ tzinfo (1.2.5)
112
+ thread_safe (~> 0.1)
113
+ unf (0.1.4)
114
+ unf_ext
115
+ unf_ext (0.0.7.5)
116
+ wasabi (3.5.0)
117
+ httpi (~> 2.0)
118
+ nokogiri (>= 1.4.2)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bundler (~> 1.16)
125
+ guard-rspec
126
+ jamef-api!
127
+ pry
128
+ rake (~> 10.0)
129
+ rspec (~> 3.0)
130
+
131
+ BUNDLED WITH
132
+ 1.16.1
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Agilso
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,251 @@
1
+ # Jamef API
2
+
3
+ Olá. Essa gem é um Ruby wrapper da API SOAP da *Jamef.com.br*. Use-a em qualquer projeto Ruby/Rails.
4
+
5
+ Você poderá facilmente
6
+
7
+ * **Consultar** frete e prazo de entrega
8
+ * ~~Rastrear encomendas despachadas~~ (#TO DO)
9
+
10
+ ## 1. Consulta de Frete e Prazo (Rating)
11
+
12
+ Após a instalação da gem, realizar uma consulta de frete é bastante simples. São apenas 4 passos, veja uma resumo do processo:
13
+
14
+ 1. Defina o **remetente** com `Jamef::Sender`
15
+ 2. Defina o **destinatário** com `Jamef::Receiver`
16
+ 3. Defina **a mercadoria que vai ser enviada** com `Jamef::Package`
17
+ 4. Realize a **consulta** com `Jamef.rate` ou `Jamef.complete_rate`
18
+
19
+
20
+
21
+ ### 1.1 - Remetente
22
+
23
+ Inicialize um objeto `Jamef::Sender` com as informações da sua empresa.
24
+
25
+ ```ruby
26
+ my_company = Jamef::Sender.new({
27
+ document: 'xxx', # cnpj/cpf
28
+ city: 'Jundiaí', # sua cidade
29
+ state: 'SP', # seu estado
30
+ jamef_branch: :campinas # sua filial da jamef
31
+ })
32
+ ```
33
+
34
+ **Importante:**
35
+
36
+ * `jamef_branch` é sempre o nome da cidade da filial da Jamef associada à sua conta. Veja a tabela no final do documento.
37
+
38
+ ### 1.2 - Destinatário
39
+
40
+ Crie um destinatário com o `Jamef::Receiver`.
41
+
42
+ ```ruby
43
+ receiver = Jamef::Receiver.new({
44
+ zip: 'CEP AQUI', # obrigatório: CEP
45
+ document: 'CNPJ AQUI', # opcional: cpf/cnpj do destinatário
46
+ contrib: true # opcional: Dest. é contribuinte?
47
+ })
48
+ ```
49
+
50
+ ### 1.3 - Mercadoria
51
+
52
+ Faça um pacote informando o volume final cubado (**m³**) e também seu peso (**kg**) com o `Jamef::Package`.
53
+
54
+ ```ruby
55
+ package = Jamef::Package.new({
56
+ weight: 5, # kg - peso da encomenda
57
+ package_price: 1000, # R$ - valor da encomenda
58
+ volume: 2, # m³ - vol. total cubado
59
+ type: :nf # opcional (leia abaixo)
60
+ })
61
+ ```
62
+
63
+ Este último parâmetro `type` está relacionado com o tipo de produto que será transportado.
64
+
65
+ Você pode omitir `type: :nf` que é o valor padrão. O tipo `:nf` diz à Jamef para inferir o tipo de produto a partir da nota fiscal. Veja a tabela no final do documento para preencher o campo `type` adequadamente.
66
+
67
+ ### 1.4 - Consulta
68
+
69
+ Há dois métodos que você pode usar para fazer a consulta: `Jamef.complete_rate` e `Jamef.rate`. Escolha a maneira mais adequada.
70
+
71
+ #### 1.4.1 Consulta com retorno simplificado
72
+
73
+ Você pode realizar uma consulta simples com o `Jamef::rate`
74
+
75
+ Em `shipping_in`, informe a data/horário (datetime) de coleta da encomenda.
76
+
77
+ ```ruby
78
+ Jamef.rate({
79
+ sender: my_company,
80
+ receiver: receiver,
81
+ package: package,
82
+
83
+ # Tipo de transporte: Aéreo (:air) ou rodoviário (:road)
84
+ service_type: :road,
85
+
86
+ # data/hora de coleta (Datetime obj.)
87
+ shipping_in: 3.days.from_now.midday
88
+
89
+ })
90
+ ```
91
+
92
+ O **retorno** é uma hash como esta abaixo:
93
+
94
+ ```ruby
95
+ {
96
+ freight: 50.00, # total do frete
97
+ min_delivery_date: min_date, # data mínima de entrega
98
+ max_delivery_date: max_date # data máxima de entrega
99
+ }
100
+ ```
101
+
102
+
103
+ #### 1.4.2 Consulta com retorno completo
104
+
105
+ É possível também pode realizar uma consulta completa com o método `Jamef.complete_rate`.
106
+
107
+ Os parâmetros são idênticos aos da versão simplificada acima, o que muda é o retorno que agora é uma hash originada diretamente da resposta da Jamef.
108
+
109
+ **Exemplo de retorno:**
110
+
111
+ ```ruby
112
+ {:freight=>
113
+ {:msgerro=>"Ok - Calculo executado na filial [ CPQ ] cFilAnt : [03] Cliente Destinatario [ ] ",
114
+ :valfre=>
115
+ {:avalfre=>
116
+ [{:componente=>"[01]-Pedagio ", :imposto=>"0.58634409", :total=>"8.37634409", :valor=>"7.79000000"},
117
+ {:componente=>"[03]-GRIS ", :imposto=>"0.17583323", :total=>"2.51190323", :valor=>"2.33607000"},
118
+ {:componente=>"[04]-TAS ", :imposto=>"0.49000000", :total=>"7.00000000", :valor=>"6.51000000"},
119
+ {:componente=>"[05]-Taxa (ate 100kg) ", :imposto=>"0.00000000", :total=>"0.00000000", :valor=>"0.00000000"},
120
+ {:componente=>"[06]-Frete Peso (FM) ", :imposto=>"13.81830288", :total=>"197.40432688", :valor=>"183.58602400"},
121
+ {:componente=>"[07]-Frete Valor ", :imposto=>"0.55680522", :total=>"7.95436022", :valor=>"7.39755500"},
122
+ {:componente=>"[10]-TRT ", :imposto=>"0.00000000", :total=>"0.00000000", :valor=>"0.00000000"},
123
+ {:componente=>"[23]-Frete Peso (FP) ", :imposto=>"0.00000000", :total=>"0.00000000", :valor=>"0.00000000"},
124
+ {:componente=>"[24]-Taxa (acima 100kg) ", :imposto=>"0.00000000", :total=>"0.00000000", :valor=>"0.00000000"},
125
+ {:componente=>"TF-TOTAL DO FRETE", :imposto=>"15.63000000", :total=>"223.25000000", :valor=>"207.62000000"}]}},
126
+ :delivery=>{:cdtmax=>"03/05/18", :cdtmin=>"02/05/18", :msgerro=>"OK"}}
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 2. Rastreio (Tracking)
132
+
133
+ Ainda não está pronto.
134
+
135
+ ---
136
+
137
+ ## 3. Instalação
138
+
139
+ Se você estiver usando o Bundler, adiciona esta linha no seu Gemfile
140
+
141
+ ```ruby
142
+ gem 'jamef-api', require: 'jamef'
143
+ ```
144
+
145
+ E execute
146
+
147
+ $ bundle
148
+
149
+ Ou instale diretamente no Ruby com
150
+
151
+ $ gem install jamef-api
152
+
153
+ Neste caso, quando for utilizar, não esqueça de dar um
154
+
155
+ ```ruby
156
+ require 'jamef-api'
157
+ ```
158
+
159
+ em cima do documento antes utilizar a Gem.
160
+
161
+ ---
162
+
163
+ ## 4. Informações Complementares - Jamef
164
+
165
+ ### 4.1 Tipo de Produto a ser enviado
166
+
167
+ Você pode especificar o tipo de produto transportado num pacote a partir da tabela abaixo.
168
+
169
+ ##### 4.1.1 Para frete rodoviário​
170
+
171
+ | Ruby symbol | Tipo de produto |
172
+ | -------- | ------- |
173
+ | `:nf` | CONFORME NOTA FISCAL |
174
+ | `:livros` | LIVROS |
175
+
176
+ ##### 4.1.2 Para frete aéreo
177
+
178
+ | Ruby symbol | Tipo de produto |
179
+ | -------- | ------- |
180
+ | `:nf` | CONFORME NOTA FISCAL |
181
+ | `:livros` | LIVROS |
182
+ | `:alimentos` | ALIMENTOS INDUSTRIALIZADOS |
183
+ | `:confeccoes` | CONFECCOES |
184
+ | `:comesticos` | COSMETICOS |
185
+ | `:cirugicos` | MATERIAL CIRURGICO
186
+ | `:jornais` | JORNAIS / REVISTAS |
187
+ | `material_escolar` | MATERIAL ESCOLAR |
188
+
189
+
190
+ ### 4.2 Filiais da Jamef
191
+
192
+ Encontre a sua filial e veja o valor do `jamef_branch` que você deve utilizar. Basicamente é o nome da cidade, mas por via das dúvidas:
193
+
194
+ **Filial Map:**
195
+
196
+ | Ruby symbol | Filial |
197
+ |---|---|
198
+ | `:aracaju` | AJU - Aracaju - SE |
199
+ | `:barueri` | BAR - Barueri - SP |
200
+ | `:bauru` | BAU - Bauru - SP |
201
+ | `:belo_horizonte` | BHZ - Belo Horizonte - MG |
202
+ | `:blumenau` | BNU - Blumenau - SC |
203
+ | `:brasilia` | BSB - Brasília - DF |
204
+ | `:criciuma` | CCM - Criciúma - SC |
205
+ | `:campinas` | CPQ - Campinas - SP |
206
+ | `:caxias_do_sul` | CXJ - Caxias do Sul - RS |
207
+ | `:curitiba` | CWB - Curitiba - PR |
208
+ | `:divinopolis` | DIV - Divinópolis - MG |
209
+ | `:feira_de_santana` | FES - Feira de Santana - BA |
210
+ | `:florianopolis` | FLN - Florianópolis - SC |
211
+ | `:fortaleza` | FOR - Fortaleza - CE |
212
+ | `:goiania` | GYN - Goiânia - GO |
213
+ | `:joao_pessoa` | JPA - João Pessoa - PB |
214
+ | `:juiz_de_fora` | JDF - Juiz de Fora - MG |
215
+ | `:joinville` | JOI - Joinville - SC |
216
+ | `:londrina` | LDB - Londrina - PR |
217
+ | `:manaus` | MAO - Manaus - AM |
218
+ | `:maceio` | MCZ - Maceió - AL |
219
+ | `:maringa` | MGF - Maringá - PR |
220
+ | `:porto_alegre` | POA - Porto Alegre - RS |
221
+ | `:pouso_alegre` | PSA - Pouso Alegre - MG |
222
+ | `:ribeirao_preto` | RAO - Ribeirão Preto - SP |
223
+ | `:recife` | REC - Recife - PE |
224
+ | `:rio_de_janeiro` | RIO - Rio de Janeiro - RJ |
225
+ | `:sao_paulo` | SAO - São Paulo - SP |
226
+ | `:sao_jose_dos_campos` | SJK - São José dos Campos - SP |
227
+ | `:sao_jose_do_rio_preto` | SJP - São José do Rio Preto - SP |
228
+ | `:salvador` | SSA - Salvador - BA |
229
+ | `:uberlandia` | UDI - Uberlândia - MG |
230
+ | `:vitoria_da_conquista` | VDC - Vitória da Conquista - BA |
231
+ | `:vitoria` | VIX - Vitória - ES |
232
+
233
+ ---
234
+
235
+ ## 5. Contribuições
236
+
237
+ Se vir um bug, manda aí.
238
+
239
+ Pull requests são super bem-vindos e serão aceitos desde que:
240
+
241
+ * Não sejam mirabolantes,
242
+ * Incluam testes,
243
+ * Façam sentido.
244
+
245
+ Tamo junto. :)
246
+
247
+ ---
248
+
249
+ ## 6. License
250
+
251
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jamef"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jamef.gemspec ADDED
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jamef/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jamef-api"
8
+ spec.version = Jamef::VERSION
9
+ spec.authors = ["Agilso"]
10
+ spec.email = ["agilso.b@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for the Jamef API}
13
+ spec.description = %q{Ruby wrapper for the Jamef.com.br SOAP API.}
14
+ spec.homepage = "https://github.com/agilso/jamef-api"
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "guard-rspec"
37
+ spec.add_development_dependency "pry"
38
+
39
+ spec.add_dependency "activesupport"
40
+ spec.add_dependency "activemodel"
41
+ spec.add_dependency "rest-client"
42
+ spec.add_dependency 'savon', '~> 2.0'
43
+ end
@@ -0,0 +1,83 @@
1
+ require 'ostruct'
2
+ require 'active_model'
3
+
4
+ module Jamef
5
+ class Branch < OpenStruct
6
+
7
+ include ActiveModel::Validations
8
+
9
+ validates :id, :code, :initials, :location, presence: true
10
+
11
+ def self.branches
12
+ @branches ||= {}
13
+ end
14
+
15
+ def self.find id
16
+ raise ArgumentError, 'Id must be a String or Symbol' unless id.class.in?([Symbol, String])
17
+ branches[id.to_sym]
18
+ end
19
+
20
+ def self.create branch_hash
21
+ raise(ArgumentError,'branch_hash should be a hash. Got #{branch.class} instead.') unless branch_hash.is_a?(Hash)
22
+ branch = new(branch_hash)
23
+ raise("Can not create an invalid branch") unless branch.valid?
24
+ branches.store(branch.id,branch)
25
+ branch
26
+ end
27
+
28
+ def self.all
29
+ branches.map{|k,v| v}
30
+ end
31
+
32
+ def self.first
33
+ all.first
34
+ end
35
+
36
+ def self.last
37
+ all.last
38
+ end
39
+
40
+
41
+ def self.populate
42
+ [
43
+ { id: :aracaju, code: '31', initials: 'AJU' , location: 'Aracaju - SE' },
44
+ { id: :barueri, code: '19', initials: 'BAR' , location: 'Barueri - SP' },
45
+ { id: :bauru, code: '16', initials: 'BAU' , location: 'Bauru - SP' },
46
+ { id: :belo_horizonte, code: '02', initials: 'BHZ' , location: 'Belo Horizonte - MG' },
47
+ { id: :blumenau, code: '09', initials: 'BNU' , location: 'Blumenau - SC' },
48
+ { id: :brasilia, code: '28', initials: 'BSB' , location: 'Brasília - DF' },
49
+ { id: :criciuma, code: '26', initials: 'CCM' , location: 'Criciúma - SC' },
50
+ { id: :campinas, code: '03', initials: 'CPQ' , location: 'Campinas - SP' },
51
+ { id: :caxias_do_sul, code: '22', initials: 'CXJ' , location: 'Caxias do Sul - RS' },
52
+ { id: :curitiba, code: '04', initials: 'CWB' , location: 'Curitiba - PR' },
53
+ { id: :divinopolis, code: '38', initials: 'DIV' , location: 'Divinópolis - MG' },
54
+ { id: :feira_de_santana, code: '34', initials: 'FES' , location: 'Feira de Santana - BA' },
55
+ { id: :florianopolis, code: '11', initials: 'FLN' , location: 'Florianópolis - SC' },
56
+ { id: :fortaleza, code: '32', initials: 'FOR' , location: 'Fortaleza - CE' },
57
+ { id: :goiania, code: '24', initials: 'GYN' , location: 'Goiânia - GO' },
58
+ { id: :joao_pessoa, code: '36', initials: 'JPA' , location: 'João Pessoa - PB' },
59
+ { id: :juiz_de_fora, code: '23', initials: 'JDF' , location: 'Juiz de Fora - MG' },
60
+ { id: :joinville, code: '08', initials: 'JOI' , location: 'Joinville - SC' },
61
+ { id: :londrina, code: '10', initials: 'LDB' , location: 'Londrina - PR' },
62
+ { id: :manaus, code: '25', initials: 'MAO' , location: 'Manaus - AM' },
63
+ { id: :maceio, code: '33', initials: 'MCZ' , location: 'Maceió - AL' },
64
+ { id: :maringa, code: '12', initials: 'MGF' , location: 'Maringá - PR' },
65
+ { id: :porto_alegre, code: '05', initials: 'POA' , location: 'Porto Alegre - RS' },
66
+ { id: :pouso_alegre, code: '27', initials: 'PSA' , location: 'Pouso Alegre - MG' },
67
+ { id: :ribeirao_preto, code: '18', initials: 'RAO' , location: 'Ribeirão Preto - SP' },
68
+ { id: :recife, code: '30', initials: 'REC' , location: 'Recife - PE' },
69
+ { id: :rio_de_janeiro, code: '06', initials: 'RIO' , location: 'Rio de Janeiro - RJ' },
70
+ { id: :sao_paulo, code: '07', initials: 'SAO' , location: 'São Paulo - SP' },
71
+ { id: :sao_jose_dos_campos, code: '21', initials: 'SJK', location: 'São José dos Campos - SP' },
72
+ { id: :sao_jose_do_rio_preto, code: '20', initials: 'SJP', location: 'São José do Rio Preto - SP' },
73
+ { id: :salvador, code: '29', initials: 'SSA', location: 'Salvador - BA' },
74
+ { id: :uberlandia, code: '17', initials: 'UDI', location: 'Uberlândia - MG' },
75
+ { id: :vitoria_da_conquista, code: '39', initials: 'VDC', location: 'Vitória da Conquista - BA' },
76
+ { id: :vitoria, code: '14', initials: 'VIX', location: 'Vitória - ES' }
77
+ ].each {|branch| create(branch) }
78
+ end
79
+
80
+ populate
81
+
82
+ end
83
+ end