solidus_melhor_envio 1.0.2 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c6708cbeb3642d4badecc81cf24b42297e7db6254f4492a4edfe92d057f9cc2
4
- data.tar.gz: 8820b20d0e323555d53ffc3a81d01bd0fd6e01538b81238a8d7feb80d19c326a
3
+ metadata.gz: '0871a5d3a64d261d6c9fed40d8b3b1bb2ce8fdab2c1a6465d75dc073c47e94d5'
4
+ data.tar.gz: 37aa4497184d5e98e1e00ba2ee2a52082209ad74b47850ca00ba17da3be6e006
5
5
  SHA512:
6
- metadata.gz: 4aa5fbdfaa69349510abf0cedc2a805c08bf90796f827c10fdfda8bede9a2c2d963bfeaeec28d11fcbea9d4d6559e434cf870fcb274505715f7674035a7400c6
7
- data.tar.gz: 280368821229c67f4e57bbb4ed0534e90902a3a16513e4348db15d17b64a01363a6fab7e76d95bdca4bc3c86f8cbf6f4b996ae9ddc7088977c8133787cad3bfb
6
+ metadata.gz: ab880b0187ceda03cf865b7ab257398ac1c2cc23928a4b7a6d2905bcdcd2955eb25438ca71c1d0b9c7393387f3cc15b761f97cdaa33daeea2439733e8acc6424
7
+ data.tar.gz: 628f824b93dcf33ed1ba02d786b1c29de796dcda2e194a8e9d71dd08569e6c6370766545f896bd29b54066b5b147f109c8e5eb775a085e7e0a9e9d40f8fd91b8
data/README.md CHANGED
@@ -11,7 +11,7 @@ Gem utilizada para integrar o MelhorEnvio (cotação de frete) no Solidus.
11
11
  Add solidus_melhor_envio to your Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'solidus_melhor_envio'
14
+ gem "solidus_melhor_envio"
15
15
  ```
16
16
 
17
17
  Bundle your dependencies and run the installation generator:
@@ -28,7 +28,7 @@ Adicionar no aquivo `/config/initializers/spree.rb` a linha abaixo, para configu
28
28
  Spree.config do |config|
29
29
 
30
30
  # +++
31
- config.stock.estimator_class= 'SolidusMelhorEnvio::ShippingEstimator'
31
+ config.stock.estimator_class = "SolidusMelhorEnvio::ShippingEstimator"
32
32
  end
33
33
  ```
34
34
  No arquivo `/config/initializers/solidus_melhor_envio.rb` definir as variáveis `app_name` (nome do aplicativo cadastrado no MelhorEnvio), `postal_code_from` (Código Postal de origem) e `services` (id dos serviços de frete desejados que retorne na requisição)
@@ -36,9 +36,9 @@ No arquivo `/config/initializers/solidus_melhor_envio.rb` definir as variáveis
36
36
  ```ruby
37
37
  SolidusMelhorEnvio.configure do |config|
38
38
 
39
- config.app_name = '' # ex. 'app_name'
40
- config.postal_code_from = '' # ex.: '01555-000'
41
- config.services = '' # ex.: '1,2,3,4' - valores separados por vírgula
39
+ config.app_name = "" # ex. 'app_name'
40
+ config.postal_code_from = "" # ex.: '01555-000'
41
+ config.services = "" # ex.: '1,2,3,4' - valores separados por vírgula
42
42
  end
43
43
  ```
44
44
 
@@ -46,12 +46,12 @@ Após, criar a `SolidusMelhorEnvio::Account`, onde ficarão registrados os dados
46
46
 
47
47
  ```ruby
48
48
  SolidusMelhorEnvio::Account.create!({
49
- app_name: 'app_name',
50
- api_base_url: 'https://www.melhorenvio.com.br',
51
- client_id: '12345',
52
- client_secret: '123456',
53
- refresh_token: '1234',
54
- user_agent: 'usuario@example.com'
49
+ app_name: "app_name",
50
+ api_base_url: "https://www.melhorenvio.com.br",
51
+ client_id: "12345",
52
+ client_secret: "123456",
53
+ refresh_token: "1234",
54
+ user_agent: "usuario@example.com"
55
55
  })
56
56
  ```
57
57
 
@@ -1,5 +1,4 @@
1
1
  module SolidusMelhorEnvio
2
2
  class Account < ApplicationRecord
3
-
4
3
  end
5
4
  end
@@ -32,14 +32,12 @@ module SolidusMelhorEnvio
32
32
  end
33
33
 
34
34
  def response_has_error? json
35
- if json.include? "error"
36
- error = json["error"]
37
- raise "ERROR: #{json}"
38
- end
35
+ raise "ERROR: #{json}" if json.include? "error"
39
36
  end
40
37
 
41
38
  def need_refresh_token?
42
39
  return true if @account.token_expires_in.nil?
40
+
43
41
  DateTime.now.utc > (@account.token_expires_in - 2.hours)
44
42
  end
45
43
 
@@ -47,4 +45,4 @@ module SolidusMelhorEnvio
47
45
  refresh_token if need_refresh_token?
48
46
  end
49
47
  end
50
- end
48
+ end
@@ -1,34 +1,32 @@
1
1
  module SolidusMelhorEnvio
2
2
  class ShippingEstimator < SolidusMelhorEnvio::Api
3
-
4
3
  def initialize
5
4
  super(SolidusMelhorEnvio::Account.find_by(app_name: SolidusMelhorEnvio.config.app_name))
6
5
  end
7
6
 
8
-
9
- def shipping_rates(package, _frontend_only = true)
7
+ def shipping_rates(package, _frontend_only: true)
10
8
  melhor_envio_rates = get_rates_from_melhor_envio(package)
