From b8ccdfbe9550398ceba8b104936f2649780dcfdb Mon Sep 17 00:00:00 2001 From: Chris Francis Date: Fri, 25 Jun 2021 16:30:34 -0400 Subject: [PATCH 1/2] Added install generator --- Gemfile | 5 +- Gemfile.lock | 135 +++++++++++++++------- README.md | 60 ++++++++-- lib/generators/spire/install_generator.rb | 43 +++++++ lib/generators/templates/spire.rb | 7 ++ 5 files changed, 196 insertions(+), 54 deletions(-) create mode 100644 lib/generators/spire/install_generator.rb create mode 100644 lib/generators/templates/spire.rb diff --git a/Gemfile b/Gemfile index 3c8da79..a55e2f0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,9 @@ source "https://rubygems.org" -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in spire.gemspec gemspec + +# lower rails version +gem "rails", "~> 4.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index 1abc0b6..d5dcfd3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - spire (2.3.0) + spire (3.3.0) activemodel (>= 3.2.0) json rest-client (>= 1.8.0) @@ -9,68 +9,116 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (5.2.4.3) - activesupport (= 5.2.4.3) - activesupport (5.2.4.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - coderay (1.1.2) - concurrent-ruby (1.1.6) - diff-lcs (1.3) - docile (1.3.0) + actionmailer (4.0.13) + actionpack (= 4.0.13) + mail (~> 2.5, >= 2.5.4) + actionpack (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.13) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + arel (4.0.2) + builder (3.1.4) + coderay (1.1.3) + concurrent-ruby (1.1.9) + diff-lcs (1.4.4) + docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - factory_bot (4.8.2) + erubis (2.7.0) + factory_bot (4.11.1) activesupport (>= 3.0.0) - faker (1.8.7) - i18n (>= 0.7) + faker (2.2.1) + i18n (>= 0.8) http-accept (1.7.0) - http-cookie (1.0.3) + http-cookie (1.0.4) domain_name (~> 0.5) - i18n (1.5.1) + i18n (0.9.5) concurrent-ruby (~> 1.0) - json (2.3.1) - method_source (0.9.0) + json (2.5.1) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2019.1009) - minitest (5.14.1) + mime-types-data (3.2021.0225) + mini_mime (1.1.0) + minitest (4.7.5) + multi_json (1.15.0) netrc (0.11.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rake (13.0.1) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.13) + actionmailer (= 4.0.13) + actionpack (= 4.0.13) + activerecord (= 4.0.13) + activesupport (= 4.0.13) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.13) + sprockets-rails (~> 2.0) + railties (4.0.13) + actionpack (= 4.0.13) + activesupport (= 4.0.13) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (13.0.3) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.1) - simplecov (0.16.1) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + simplecov (0.21.2) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.3) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + thor (1.1.0) thread_safe (0.3.6) - tzinfo (1.2.7) - thread_safe (~> 0.1) + tzinfo (0.3.60) unf (0.1.4) unf_ext - unf_ext (0.0.7.6) + unf_ext (0.0.7.7) PLATFORMS ruby @@ -80,6 +128,7 @@ DEPENDENCIES factory_bot (~> 4.8) faker pry + rails (~> 4.0.0) rake (~> 13.0) rspec (~> 3.2) simplecov diff --git a/README.md b/README.md index a9c5e16..7978155 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Spire + Spire is a Ruby wrapper around the [Spire Systems API](http://www.spiresystems.com/). This gem was inspired by [ruby-trello](https://github.com/jeremytregunna/ruby-trello). @@ -22,13 +23,29 @@ gem 'spire', git: "https://github.com/bitesite/spire-ruby", tag: "v2.5.0" And then execute: - $ bundle +```shell +$ bundle +``` ## Usage First you will need to configure spire. This is a global configuration. Thus it will be applied anywhere you use spire within your application. +### Rails + +There are 2 options to configure your rails project to use this gem. + +**Automated Rails Generator** + +Run the following command in your projects root folder. + +```shell +$ rails generate spire:install +``` + +**Manual** + If you are using spire within a Rails application, you could put the following config in an initializer. ```ruby @@ -41,34 +58,41 @@ end ``` ### Items + Below are a few usage examples. For other uses, please refer to `lib/item.rb`. Will retrieve one item from Spire + ```ruby Spire::Item.find(itemId) ``` Will search Spire for an item that matches the given query + ```ruby Spire::Item.search('GF-1234') ``` Will retrieve many Items based on a filter from Spire + ```ruby Spire::Item.filter('{"partNo":"ABCD-0001", "whse":"00"}') ``` Will create a new item on Spire + ```ruby Spire::Item.create(options) ``` Will delete an item from Spire + ```ruby Spire::Item.find(itemId).delete ``` Updates item description on Spire + ```ruby item = Spire::Item.find(71) item.description = 'This is a new description' @@ -76,29 +100,35 @@ item.save ``` ### UPCs + Below are a few usage examples. For other uses, please refer to `lib/upc.rb`. Will retrieve many UPCs based on a filter from Spire + ```ruby Spire::Upc.filter('{"partNo":"ABCD-0001", "whse":"00"}') ``` Will retrieve one UPC from Spire + ```ruby Spire::Upc.find(upcId) ``` Will create a new UPC on Spire + ```ruby Spire::Upc.create(upc: "12345678901", uomCode: "EA", inventory: {id: 1}) ``` Will delete a UPC from Spire + ```ruby Spire::Upc.find(upcId).delete ``` Updates a UPC on Spire + ```ruby upc = Spire::Upc.find(1) upc.upc = '12345678902' @@ -106,32 +136,39 @@ upc.save ``` ### Customers + Below are a few usage examples. For other uses, please refer to `lib/customer.rb`. Will retrieve one customer from Spire + ```ruby Spire::Customer.find(customerId) ``` Will search Spire for a customer that matches the given query + ```ruby Spire::Customer.search('casey.li@bitesite.ca') ``` ### Orders + The syntax for orders is very similar to items. For additional information please refer to `lib/order.rb`. Will retrieve one order from Spire + ```ruby Spire::Order.find(orderId) ``` Will search Spire for any order that match the given query + ```ruby Spire::Order.search('casey.li@bitesite.ca') ``` Will create order in Spire + ```ruby Spire::Order.create({ 'customer' => {'id': 'customer id'}, @@ -167,12 +204,15 @@ Spire::Order.create({ 'freight': '14' }) ``` -*Above is the minimum param to create an order in Spire* + +_Above is the minimum param to create an order in Spire_ ### Vendors + The syntax for vendors is very similar to items. For additional information please refer to `lib/vendor.rb`. Will retrieve one vendor from Spire + ```ruby Spire::Vendor.find(vendorId) ``` @@ -193,23 +233,23 @@ To install this gem onto your local machine, run `bundle exec rake install`. 4. ~~Build the gem `gem build spire.gemspec`~~ 5. ~~Publish to BiteSite's RubyGems account `gem push spire-2.4.1.gem`~~ -After trying to publish to rubygems.org, we realized we had a name conflict. If we changed the name of the gem, +After trying to publish to rubygems.org, we realized we had a name conflict. If we changed the name of the gem, that would also affect the code that requires the top-level package. Until we're willing to release a Major version -upgrade with breaking changes, we'll just have to publish via GitHub. +upgrade with breaking changes, we'll just have to publish via GitHub. Until then, when we're ready to release a new version: 1. On master, `git checkout master` 2. Make sure you have the latest changes `git pull` -2. Update `spire/version.rb` with a new version number following Semantic Versioning Rules. -3. Commit the change `git add .` and `git commit -m "Updated version number for release."` -4. Push changes `git push origin master` -5. Tag the commit `git tag 'vX.X.X'` -6. Push tags `git push origin --tags` +3. Update `spire/version.rb` with a new version number following Semantic Versioning Rules. +4. Commit the change `git add .` and `git commit -m "Updated version number for release."` +5. Push changes `git push origin master` +6. Tag the commit `git tag 'vX.X.X'` +7. Push tags `git push origin --tags` ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/bitesite/spire. +Bug reports and pull requests are welcome on GitHub at https://github.com/bitesite/spire-ruby. We do not currently support the entire [Spire](http://www.spiresystems.com/) api. Any pull requests adding CRUD resources to this gem are appreciated. diff --git a/lib/generators/spire/install_generator.rb b/lib/generators/spire/install_generator.rb new file mode 100644 index 0000000..78f6632 --- /dev/null +++ b/lib/generators/spire/install_generator.rb @@ -0,0 +1,43 @@ +module Spire + module Generators + class InstallGenerator < Rails::Generators::Base + source_root File.expand_path("../../templates", __FILE__) + + desc "Creates a spire initializer." + + def setup_initializer + template "spire.rb", "config/initializers/spire.rb" + + if yes?("\nAre you using the dotenv-rails gem to store your environment variables?") + gsub_file "config/initializers/spire.rb", /(config\.company.+)/, "config.company = ENV['SPIRE_COMPANY']" + gsub_file "config/initializers/spire.rb", /(config\.username.+)/, "config.username = ENV['SPIRE_USERNAME']" + gsub_file "config/initializers/spire.rb", /(config\.password.+)/, "config.password = ENV['SPIRE_PASSWORD']" + gsub_file "config/initializers/spire.rb", /(config\.host.+)/, "config.host = ENV['SPIRE_HOST']" + gsub_file "config/initializers/spire.rb", /(config\.port.+)/, "config.port = ENV['SPIRE_PORT']" + + if yes?("\nDo you have the Spire configuration variables?") + spire_company = ask("Spire Company:") + spire_host = ask("Spire Host:") + spire_port = ask("Spire Port:") + spire_username = ask("Spire Username:") + spire_password = ask("Spire Password:") + + spire_env_vars = <<~EOF + SPIRE_COMPANY=#{spire_company} + SPIRE_HOST=#{spire_host} + SPIRE_PORT=#{spire_port} + SPIRE_USERNAME=#{spire_username} + SPIRE_PASSWORD=#{spire_password} + EOF + + if File.file?(".env") + inject_into_file ".env", spire_env_vars + else + create_file ".env", spire_env_vars + end + end + end + end + end + end +end diff --git a/lib/generators/templates/spire.rb b/lib/generators/templates/spire.rb new file mode 100644 index 0000000..0a46ee9 --- /dev/null +++ b/lib/generators/templates/spire.rb @@ -0,0 +1,7 @@ +Spire.configure do |config| + config.company = "company name" + config.username = "username" # Username of a user account within "company name" + config.password = "xxxxxxxx" # Password of that user + config.host = "example.com" # Location of your Spire server + config.port = "123" # Port of your Spire server +end From ebf0806dab4fa9d4df303282921ec7ff6e079754 Mon Sep 17 00:00:00 2001 From: Chris Francis Date: Fri, 15 Jul 2022 17:20:37 -0400 Subject: [PATCH 2/2] Update to match master --- Gemfile | 5 +- Gemfile.lock | 135 ++++++++++++++++----------------------------------- 2 files changed, 44 insertions(+), 96 deletions(-) diff --git a/Gemfile b/Gemfile index a55e2f0..3c8da79 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,6 @@ source "https://rubygems.org" -git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in spire.gemspec gemspec - -# lower rails version -gem "rails", "~> 4.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index d5dcfd3..2efd750 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - spire (3.3.0) + spire (3.11.0) activemodel (>= 3.2.0) json rest-client (>= 1.8.0) @@ -9,116 +9,68 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) - mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) - builder (3.1.4) - coderay (1.1.3) - concurrent-ruby (1.1.9) - diff-lcs (1.4.4) - docile (1.4.0) + activemodel (5.2.4.3) + activesupport (= 5.2.4.3) + activesupport (5.2.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + coderay (1.1.2) + concurrent-ruby (1.1.6) + diff-lcs (1.3) + docile (1.3.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - erubis (2.7.0) - factory_bot (4.11.1) + factory_bot (4.8.2) activesupport (>= 3.0.0) - faker (2.2.1) - i18n (>= 0.8) + faker (1.8.7) + i18n (>= 0.7) http-accept (1.7.0) http-cookie (1.0.4) domain_name (~> 0.5) - i18n (0.9.5) + i18n (1.5.1) concurrent-ruby (~> 1.0) - json (2.5.1) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (1.0.0) - mime-types (3.3.1) + json (2.3.1) + method_source (0.9.0) + mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) - mini_mime (1.1.0) - minitest (4.7.5) - multi_json (1.15.0) + mime-types-data (3.2022.0105) + minitest (5.14.1) netrc (0.11.0) - pry (0.14.1) - coderay (~> 1.1) - method_source (~> 1.0) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) - bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) - sprockets-rails (~> 2.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (13.0.3) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + rake (13.0.1) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - simplecov (0.21.2) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) + simplecov (0.16.1) docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) - simplecov_json_formatter (0.1.3) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - thor (1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) thread_safe (0.3.6) - tzinfo (0.3.60) + tzinfo (1.2.7) + thread_safe (~> 0.1) unf (0.1.4) unf_ext - unf_ext (0.0.7.7) + unf_ext (0.0.8) PLATFORMS ruby @@ -128,7 +80,6 @@ DEPENDENCIES factory_bot (~> 4.8) faker pry - rails (~> 4.0.0) rake (~> 13.0) rspec (~> 3.2) simplecov