me_api 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -37
- data/lib/me_api/client.rb +2 -3
- data/lib/me_api/version.rb +1 -1
- data/lib/me_api.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a31e7c7edbb13a8a4ac1ce264472d5d1b76e934c19b91d4aef12892429bf5fe
|
4
|
+
data.tar.gz: 0ffc254d5482c1c93f5b3741a4a5f3158773724b5fe9f7c4d246bb801ad70f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6217b231ae87685bf8541726c8064a85b45ffba3f343d1d5b1f627b6a0fc7212024799a513de33f1c8784aeb0e0f424fa51047e1bbc0793111cac0574d509250
|
7
|
+
data.tar.gz: ea471a49a79450c4f198560c574cfaeacff1fd0ac6d1d4afd3df316d547205019b2a929ddaefbb645f9f7c71ab2c1b6acbc592c762cbf2dbd09ce624fb001e35
|
data/README.md
CHANGED
@@ -1,39 +1,58 @@
|
|
1
1
|
# MeApi
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
##
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
3
|
+
Wrapper de integração com a API v2 do Melhor Envio para cotação de frete.
|
4
|
+
|
5
|
+
[Documentação API Melhor Envio](https://docs.melhorenvio.com.br/reference/introducao-api-melhor-envio)
|
6
|
+
|
7
|
+
### Funcionalidades:
|
8
|
+
- Autenticação: authorization e refresh_token
|
9
|
+
- Cotação de frete
|
10
|
+
|
11
|
+
## Instalação
|
12
|
+
|
13
|
+
Adicionar me_api no Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'me_api'
|
17
|
+
```
|
18
|
+
ou
|
19
|
+
```shell
|
20
|
+
bundle add me_api
|
21
|
+
```
|
22
|
+
|
23
|
+
Instalar a gem:
|
24
|
+
|
25
|
+
```shell
|
26
|
+
bin/rails generate me_api:install
|
27
|
+
```
|
28
|
+
|
29
|
+
## Uso
|
30
|
+
|
31
|
+
### Exemplo
|
32
|
+
#### Autorização
|
33
|
+
```ruby
|
34
|
+
api_client = MeApi::Client.new.authorize(client_id: "123456", client_secret: "abcde", code: "a1b2c3d4e5", redirect_url: "https://redirect-url.com")
|
35
|
+
# retorna JSON da resposta
|
36
|
+
puts api_client["access_token"] # string -> "abcde12345"
|
37
|
+
puts api_client["refresh_token"] # string -> "asdfghjk123456"
|
38
|
+
puts api_client["expires_in"] # integer -> 216000
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Refresh Token
|
42
|
+
```ruby
|
43
|
+
api_client = MeApi::Client.new.refresh_token(client_id: "123456", client_secret: "abcde", refresh_token: "asdfghjk123456")
|
44
|
+
# retorna JSON da resposta
|
45
|
+
puts api_client["access_token"] # string -> "abcde12345"
|
46
|
+
puts api_client["refresh_token"] # string -> "qwertyu098765"
|
47
|
+
puts api_client["expires_in"] # string -> 21600
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Cotação de Frete
|
51
|
+
```ruby
|
52
|
+
rates = MeApi::Client.new("access_token").rates(from: "01002010", to: "99990971", weight_kg: 10, contents_value_brl: 100.00, height_cm: 15, width_cm: 30, length_cm: 30)
|
53
|
+
|
54
|
+
#retorna um array de Objetos <MeApi::Client::Rate>
|
55
|
+
puts rates[0] # <data MeApi::Client::Rate from="01002010", to="99990971", price=87.3, delivery_range={"min"=>16, "max"=>17}, service_name="PAC", carrier_name="Correios", carrier_logo_url="https://www.melhorenvio.com.br/images/shipping-companies/correios.png">
|
56
|
+
|
57
|
+
puts rates[0].price # 87.3
|
58
|
+
```
|
data/lib/me_api/client.rb
CHANGED
@@ -53,7 +53,7 @@ module MeApi
|
|
53
53
|
client_secret: client_secret,
|
54
54
|
refresh_token: refresh_token
|
55
55
|
}
|
56
|
-
|
56
|
+
post "/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}
|
57
57
|
end
|
58
58
|
|
59
59
|
def authorize client_id:, client_secret:, code:, redirect_url:
|
@@ -64,8 +64,7 @@ module MeApi
|
|
64
64
|
code: code,
|
65
65
|
redirect_uri: redirect_url
|
66
66
|
}
|
67
|
-
|
67
|
+
post "/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}
|
68
68
|
end
|
69
|
-
|
70
69
|
end
|
71
70
|
end
|
data/lib/me_api/version.rb
CHANGED
data/lib/me_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: me_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Todas Essas Coisas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|
@@ -40,12 +40,12 @@ files:
|
|
40
40
|
- lib/me_api.rb
|
41
41
|
- lib/me_api/client.rb
|
42
42
|
- lib/me_api/version.rb
|
43
|
-
homepage: https://github.com/
|
43
|
+
homepage: https://github.com/todasessascoisas/me_api
|
44
44
|
licenses:
|
45
45
|
- MIT
|
46
46
|
metadata:
|
47
|
-
homepage_uri: https://github.com/
|
48
|
-
source_code_uri: https://github.com/
|
47
|
+
homepage_uri: https://github.com/todasessascoisas/me_api
|
48
|
+
source_code_uri: https://github.com/todasessascoisas/me_api
|
49
49
|
post_install_message:
|
50
50
|
rdoc_options: []
|
51
51
|
require_paths:
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.5.
|
64
|
+
rubygems_version: 3.5.9
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: ''
|