11
9
  shipping_rates = melhor_envio_rates.map do |melhor_envio_rate|
12
10
  build_shipping_rate(melhor_envio_rate, package)
13
11
  end
14
-
12
+
15
13
  unless shipping_rates.empty?
16
14
  default_shipping_rate = ::Spree::Config.shipping_rate_selector_class.new(shipping_rates).find_default
17
15
  default_shipping_rate.selected = true
18
16
  end
19
-
17
+
20
18
  shipping_rates
21
19
  end
22
-
20
+
23
21
  private
24
-
22
+
25
23
  def get_rates_from_melhor_envio(package)
26
24
  postal_code_from = SolidusMelhorEnvio.config.postal_code_from
27
25
  services = SolidusMelhorEnvio.config.services
28
- weight = package.contents.map {|content| content.weight }.sum
29
- price = package.contents.map {|content| content.price }.sum
26
+ weight = package.contents.map(&:weight).sum
27
+ price = package.contents.map(&:price).sum
30
28
  zipcode = package.order.ship_address.zipcode
31
-
29
+
32
30
  request_body = {
33
31
  "from" => {
34
32
  "postal_code" => postal_code_from
@@ -55,18 +53,18 @@ module SolidusMelhorEnvio
55
53
  res_json.select { |a| a["price"] }
56
54
  end
57
55
 
58
- def build_shipping_rate(melhor_envio_rate, package)
59
-
56
+ def build_shipping_rate(melhor_envio_rate, _package)
57
+
60
58
  shipping_method = ::Spree::ShippingMethod.find_or_create_by(
61
59
  carrier: melhor_envio_rate["company"]["name"],
62
- service_level: melhor_envio_rate["name"],
63
- ) do |shipping_method|
64
- shipping_method.name = "#{melhor_envio_rate["company"]["name"]} #{melhor_envio_rate["name"]}"
65
- shipping_method.calculator = ::Spree::Calculator::Shipping::FlatRate.create
66
- shipping_method.shipping_categories = ::Spree::ShippingCategory.all
67
- shipping_method.available_to_users = true
60
+ service_level: melhor_envio_rate["name"]
61
+ ) do |sm|
62
+ sm.name = "#{melhor_envio_rate["company"]["name"]} #{melhor_envio_rate["name"]}"
63
+ sm.calculator = ::Spree::Calculator::Shipping::FlatRate.create
64
+ sm.shipping_categories = ::Spree::ShippingCategory.all
65
+ sm.available_to_users = true
68
66
  end
69
-
67
+
70
68
  ::Spree::ShippingRate.new(
71
69
  shipping_method: shipping_method,
72
70
  cost: melhor_envio_rate["price"],
@@ -75,4 +73,4 @@ module SolidusMelhorEnvio
75
73
  )
76
74
  end
77
75
  end
78
- end
76
+ end
@@ -4,36 +4,26 @@ module SolidusMelhorEnvio
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
- source_root File.expand_path('templates', __dir__)
7
+ source_root File.expand_path("templates", __dir__)
8
8
 
9
9
  def self.exit_on_failure?
10
10
  true
11
11
  end
12
12
 
13
13
  def copy_initializer
14
- template 'initializer.rb', 'config/initializers/solidus_melhor_envio.rb'
15
- end
16
-
17
- def add_javascripts
18
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_melhor_envio\n"
19
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_melhor_envio\n"
20
- end
21
-
22
- def add_stylesheets
23
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_melhor_envio\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
24
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_melhor_envio\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
14
+ template "initializer.rb", "config/initializers/solidus_melhor_envio.rb"
25
15
  end
26
16
 
27
17
  def add_migrations
28
- run 'bin/rails railties:install:migrations FROM=solidus_melhor_envio'
18
+ run "bin/rails railties:install:migrations FROM=solidus_melhor_envio"
29
19
  end
30
20
 
31
21
  def run_migrations
32
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
22
+ run_migrations = options[:auto_run_migrations] || ["", "y", "Y"].include?(ask("Would you like to run the migrations now? [Y/n]")) # rubocop:disable Layout/LineLength
33
23
  if run_migrations
34
- run 'bin/rails db:migrate'
24
+ run "bin/rails db:migrate"
35
25
  else
36
- puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
26
+ puts "Skipping bin/rails db:migrate, don't forget to run it!" # rubocop:disable Rails/Output
37
27
  end
38
28
  end
39
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMelhorEnvio
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_melhor_envio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamilton Tumenas Borges
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -90,10 +90,6 @@ files:
90
90
  - LICENSE
91
91
  - README.md
92
92
  - Rakefile
93
- - app/assets/javascripts/spree/backend/solidus_melhor_envio.js
94
- - app/assets/javascripts/spree/frontend/solidus_melhor_envio.js
95
- - app/assets/stylesheets/spree/backend/solidus_melhor_envio.css
96
- - app/assets/stylesheets/spree/frontend/solidus_melhor_envio.css
97
93
  - app/models/solidus_melhor_envio/account.rb
98
94
  - app/models/solidus_melhor_envio/api.rb
99
95
  - app/models/solidus_melhor_envio/shipping_estimator.rb
@@ -107,7 +103,7 @@ files:
107
103
  - config/locales/en.yml
108
104
  - config/routes.rb
109
105
  - db/migrate/20230929133307_create_solidus_melhor_envio_accounts.rb
110
- - db/migrate/20230929180714_add_delivery_time_to_spree_shipping_rate.rb
106
+ - db/migrate/20231020174403_add_delivery_time_to_spree_shipping_rate.rb
111
107
  - lib/generators/solidus_melhor_envio/install/install_generator.rb
112
108
  - lib/generators/solidus_melhor_envio/install/templates/initializer.rb
113
109
  - lib/solidus_melhor_envio.rb
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
- */