solidus_bling 1.0.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/.circleci/config.yml +53 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +1 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +48 -0
- data/LICENSE +26 -0
- data/README.md +73 -0
- data/Rakefile +7 -0
- data/app/assets/javascripts/spree/backend/solidus_bling.js +2 -0
- data/app/assets/javascripts/spree/frontend/solidus_bling.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_bling.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_bling.css +4 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/erp_contact_job.rb +18 -0
- data/app/jobs/erp_order_job.rb +20 -0
- data/app/jobs/erp_product_job.rb +11 -0
- data/app/models/bling/api.rb +56 -0
- data/app/models/bling/contato.rb +83 -0
- data/app/models/bling/pedido.rb +131 -0
- data/app/models/bling/produto.rb +33 -0
- data/app/models/erp_account.rb +3 -0
- data/app/models/erp_event.rb +2 -0
- data/app/models/erp_product.rb +3 -0
- data/app/subscribers/bling/subscriber.rb +39 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +78 -0
- data/bin/setup +8 -0
- data/config/initializers/solidus_bling.rb +11 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20230906141624_create_erp_accounts.rb +17 -0
- data/db/migrate/20230906141728_add_erp_id_to_spree_orders.rb +6 -0
- data/db/migrate/20230906142108_create_erp_products.rb +12 -0
- data/db/migrate/20230906142806_create_erp_events.rb +14 -0
- data/db/migrate/20230908145050_add_number_district_to_addresses.rb +6 -0
- data/lib/generators/solidus_bling/install/install_generator.rb +41 -0
- data/lib/generators/solidus_bling/install/templates/initializer.rb +11 -0
- data/lib/solidus_bling/configuration.rb +19 -0
- data/lib/solidus_bling/engine.rb +26 -0
- data/lib/solidus_bling/testing_support/factories.rb +4 -0
- data/lib/solidus_bling/version.rb +5 -0
- data/lib/solidus_bling.rb +6 -0
- data/solidus_bling.gemspec +36 -0
- data/spec/jobs/erp_contact_job_spec.rb +5 -0
- data/spec/jobs/erp_order_job_spec.rb +5 -0
- data/spec/jobs/erp_product_job_spec.rb +5 -0
- data/spec/models/erp_account_spec.rb +5 -0
- data/spec/models/erp_event_spec.rb +5 -0
- data/spec/models/erp_product_spec.rb +5 -0
- data/spec/spec_helper.rb +32 -0
- metadata +175 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
module Bling
|
2
|
+
class Subscriber
|
3
|
+
include Omnes::Subscriber
|
4
|
+
|
5
|
+
handle :order_finalized,
|
6
|
+
with: :send_order_to_bling,
|
7
|
+
id: :send_order_to_bling
|
8
|
+
|
9
|
+
handle :erp_products_updated,
|
10
|
+
with: :products_updated,
|
11
|
+
id: :products_updated
|
12
|
+
|
13
|
+
handle :erp_contato_created,
|
14
|
+
with: :contato_created,
|
15
|
+
id: :contato_created
|
16
|
+
|
17
|
+
def send_order_to_bling event
|
18
|
+
order = event.payload[:order]
|
19
|
+
subscriber_name = event.omnes_event_name
|
20
|
+
method = __method__.to_s
|
21
|
+
ErpOrderJob.perform_later(order: order, event_name: subscriber_name, method_name: method)
|
22
|
+
end
|
23
|
+
|
24
|
+
def contato_created event
|
25
|
+
contato = event.payload[:args][:contato]
|
26
|
+
order = event.payload[:args][:order]
|
27
|
+
subscriber_name = event.omnes_event_name
|
28
|
+
method = __method__.to_s
|
29
|
+
ErpContactJob.perform_later(order: order, contact: contato, event_name: subscriber_name, method_name: method)
|
30
|
+
end
|
31
|
+
|
32
|
+
def products_updated event
|
33
|
+
products = event.payload[:products]
|
34
|
+
method = __method__.to_s
|
35
|
+
subscriber_name = event.omnes_event_name
|
36
|
+
ErpProductJob.perform_later(products: products, event_name: subscriber_name, method_name: method)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "bundler/setup"
|
6
|
+
require "solidus_bling"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require "irb"
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
data/bin/rails-engine
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_bling/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
app_root = 'sandbox'
|
4
|
+
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
6
|
+
warn 'Creating the sandbox app...'
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
9
|
+
warn 'Automatic creation of the sandbox app failed'
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir.chdir app_root
|
16
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/sandbox
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
test -z "${DEBUG+empty_string}" || set -x
|
5
|
+
|
6
|
+
test "$DB" = "sqlite" && export DB="sqlite3"
|
7
|
+
|
8
|
+
if [ -z "$SOLIDUS_BRANCH" ]
|
9
|
+
then
|
10
|
+
echo "~~> Use 'export SOLIDUS_BRANCH=[main|v3.2|...]' to control the Solidus branch"
|
11
|
+
SOLIDUS_BRANCH="main"
|
12
|
+
fi
|
13
|
+
echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
|
14
|
+
|
15
|
+
if [ -z "$SOLIDUS_FRONTEND" ]
|
16
|
+
then
|
17
|
+
echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend"
|
18
|
+
SOLIDUS_FRONTEND="solidus_frontend"
|
19
|
+
fi
|
20
|
+
echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend"
|
21
|
+
|
22
|
+
extension_name="solidus_bling"
|
23
|
+
|
24
|
+
# Stay away from the bundler env of the containing extension.
|
25
|
+
function unbundled {
|
26
|
+
ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
|
27
|
+
}
|
28
|
+
|
29
|
+
rm -rf ./sandbox
|
30
|
+
unbundled bundle exec rails new sandbox \
|
31
|
+
--database="${DB:-sqlite3}" \
|
32
|
+
--skip-bundle \
|
33
|
+
--skip-git \
|
34
|
+
--skip-keeps \
|
35
|
+
--skip-rc \
|
36
|
+
--skip-spring \
|
37
|
+
--skip-test \
|
38
|
+
--skip-javascript
|
39
|
+
|
40
|
+
if [ ! -d "sandbox" ]; then
|
41
|
+
echo 'sandbox rails application failed'
|
42
|
+
exit 1
|
43
|
+
fi
|
44
|
+
|
45
|
+
cd ./sandbox
|
46
|
+
cat <<RUBY >> Gemfile
|
47
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
|
48
|
+
gem 'rails-i18n'
|
49
|
+
gem 'solidus_i18n'
|
50
|
+
|
51
|
+
gem '$extension_name', path: '..'
|
52
|
+
|
53
|
+
group :test, :development do
|
54
|
+
platforms :mri do
|
55
|
+
gem 'pry-byebug'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RUBY
|
59
|
+
|
60
|
+
unbundled bundle install --gemfile Gemfile
|
61
|
+
|
62
|
+
unbundled bundle exec rake db:drop db:create
|
63
|
+
|
64
|
+
unbundled bundle exec rails generate solidus:install \
|
65
|
+
--auto-accept \
|
66
|
+
--user_class=Spree::User \
|
67
|
+
--enforce_available_locales=true \
|
68
|
+
--with-authentication=true \
|
69
|
+
--payment-method=none \
|
70
|
+
--frontend=${SOLIDUS_FRONTEND} \
|
71
|
+
$@
|
72
|
+
|
73
|
+
unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
|
74
|
+
unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
|
75
|
+
|
76
|
+
echo
|
77
|
+
echo "🚀 Sandbox app successfully created for $extension_name!"
|
78
|
+
echo "🧪 This app is intended for test purposes."
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SolidusBling.configure do |config|
|
4
|
+
# TODO: Remember to change this with the actual preferences you have implemented!
|
5
|
+
# config.sample_preference = 'sample_value'
|
6
|
+
config.app_name = ''
|
7
|
+
config.store_id = ''
|
8
|
+
config.seller_id = ''
|
9
|
+
config.payment_type_id = ''
|
10
|
+
config.category_id = ''
|
11
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateErpAccounts < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :erp_accounts do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :app_name
|
6
|
+
t.string :api_base_url
|
7
|
+
t.string :api_key
|
8
|
+
t.string :client_id
|
9
|
+
t.string :client_secret
|
10
|
+
t.string :refresh_token
|
11
|
+
t.string :access_token
|
12
|
+
t.datetime :token_expires_in
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateErpProducts < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :erp_products do |t|
|
4
|
+
t.string :external_id, null: false, index: { unique: true }
|
5
|
+
t.string :name, null: false
|
6
|
+
t.string :sku, null: false, index: { unique: true }
|
7
|
+
t.references :erp_account, null: false, foreign_key: true
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateErpEvents < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :erp_events do |t|
|
4
|
+
t.string :internal_id
|
5
|
+
t.string :status
|
6
|
+
t.string :message
|
7
|
+
t.string :body
|
8
|
+
t.string :name
|
9
|
+
t.string :method
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBling
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def self.exit_on_failure?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_initializer
|
14
|
+
template 'initializer.rb', 'config/initializers/solidus_bling.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_javascripts
|
18
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_bling\n"
|
19
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_bling\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_stylesheets
|
23
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_bling\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
24
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_bling\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_migrations
|
28
|
+
run 'bin/rails railties:install:migrations FROM=solidus_bling'
|
29
|
+
end
|
30
|
+
|
31
|
+
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
|
33
|
+
if run_migrations
|
34
|
+
run 'bin/rails db:migrate'
|
35
|
+
else
|
36
|
+
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SolidusBling.configure do |config|
|
4
|
+
# TODO: Remember to change this with the actual preferences you have implemented!
|
5
|
+
# config.sample_preference = 'sample_value'
|
6
|
+
config.app_name = ''
|
7
|
+
config.store_id = ''
|
8
|
+
config.seller_id = ''
|
9
|
+
config.payment_type_id = ''
|
10
|
+
config.category_id = ''
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBling
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :app_name, :store_id, :seller_id, :payment_type_id, :category_id
|
6
|
+
end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
alias config configuration
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield configuration
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'solidus_core'
|
4
|
+
require 'solidus_support'
|
5
|
+
|
6
|
+
module SolidusBling
|
7
|
+
class Engine < Rails::Engine
|
8
|
+
include SolidusSupport::EngineExtensions
|
9
|
+
|
10
|
+
isolate_namespace ::Spree
|
11
|
+
|
12
|
+
engine_name 'solidus_bling'
|
13
|
+
|
14
|
+
# use rspec for tests
|
15
|
+
config.generators do |g|
|
16
|
+
g.test_framework :rspec
|
17
|
+
end
|
18
|
+
|
19
|
+
config.to_prepare do
|
20
|
+
Spree::Bus.register(:erp_products_updated)
|
21
|
+
Spree::Bus.register(:erp_contato_created)
|
22
|
+
Bling::Subscriber.new.subscribe_to(Spree::Bus)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/solidus_bling/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'solidus_bling'
|
7
|
+
spec.version = SolidusBling::VERSION
|
8
|
+
spec.authors = ['ulysses-bull']
|
9
|
+
spec.email = 'contato7bulloleo@gmail.com'
|
10
|
+
|
11
|
+
spec.summary = 'Solidus extension to integrate with the Bling'
|
12
|
+
spec.homepage = 'https://github.com/ulysses-bull/solidus_bling#readme'
|
13
|
+
spec.license = 'BSD-3-Clause'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ulysses-bull/solidus_bling'
|
17
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ulysses-bull/solidus_bling/blob/master/CHANGELOG.md'
|
18
|
+
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
24
|
+
|
25
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
26
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
|
32
|
+
spec.add_dependency 'solidus_support', '~> 0.5'
|
33
|
+
spec.add_dependency 'typhoeus'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'solidus_dev_support', '~> 2.7'
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV['RAILS_ENV'] = 'test'
|
5
|
+
|
6
|
+
# Run Coverage report
|
7
|
+
require 'solidus_dev_support/rspec/coverage'
|
8
|
+
|
9
|
+
# Create the dummy app if it's still missing.
|
10
|
+
dummy_env = "#{__dir__}/dummy/config/environment.rb"
|
11
|
+
system 'bin/rake extension:test_app' unless File.exist? dummy_env
|
12
|
+
require dummy_env
|
13
|
+
|
14
|
+
# Requires factories and other useful helpers defined in spree_core.
|
15
|
+
require 'solidus_dev_support/rspec/feature_helper'
|
16
|
+
|
17
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
|
+
# in spec/support/ and its subdirectories.
|
19
|
+
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
20
|
+
|
21
|
+
# Requires factories defined in Solidus core and this extension.
|
22
|
+
# See: lib/solidus_bling/testing_support/factories.rb
|
23
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusBling::Engine)
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.infer_spec_type_from_file_location!
|
27
|
+
config.use_transactional_fixtures = false
|
28
|
+
|
29
|
+
if Spree.solidus_gem_version < Gem::Version.new('2.11')
|
30
|
+
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
|
31
|
+
end
|
32
|
+
end
|