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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6ea3e2a7302505ff5c257e9125c72609c5cd99c021044e2d15dd87ad219cccc
4
- data.tar.gz: d7b0e714da2560ed6c485ea3f5b2ec257e6673e5ab387b287d76cce67f143934
3
+ metadata.gz: 4a31e7c7edbb13a8a4ac1ce264472d5d1b76e934c19b91d4aef12892429bf5fe
4
+ data.tar.gz: 0ffc254d5482c1c93f5b3741a4a5f3158773724b5fe9f7c4d246bb801ad70f85
5
5
  SHA512:
6
- metadata.gz: c3e01d16aea17a1a9d04af7ea24e46531f9998f16233d1f0278943dcb2b5f7f5097b7a090f6e558fe5527052c33f499c7da324b4f11d389db502ccd84bfaafaf
7
- data.tar.gz: bef4b5a02a5cc1e582ec0bc8d7ab3dfde8d12e1e3231a97c5b0b8ae48a7888bd9fe6e832645a535c74436d013dc53f467076121a28675cc5ee388d3459d3f878
6
+ metadata.gz: 6217b231ae87685bf8541726c8064a85b45ffba3f343d1d5b1f627b6a0fc7212024799a513de33f1c8784aeb0e0f424fa51047e1bbc0793111cac0574d509250
7
+ data.tar.gz: ea471a49a79450c4f198560c574cfaeacff1fd0ac6d1d4afd3df316d547205019b2a929ddaefbb645f9f7c71ab2c1b6acbc592c762cbf2dbd09ce624fb001e35
data/README.md CHANGED
@@ -1,39 +1,58 @@
1
1
  # MeApi
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/me_api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/me_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/me_api/blob/master/CODE_OF_CONDUCT.md).
32
-
33
- ## License
34
-
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the MeApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/me_api/blob/master/CODE_OF_CONDUCT.md).
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
- response = post "/oauth/token", body: JSON.dump(body), headers: { "Content-Type": "application/json" }
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
- response = post "/oauth/token", body: JSON.dump(body), headers: { "Content-Type": "application/json" }
67
+ post "/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}
68
68
  end
69
-
70
69
  end
71
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeApi
4
- VERSION = "0.3.3"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/me_api.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ac'
3
+ require "ac"
4
4
  require_relative "me_api/version"
5
5
  require_relative "me_api/client"
6
6
 
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.3.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - ulysses-bull
7
+ - Todas Essas Coisas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-04 00:00:00.000000000 Z
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/ulysses-bull/me_api
43
+ homepage: https://github.com/todasessascoisas/me_api
44
44
  licenses:
45
45
  - MIT
46
46
  metadata:
47
- homepage_uri: https://github.com/ulysses-bull/me_api
48
- source_code_uri: https://github.com/ulysses-bull/me_api
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.10
64
+ rubygems_version: 3.5.9
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: ''