enviopack_api 0.1.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 +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +163 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/enviopack_api.gemspec +37 -0
- data/lib/enviopack_api/auth.rb +33 -0
- data/lib/enviopack_api/client.rb +168 -0
- data/lib/enviopack_api/version.rb +3 -0
- data/lib/enviopack_api.rb +9 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2af4f2a40f686135630ef08631f6f09d1e3e26d6
|
4
|
+
data.tar.gz: 2dc207bae0cab04bfc4625161dd1789d201cc5b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71c88fbd04172d0a3012d12f4be7160c6e44464737b2cee0de09514e61aa1c68e334dc2bbb7a3ed6dcaddbe0ed401a24e6cc9efe6f1a8b4936e7084fffd072be
|
7
|
+
data.tar.gz: 4d992863bb9ad13b917b1fbd3250b257d7860565bf59e2f3d782b92d9109983b52c7b3f942c822d909747df4fb72e7fed99f4d2a972e2826490d6e817effbdb4
|
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 slaff@pow.la. 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,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
enviopack_api (0.1.0)
|
5
|
+
json
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
domain_name (0.5.20170404)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
json (2.1.0)
|
16
|
+
mime-types (3.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2016.0521)
|
19
|
+
netrc (0.11.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rest-client (2.0.2)
|
22
|
+
http-cookie (>= 1.0.2, < 2.0)
|
23
|
+
mime-types (>= 1.16, < 4.0)
|
24
|
+
netrc (~> 0.8)
|
25
|
+
unf (0.1.4)
|
26
|
+
unf_ext
|
27
|
+
unf_ext (0.0.7.5)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.16.a)
|
34
|
+
enviopack_api!
|
35
|
+
rake (~> 10.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.16.0.pre.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 V.Bondaruk
|
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,163 @@
|
|
1
|
+
# EnviopackApi
|
2
|
+
|
3
|
+
## Instalación
|
4
|
+
|
5
|
+
Agregá esta linea en tu Ruby (Ruby on Rails) applicación:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# para la última versión
|
9
|
+
gem 'enviopack_api', :git => "git@github.com:bondarolik/enviopack-api.git"
|
10
|
+
```
|
11
|
+
|
12
|
+
Ejecutá bundler:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
O actualiza (instala) independientemente:
|
17
|
+
|
18
|
+
$ gem install enviopack_api
|
19
|
+
|
20
|
+
## Uso
|
21
|
+
|
22
|
+
> Todos los metodos devuelven objetos en OpenStruct. Por lo cual, los response que deberias usar son: result.id (result.code, etc.)
|
23
|
+
|
24
|
+
Primero deberias leer documentación oficial y [consideraciones iniciales](https://www.enviopack.com/documentacion/consideraciones-iniciales) de Enviopack.
|
25
|
+
|
26
|
+
### Access & Refresh tokens
|
27
|
+
|
28
|
+
En segunda instancia seguí los pasos para obtener los API ID & KEY en tu panel de control en Enviopack y luego el `access_token` o `refresh_token`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# Obtener access token
|
32
|
+
irb: EnviopackApi::Auth.new(api_key, api_secret).auth
|
33
|
+
|
34
|
+
# Actualizar tokens:
|
35
|
+
# no olvides a grabarlos en tu base de datos
|
36
|
+
irb: refresh = EnviopackApi::Auth.new(api_key, api_secret).refres(refresh_token)
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
Para usar API en general necesitaras pocos metodos y muchos parametros. Los principales y testeados en esta GEMa estan descriptos a continuación.
|
41
|
+
|
42
|
+
Una vez obtenido access_token podeis comenzar a trabajar con API. Simplemente crea una conexión con cliente:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
client = EnviopackApi::Client.new(access_token)
|
46
|
+
|
47
|
+
# presta atención que va sin trailing slash en adelante
|
48
|
+
client.get("pedidos/id")
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
### Metodos principales GET
|
53
|
+
|
54
|
+
Para obtener datos de pracitcametne cualquier recurso:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
client.get("resource")
|
58
|
+
```
|
59
|
+
|
60
|
+
Recursos disponibles en el momento de publicación:
|
61
|
+
|
62
|
+
+ correos
|
63
|
+
+ sucursales
|
64
|
+
+ provincias
|
65
|
+
+ localidades
|
66
|
+
+ tipos-de-paquetes
|
67
|
+
+ mis-direcciones
|
68
|
+
+ direcciones-de-envio
|
69
|
+
|
70
|
+
Mas información sobre cada uno y sus usos encuentra en [Documentación correspondiente](https://www.enviopack.com/documentacion/correos)
|
71
|
+
|
72
|
+
Para obtener datos de algún recurso especifico podeis utilizar siguiente metodo:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
client.get_resource("resource")
|
76
|
+
```
|
77
|
+
|
78
|
+
### Validación de Código Postal
|
79
|
+
|
80
|
+
Existe un metodo especial para validad `código postal` . El parametro `provincia_id` es un **iso_code** sin prefijo **"AR-"**
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# /provincia/ID/validar-codigo-postal
|
84
|
+
client.validate_zipcode(province_id, zipcode)
|
85
|
+
# => {"valido":true}
|
86
|
+
```
|
87
|
+
|
88
|
+
Mas info sobre [ISO 3166](https://www.iso.org/obp/ui/#iso:code:3166:AR). Sugerimos tenerlos en agluna tabla de tu base de datos.
|
89
|
+
|
90
|
+
### Cotizar un envío
|
91
|
+
|
92
|
+
Basicamente se puede hacer un request por `EnviopackApi::Client.get`, pero también se puede usar este metodo:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# https://www.enviopack.com/documentacion/cotiza-un-envio
|
96
|
+
quote = client.get_quote(params)
|
97
|
+
```
|
98
|
+
|
99
|
+
Existen parametros obligatorios y opcionales. Ten cuidado con esto.
|
100
|
+
|
101
|
+
### Crear un POST
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
client.post("resource")
|
105
|
+
```
|
106
|
+
|
107
|
+
Atención con lo que mandas. Originalmente, los dos **POST** que vas hacer son a "pedidos" y "envios". Pero, también podeis mandar "place_order" o "shipping". No hay problema en esto.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
case resource
|
111
|
+
when "pedidos", "place_order", "new_order" then url = "/pedidos"
|
112
|
+
when "envios", "shipping" then url = "/envios"
|
113
|
+
else url = "/#{resource}"
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
### Impresión de etiquetas de envío
|
119
|
+
|
120
|
+
> Aún no testeado en GEMa en producción. En localhost anda bien, pero sin confirmación todavía.
|
121
|
+
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# imprimir etiqueta particular
|
125
|
+
client.print_single(id, "pdf")
|
126
|
+
|
127
|
+
# imprimir varias etiquetas
|
128
|
+
client.print_batch(ids)
|
129
|
+
```
|
130
|
+
|
131
|
+
En BATCH se imprime únicamente PDF. Tienes que pasar el Array de IDS. Por ejemplo:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
ids = [1,2,3,4]
|
135
|
+
```
|
136
|
+
|
137
|
+
La GEMa lo convierte en formato que corresponde. Como resultado vas a recibir un PDF por el medio de siguiente función ruby:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
send_data(response, :filename => "etiquetas_-_#{timenow}.pdf", :disposition => "attachment", :type => "application/pdf")
|
141
|
+
```
|
142
|
+
|
143
|
+
De la misma manera podes crear un request GET y procesar por separado la etiqueta.
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
## Development
|
148
|
+
|
149
|
+
No esta hecho **SPLIT DE PAGO** y **NOTIFICACIONES**. No se sabe cuando y si se va a realizarse en esta GEMa.
|
150
|
+
|
151
|
+
## Contributing
|
152
|
+
|
153
|
+
Sea bienvenido de forkear, modificar y hacer sugerencias. Postea bugs y requests en ISSUES explicando lo que te paso paso a paso para comprender mejor.
|
154
|
+
|
155
|
+
## License
|
156
|
+
|
157
|
+
GEMa hecha en laboratorios de desarrollo [POW](http://pow.la/)
|
158
|
+
|
159
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
160
|
+
|
161
|
+
## Code of Conduct
|
162
|
+
|
163
|
+
Everyone interacting in the EnviopackApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/enviopack_api/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 "enviopack_api"
|
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,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "enviopack_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "enviopack_api"
|
8
|
+
spec.version = EnviopackApi::VERSION
|
9
|
+
spec.authors = ["V.Bondaruk"]
|
10
|
+
spec.email = ["slaff@pow.la"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby on Rails Enviopack API Interface}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/bondarolik/enviopack-api.git"
|
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"] = "https://rubygems.org/gems/enviopack_api'"
|
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.a"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_dependency "rest-client"
|
36
|
+
spec.add_dependency "json"
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EnviopackApi
|
2
|
+
class Auth
|
3
|
+
def initialize(api_key = nil, api_secret = nil)
|
4
|
+
@api_key = access_token || ENV["ENVIPACK_API_KEY"]
|
5
|
+
@api_secret = access_token || ENV["ENVIPACK_API_SECRET"]
|
6
|
+
@base_uri = "https://api.enviopack.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
def auth
|
10
|
+
endpoint = "#{@base_uri}/auth"
|
11
|
+
|
12
|
+
begin
|
13
|
+
response = RestClient.post endpoint, { "api-key" => @api_key, "secret-key" => @api_secret }
|
14
|
+
result = JSON.parse(response, object_class: OpenStruct)
|
15
|
+
return result
|
16
|
+
rescue => e
|
17
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def refresh(refresh_token)
|
22
|
+
endpoint = "#{@api_url}/token/refresh?refresh_token=#{refresh_token}"
|
23
|
+
|
24
|
+
begin
|
25
|
+
response = RestClient.post endpoint, { "api-key" => @api_key, "secret-key" => @api_secret }
|
26
|
+
result = JSON.parse(response, object_class: OpenStruct)
|
27
|
+
return result
|
28
|
+
rescue => e
|
29
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # EnviopackApi::Auth
|
33
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module EnviopackApi
|
2
|
+
class Client
|
3
|
+
def initialize(access_token = nil)
|
4
|
+
@access_token = access_token || ENV["ENVIPACK_API_TOKEN"]
|
5
|
+
@base_uri = "https://api.enviopack.com"
|
6
|
+
end
|
7
|
+
|
8
|
+
# GET any available resource with or withoud ID
|
9
|
+
# ex.: get("localidades/ID")
|
10
|
+
def get(resource, options = nil)
|
11
|
+
params = options
|
12
|
+
url = "/#{resource}"
|
13
|
+
get_response(url, params)
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /resource_name
|
17
|
+
def get_resource(resource, options = nil)
|
18
|
+
# Prevent resource to be miss spelled
|
19
|
+
case resource
|
20
|
+
when "correos", "couriers"
|
21
|
+
resource_name = "correos"
|
22
|
+
when "sucursales"
|
23
|
+
resource_name = "sucursales"
|
24
|
+
when "provincias", "states"
|
25
|
+
resource_name = "provincias"
|
26
|
+
when "localidades", "barrios"
|
27
|
+
resource_name = "localidades"
|
28
|
+
when "paquetes", "packaging", "boxes", "embalaje"
|
29
|
+
resource_name = "tipos-de-paquetes"
|
30
|
+
when "mis-direcciones", "mi-dreccion", "addresses", "remitiente"
|
31
|
+
resource_name = "mis-direcciones"
|
32
|
+
when "direcciones-de-envio", "direcciones", "destination"
|
33
|
+
resource_name = "direcciones-de-envio"
|
34
|
+
else
|
35
|
+
resource_name = resource
|
36
|
+
end
|
37
|
+
|
38
|
+
# build request
|
39
|
+
url = "/#{resource}"
|
40
|
+
get_response(url, nil)
|
41
|
+
end # get(resource)
|
42
|
+
|
43
|
+
# GET /provincia/ID/validar-codigo-postal
|
44
|
+
# returns param 'valido' true or false
|
45
|
+
def validate_zipcode(province_id, zipcode)
|
46
|
+
zipcode = zipcode.to_i
|
47
|
+
url = "/provincia/#{province_id}/validar-codigo-postal"
|
48
|
+
query = "codigo_postal=#{zipcode}"
|
49
|
+
get_response(url, query)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Obtener el costo que abona el VENDEDOR por el envío
|
53
|
+
# https://www.enviopack.com/documentacion/cotiza-un-envio
|
54
|
+
# Client.get_quote(provincia: "C", codigo_postal: 1407, peso: 0.5, etc: etc)
|
55
|
+
def get_quote(options = {})
|
56
|
+
################### Optionals
|
57
|
+
# will be removed from code
|
58
|
+
# Ej: 20x2x10,20x2x10 indica que se envian 2 paquetes y cada uno tiene 20 cm de alto x 2 cm de ancho x 10 cm de largo.
|
59
|
+
paquetes = options[:paquetes]
|
60
|
+
correo = options[:correo] # ID, e.: "oca"
|
61
|
+
|
62
|
+
# For, :despacho & :modalidad
|
63
|
+
# - D: retiro por domicilio
|
64
|
+
# - S: despacho desde sucursa
|
65
|
+
despacho = options[:despacho] || "D"
|
66
|
+
modalidad = options[:modalidad] || "D"
|
67
|
+
|
68
|
+
# - N: para el servicio estándar
|
69
|
+
# - P: para el servicio prioritario
|
70
|
+
# - X: para el servicio express
|
71
|
+
# - R: para el servicio de devoluciones
|
72
|
+
servicio = options[:servicio] || "N"
|
73
|
+
|
74
|
+
# Shipping dispatch address
|
75
|
+
# Client.get('mis-direcciones')
|
76
|
+
direccion_envio = options[:direccion_envio]
|
77
|
+
|
78
|
+
# - valor: para ordenar por precio (Default)
|
79
|
+
# - horas_entrega: para ordenar por velocidad de envío
|
80
|
+
# - cumplimiento: para ordenar por porcentaje de cumplimiento en envios de similares caracteristicas
|
81
|
+
# - anomalos: para ordenar por porcentaje de anómalos en envios de similares caracteristicas
|
82
|
+
orden_columna = options[:orden_columna]
|
83
|
+
|
84
|
+
# - asc: para orden ascendente (Default)
|
85
|
+
# - desc: para orden descendente
|
86
|
+
orden_sentido = options[:orden_sentido]
|
87
|
+
|
88
|
+
################### Required params
|
89
|
+
provincia = options[:provincia] || "C"
|
90
|
+
codigo_postal = options[:codigo_postal] || ""
|
91
|
+
peso = options[:peso] || 1.0
|
92
|
+
|
93
|
+
url = "/cotizar/costo"
|
94
|
+
query = options.to_query
|
95
|
+
get_response(url, query)
|
96
|
+
end
|
97
|
+
|
98
|
+
# POST resource
|
99
|
+
# https://www.enviopack.com/documentacion/realiza-un-envio
|
100
|
+
# req: resource, params
|
101
|
+
# Client.post("pedidos", params)
|
102
|
+
def post(resource, params)
|
103
|
+
case resource
|
104
|
+
when "pedidos", "place_order", "new_order" then url = "/pedidos"
|
105
|
+
when "envios", "shipping" then url = "/envios"
|
106
|
+
else url = "/#{resource}"
|
107
|
+
end
|
108
|
+
|
109
|
+
post_request(url, params)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Print shipping ticket
|
113
|
+
# ID = ticket ID
|
114
|
+
# Output: PDF or JPG
|
115
|
+
def print_single(id, output = "pdf")
|
116
|
+
timenow = Time.current.strftime("%Y%m%d_-_%H%M")
|
117
|
+
resource_url = "#{@base_uri}/envios/#{id}/etiqueta?access_token=#{@access_token}&formato=#{output}"
|
118
|
+
begin
|
119
|
+
response = RestClient.get resource_url
|
120
|
+
send_data(response, :filename => "etiqueta_-_#{timenow}.pdf", :disposition => "attachment", :type => "application/pdf")
|
121
|
+
rescue e
|
122
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Print batch tickets
|
127
|
+
# Pass Array of ids: ids = [1,2...9]
|
128
|
+
def print_batch(ids)
|
129
|
+
timenow = Time.current.strftime("%Y%m%d_-_%H%M")
|
130
|
+
ids_string = ids.to_csv.delete("\n")
|
131
|
+
resource_url = "#{@base_uri}/envios/etiquetas?access_token=#{@access_token}&ids=#{ids_string}"
|
132
|
+
begin
|
133
|
+
response = RestClient.get resource_url
|
134
|
+
send_data(response, :filename => "etiquetas_-_#{timenow}.pdf", :disposition => "attachment", :type => "application/pdf")
|
135
|
+
rescue e
|
136
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
private
|
142
|
+
# GET
|
143
|
+
def get_response(url, query = nil)
|
144
|
+
query = "&#{query}" if query != nil || query != ""
|
145
|
+
resource_url = "#{@base_uri}#{url}?access_token=#{@access_token}#{query}"
|
146
|
+
|
147
|
+
begin
|
148
|
+
response = RestClient.get(resource_url)
|
149
|
+
result = JSON.parse(response, object_class: OpenStruct)
|
150
|
+
return result
|
151
|
+
rescue => e
|
152
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
153
|
+
end
|
154
|
+
end # get_response
|
155
|
+
|
156
|
+
# POST
|
157
|
+
def post_request(url, params)
|
158
|
+
begin
|
159
|
+
resource_url = "#{@base_uri}#{url}?access_token=#{@access_token}"
|
160
|
+
response = RestClient.post resource_url, params.to_json, {content_type: :json, accept: :json}
|
161
|
+
result = JSON.parse(response, object_class: OpenStruct)
|
162
|
+
return result
|
163
|
+
rescue => e
|
164
|
+
return JSON.parse(e.response, object_class: OpenStruct)
|
165
|
+
end
|
166
|
+
end # post_request
|
167
|
+
end # module EnviopackApi::Client
|
168
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enviopack_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- V.Bondaruk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-15 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.a
|
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.a
|
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: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- slaff@pow.la
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CODE_OF_CONDUCT.md
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- enviopack_api.gemspec
|
85
|
+
- lib/enviopack_api.rb
|
86
|
+
- lib/enviopack_api/auth.rb
|
87
|
+
- lib/enviopack_api/client.rb
|
88
|
+
- lib/enviopack_api/version.rb
|
89
|
+
homepage: https://github.com/bondarolik/enviopack-api.git
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org/gems/enviopack_api'
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.12
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Ruby on Rails Enviopack API Interface
|
114
|
+
test_files: []
|