worldpac_api 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c0ec2b4e23e80512b5ab3b2115ab6c425375b53
4
+ data.tar.gz: 3391c65990b97ef0728bf11c245589814aba46ee
5
+ SHA512:
6
+ metadata.gz: 9a15a1793001958b5b902b5d528720cd7ccc4efbc9e3cb643c00e8d511e3bf62fc7ae24ea02d947321372ae2480a19024f65843c989dd86e562d81e15ab0e956
7
+ data.tar.gz: fa0efdc9bfb294acdaaeeb184bb9f267d5751e16ec6f520cbd406952354a27f9a3ae92f503858962e8ac2a5f298159094a6fc8bd08d1aeed8656dac95abb7526
@@ -0,0 +1,54 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/YourMechanic/worldpac_api
5
+ parallelism: 1
6
+ shell: /bin/bash --login
7
+
8
+ environment:
9
+ CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
10
+ CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
11
+ docker:
12
+ - image: circleci/ruby:2.6.2
13
+ steps:
14
+ - checkout
15
+ - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
16
+ - restore_cache:
17
+ keys:
18
+ # This branch if available
19
+ - v2-dep-{{ .Branch }}-
20
+ # Default branch if not
21
+ - v2-dep-master-
22
+ # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
23
+ - v2-dep-
24
+ - run:
25
+ name: Install bundler for worldpac_api
26
+ working_directory: ~/YourMechanic/worldpac_api
27
+ command: gem install bundler:2.2.8
28
+ - run:
29
+ name: Install Gems for worldpac_api
30
+ working_directory: ~/YourMechanic/worldpac_api
31
+ command: bundle install
32
+ # Save dependency cache
33
+ - save_cache:
34
+ key: v2-dep-{{ .Branch }}-{{ epoch }}
35
+ paths:
36
+ - vendor/bundle
37
+ - ~/virtualenvs
38
+ - ~/.m2
39
+ - ~/.ivy2
40
+ - ~/.bundle
41
+ - run:
42
+ working_directory: ~/YourMechanic/worldpac_api
43
+ command: bundle exec rubocop
44
+ - run:
45
+ working_directory: ~/YourMechanic/worldpac_api
46
+ command: bundle exec rspec --colour --drb --profile -fd --format progress $(circleci tests glob "spec/*_spec.rb" | circleci tests split)
47
+ - store_test_results:
48
+ path: /tmp/circleci-test-results
49
+ - store_artifacts:
50
+ path: /tmp/circleci-artifacts
51
+ - store_artifacts:
52
+ path: /tmp/circleci-test-results
53
+ - store_artifacts:
54
+ path: worldpac_api/coverage
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,10 @@
1
+ example_id | status | run_time |
2
+ -------------------------------- | ------ | --------------- |
3
+ ./spec/worldpac_api_spec.rb[1:1] | passed | 0.00071 seconds |
4
+ ./spec/worldpac_api_spec.rb[1:2] | passed | 0.01615 seconds |
5
+ ./spec/worldpac_api_spec.rb[1:3] | passed | 0.0223 seconds |
6
+ ./spec/worldpac_api_spec.rb[1:4] | passed | 4.01 seconds |
7
+ ./spec/worldpac_api_spec.rb[1:5] | passed | 0.00731 seconds |
8
+ ./spec/worldpac_api_spec.rb[1:6] | passed | 0.00415 seconds |
9
+ ./spec/worldpac_api_spec.rb[1:7] | passed | 0.00367 seconds |
10
+ ./spec/worldpac_api_spec.rb[1:8] | passed | 0.00235 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-01-31 19:17:03 +0530 using RuboCop version 0.48.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 206
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
12
+ # SupportedStyles: single_quotes, double_quotes
13
+ Style/StringLiterals:
14
+ Exclude:
15
+ - 'spec/worldpac_api_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.8
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.8
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at Trupti.hosamani7@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in worldpac_util.gemspec
8
+ gemspec
9
+
10
+ group :test do
11
+ gem 'webmock'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ worldpac_api (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (5.2.6)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ addressable (2.8.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ ast (2.4.2)
17
+ bugsnag (2.0.3)
18
+ httparty (>= 0.6, < 1.0)
19
+ multi_json (~> 1.0)
20
+ concurrent-ruby (1.1.9)
21
+ crack (0.4.5)
22
+ rexml
23
+ diff-lcs (1.5.0)
24
+ domain_name (0.5.20190701)
25
+ unf (>= 0.0.5, < 1.0.0)
26
+ hashdiff (1.0.1)
27
+ http-accept (1.7.0)
28
+ http-cookie (1.0.4)
29
+ domain_name (~> 0.5)
30
+ httparty (0.16.2)
31
+ multi_xml (>= 0.5.2)
32
+ i18n (1.8.11)
33
+ concurrent-ruby (~> 1.0)
34
+ jaro_winkler (1.5.4)
35
+ mime-types (3.4.1)
36
+ mime-types-data (~> 3.2015)
37
+ mime-types-data (3.2021.1115)
38
+ mini_portile2 (2.3.0)
39
+ minitest (5.15.0)
40
+ multi_json (1.15.0)
41
+ multi_xml (0.6.0)
42
+ netrc (0.11.0)
43
+ nokogiri (1.8.5)
44
+ mini_portile2 (~> 2.3.0)
45
+ parallel (1.19.2)
46
+ parser (3.1.0.0)
47
+ ast (~> 2.4.1)
48
+ public_suffix (4.0.6)
49
+ rainbow (3.1.1)
50
+ rake (10.5.0)
51
+ rest-client (2.1.0)
52
+ http-accept (>= 1.7.0, < 2.0)
53
+ http-cookie (>= 1.0.2, < 2.0)
54
+ mime-types (>= 1.16, < 4.0)
55
+ netrc (~> 0.8)
56
+ rexml (3.2.5)
57
+ rspec (3.10.0)
58
+ rspec-core (~> 3.10.0)
59
+ rspec-expectations (~> 3.10.0)
60
+ rspec-mocks (~> 3.10.0)
61
+ rspec-core (3.10.1)
62
+ rspec-support (~> 3.10.0)
63
+ rspec-expectations (3.10.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.10.0)
66
+ rspec-mocks (3.10.2)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.10.0)
69
+ rspec-support (3.10.3)
70
+ rubocop (0.81.0)
71
+ jaro_winkler (~> 1.5.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.7.0.1)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ rexml
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (>= 1.4.0, < 2.0)
78
+ ruby-progressbar (1.11.0)
79
+ thread_safe (0.3.6)
80
+ tzinfo (1.2.9)
81
+ thread_safe (~> 0.1)
82
+ unf (0.1.4)
83
+ unf_ext
84
+ unf_ext (0.0.8)
85
+ unicode-display_width (1.8.0)
86
+ webmock (3.14.0)
87
+ addressable (>= 2.8.0)
88
+ crack (>= 0.3.2)
89
+ hashdiff (>= 0.4.0, < 2.0.0)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ activesupport
96
+ bugsnag (~> 2.0.0)
97
+ bundler (~> 1.17)
98
+ nokogiri (~> 1.8.2)
99
+ rake (~> 10.0)
100
+ rest-client (~> 2.1.0)
101
+ rspec (~> 3.0)
102
+ rubocop
103
+ webmock
104
+ worldpac_api!
105
+
106
+ BUNDLED WITH
107
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 YourMechanic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # WorldpacApi
2
+
3
+ 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/worldpac_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'worldpac_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install worldpac_api
22
+
23
+ ## Usage
24
+
25
+ After installing the gem create a file worldpac.rb in config/initializers with following content:
26
+
27
+ ```ruby
28
+ WorldpacApi.config do |c|
29
+ c.tomcat_domain = 'http://localhost:8080'
30
+ c.redis_config = { host: '127.0.0.1', timeout: 60, db: 1, password: nil }
31
+ c.wpc_login = '123456'
32
+ c.wpc_password = 'password'
33
+ c.wpc_login_url_invoice = 'http://sdbeta.worldpac.com/speeddial/orders/invoices.jsp'
34
+ c.wpc_url_tpl = 'http://sdbeta.worldpac.com/speeddial/orders/invoices.jsp?env=2010&range=0&fromDate=%{start}&throughDate=%{end}&comment=&invoice=&type=0&order=&name=&product='
35
+ c.wpc_download_url_combined = 'http://sdbeta.worldpac.com/speeddial/orders/download-invoicecombined.jsp?format=csv'
36
+ c.wpc_download_url_details = 'http://sdbeta.worldpac.com/speeddial/orders/download-invoicedetails.jsp?format=csv'
37
+
38
+ c.wpc_login_url_returns = 'http://sdbeta.worldpac.com/speeddial/pnaorder.jsp'
39
+ c.wpc_url_rma_search = 'http://sdbeta.worldpac.com/speeddial/ax/eligibleReturns.jsp?reasonCode=%{reason_code}&fromDate=%{start}&throughDate=%{end}&product=%{part_number}&invoiceNumber=&order=&comment='
40
+ c.wpc_url_rma_create = 'http://sdbeta.worldpac.com/speeddial/ax/createRma.jsp?index=0&invoiceNumber=%{invoice_number}&invoiceLineID=%{search_lineID}&createRMAQty=%{qty}&reasonCode=%{reason_code}&reasonText='
41
+ c.wpc_url_authorized_returns = 'http://sdbeta.worldpac.com/speeddial/ax/authorizedReturns.jsp'
42
+ c.wpc_main_orders_url = 'http://sdbeta.worldpac.com/speeddial/order.jsp?env=2010&order=76368991'
43
+ c.wpc_specific_orders_url = 'http://sdbeta.worldpac.com/speeddial/order.jsp?env=2010&order=%{order_num}'
44
+
45
+ c.wpc_rma_reason_not_needed = 'noreason'
46
+ c.wpc_rma_reason_core = 'corereason'
47
+
48
+ c.run_worldpac_api_locally = false;
49
+ c.max_tries = 3
50
+ c.max_delay = 32
51
+
52
+ c.invoice_details_keys = %w[
53
+ unit_net_price
54
+ unit_core_charge
55
+ description
56
+ list_price
57
+ ].freeze
58
+
59
+ c.required_invoice_keys = %w[
60
+ date
61
+ invoice
62
+ order_id
63
+ invoice_date
64
+ part_number
65
+ ].freeze
66
+ end
67
+ ```
68
+
69
+ to Create an Order
70
+ ```ruby
71
+ WorldpacApi.create_wpc_order(data)
72
+ ```
73
+
74
+ to Track Order
75
+ ```ruby
76
+ WorldpacApi.update_wpc_po_tracking('order_tracking_id', 'country')
77
+ ```
78
+
79
+ to Parts Search
80
+ ```ruby
81
+ WorldpacApi.search_wpc_part_by_number('PART_NUMBER', 'COUNTRY')
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/worldpac_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the WorldpacApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/worldpac_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+
10
+ require 'rubocop/rake_task'
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'worldpac_api'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorldpacApi
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,318 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'worldpac_api/version'
4
+ require 'nokogiri'
5
+ require 'cgi'
6
+ require 'bugsnag'
7
+ require 'rest-client'
8
+ require 'active_support/all'
9
+
10
+ # rubocop:disable Metrics/BlockLength
11
+ # rubocop:disable Metrics/LineLength
12
+ # rubocop:disable Metrics/MethodLength
13
+ # rubocop:disable Metrics/AbcSize
14
+ # rubocop:disable Metrics/ModuleLength
15
+ # rubocop:disable Metrics/CyclomaticComplexity
16
+ # rubocop:disable Metrics/PerceivedComplexity
17
+ # rubocop:disable Metrics/ParameterLists
18
+
19
+ # WorldpacApi
20
+ module WorldpacApi
21
+ class Error < StandardError; end
22
+
23
+ class << self
24
+ attr_accessor :redis_config, :tomcat_domain, :max_delay, :max_tries,
25
+ :wpc_login_url_invoice, :wpc_url_tpl,
26
+ :wpc_download_url_combined, :wpc_download_url_details,
27
+ :wpc_login_url_returns, :wpc_password, :wpc_login,
28
+ :wpc_url_rma_search, :wpc_url_rma_create, :wpc_url_authorized_returns,
29
+ :wpc_main_orders_url, :wpc_specific_orders_url,
30
+ :wpc_rma_reason_not_needed, :wpc_rma_reason_core, :run_worldpac_api_locally,
31
+ :invoice_details_keys, :required_invoice_keys
32
+
33
+ def config
34
+ yield self
35
+ end
36
+
37
+ def download_invoice(account_nums, wpc_supplier_id, supplier_id, date, days = 0)
38
+ invoices = []
39
+ account_numbers = [WorldpacApi.wpc_login]
40
+ account_numbers = account_nums if supplier_id == wpc_supplier_id
41
+ account_numbers.each_with_index do |account_number, idx|
42
+ execute_with_retry(raise_error: true) do |delay|
43
+ puts "#{idx + 1}: Downloading for Account: #{account_number}"
44
+ cookies = session_cookies(
45
+ WorldpacApi.wpc_login_url_invoice,
46
+ user_id: account_number,
47
+ delay: delay
48
+ )
49
+ page_url = format_url_wpc_invoice(date, days)
50
+ RestClient.get(page_url, cookies: cookies)
51
+ resp = RestClient.get(WorldpacApi.wpc_download_url_combined, headers: { 'Referer' => page_url }, cookies: cookies)
52
+ resp_details = RestClient.get(WorldpacApi.wpc_download_url_details, headers: { 'Referer' => page_url }, cookies: cookies)
53
+ body = resp.body.split("\n")
54
+ body_details = resp_details.body.split("\n")
55
+ next unless body || body_details
56
+
57
+ # this code is to cleanup the response into searchable array
58
+ clean_body_details = []
59
+ fields = body_details.shift.delete('"').split(',')
60
+ fields = fields.map { |f| f.downcase.tr(' ', '_') }
61
+ body_details.each do |b|
62
+ parsed_b = b.gsub('",', ';').delete('"').split(';')
63
+ clean_body_details << Hash[*fields.zip(parsed_b).flatten]
64
+ end
65
+
66
+ fields = body.shift.delete('"').split(',') + ['Unit Net Price', 'Unit Core Charge', 'Description', 'List Price']
67
+ fields = fields.map { |f| f.downcase.tr(' ', '_') }
68
+ unless WorldpacApi.required_invoice_keys.all? { |k| fields.include?(k) }
69
+ next
70
+ end
71
+
72
+ body.each do |b|
73
+ parsed_b = b.gsub('",', ';').delete('"').split(';') # #TODO: This is kind of retarded, need a better way to do this
74
+ invoice_hash = Hash[*fields.zip(parsed_b).flatten]
75
+ psearch = clean_body_details.find do |details_hash|
76
+ details_hash['invoice'] == invoice_hash['invoice'] &&
77
+ details_hash['part_number'] == invoice_hash['part_number']
78
+ end
79
+ if psearch
80
+ WorldpacApi.invoice_details_keys.each do |key|
81
+ invoice_hash[key] = psearch[key] if psearch[key]
82
+ end
83
+ end
84
+ invoice_hash['account_number'] = account_number
85
+ invoices << invoice_hash
86
+ end
87
+ end
88
+ end
89
+ invoices
90
+ end
91
+
92
+ def find_or_create_wpc_rma(order_code, account_number, invoice_num, reason_code, quantity, end_date, is_core_return)
93
+ return unless account_number
94
+
95
+ execute_with_retry do |delay|
96
+ cookies = session_cookies(
97
+ WorldpacApi.wpc_login_url_returns,
98
+ user_id: account_number,
99
+ delay: delay
100
+ )
101
+ start_date = end_date - 1.year
102
+ partnum = nil
103
+ if order_code
104
+ split_oc = order_code.split(':')
105
+ partnum = split_oc.length > 2 ? split_oc[2] : split_oc[0]
106
+ end
107
+ return unless invoice_num
108
+
109
+ page_url = format_url_rma_search(reason_code, start_date, end_date, partnum)
110
+ # query whether part is eligible for RMA
111
+ resp = RestClient.get(page_url, cookies: cookies)
112
+ return unless resp.code == 200
113
+
114
+ response = JSON.parse(resp.body)
115
+ # check for existing RMAs or create new RMA
116
+ if !response.is_a?(Array) && response['status'] == 'ERROR'
117
+ find_wpc_rma(partnum, invoice_num, cookies, is_core_return)
118
+ else
119
+ create_wpc_rma(partnum, invoice_num, cookies, response, reason_code, quantity)
120
+ end
121
+ end
122
+ end
123
+
124
+ def bulk_fetch_rmas(accounts)
125
+ response = []
126
+ account_numbers = [WorldpacApi.wpc_login]
127
+ account_numbers += accounts
128
+ account_numbers.each_with_index do |account_number, idx|
129
+ begin
130
+ puts "#{idx + 1}: Downloading for Account: #{account_number}"
131
+ cookies = session_cookies(
132
+ WorldpacApi.wpc_login_url_returns,
133
+ user_id: account_number,
134
+ delay: 2
135
+ )
136
+ resp = RestClient.get(WorldpacApi.wpc_url_authorized_returns, cookies: cookies)
137
+ response += JSON.parse(resp.body) if resp.code == 200
138
+ rescue StandardError => e
139
+ puts "#{e.message}\n#{e.backtrace.join("\n")}"
140
+ Bugsnag.notify(e.message)
141
+ end
142
+ end
143
+ response
144
+ end
145
+
146
+ def bulk_update_arrival_info(order_tracking_id)
147
+ execute_with_retry do |delay|
148
+ cookies = session_cookies(WorldpacApi.wpc_main_orders_url, delay: delay)
149
+ order_url = format(WorldpacApi.wpc_specific_orders_url, order_num: order_tracking_id)
150
+ html = RestClient.get(order_url, cookies: cookies)
151
+ doc = Nokogiri::HTML(html)
152
+ doc.xpath('//span[@class="truck-leave-time"]')
153
+ end
154
+ end
155
+
156
+ def update_wpc_po_tracking(order_tracking_id, country = nil)
157
+ url = tomcat_url('/YMWorldpacApi/orders/track', orderID: order_tracking_id,
158
+ country: country)
159
+ begin
160
+ result = RestClient.get(url)
161
+ result = JSON.parse(result.body)
162
+ if result&.include?('trackCodes') && !result['trackCodes'].empty?
163
+ tracking_codes = result['trackCodes']
164
+ end
165
+ if result&.include?('shippingStatus') && !result['shippingStatus'].empty?
166
+ shipping_status = result['shippingStatus']
167
+ end
168
+ { tracking_codes: tracking_codes, shipping_status: shipping_status }
169
+ rescue StandardError
170
+ Bugsnag.notify($ERROR_INFO)
171
+ end
172
+ end
173
+
174
+ def search_wpc_part_by_number(partnum, country)
175
+ res = nil
176
+ begin
177
+ res = RestClient.get(tomcat_url(
178
+ '/YMWorldpacApi/parts/search',
179
+ prodCode: partnum,
180
+ country: country
181
+ ))
182
+ return [] if res.code != 200
183
+
184
+ res = JSON.parse(res)
185
+ rescue StandardError
186
+ Bugsnag.notify($ERROR_INFO)
187
+ return []
188
+ end
189
+ res['quotes']
190
+ end
191
+
192
+ def create_wpc_order(data)
193
+ RestClient.post(tomcat_url('/YMWorldpacApi/orders/create'), JSON.generate(data))
194
+ end
195
+
196
+ private
197
+
198
+ def tomcat_url(url, params = nil)
199
+ params ||= {}
200
+ params[:db] = WorldpacApi.redis_config[:db] || 0
201
+ # params[:env] = Rails.env.production? ? "prod" : "stage"
202
+ params[:env] = 'stage'
203
+ params = params.map { |k, v| "#{k}=#{v}" }.join('&')
204
+ "#{WorldpacApi.tomcat_domain}#{url}?#{params}"
205
+ end
206
+
207
+ def execute_with_retry(raise_error: false)
208
+ tries = 0
209
+ delay = 0
210
+ begin
211
+ yield(delay)
212
+ rescue RestClient::Unauthorized => e
213
+ puts "#{e.message}\n#{e.backtrace.join("\n")}"
214
+ rescue StandardError => e
215
+ tries += 1
216
+ # retry with exponential backoff
217
+ if tries <= WorldpacApi.max_tries
218
+ exp_delay = Float(2**tries)
219
+ random_delay = rand(0..exp_delay)
220
+ max_exp_delay = exp_delay + random_delay
221
+ delay = [max_exp_delay, WorldpacApi.max_delay].min
222
+ if e.is_a?(RestClient::ServiceUnavailable)
223
+ delay = WorldpacApi.max_delay
224
+ end
225
+ puts "#{e.message}\n#{e.backtrace.join("\n")}\nRETRYING in #{delay} seconds..."
226
+ retry
227
+ else
228
+ Bugsnag.notify(e.message)
229
+ raise Error, e.message if raise_error
230
+ end
231
+ end
232
+ end
233
+
234
+ def format_url_rma_search(reason_code, start_date, end_date, part_number)
235
+ formatted_start_date = start_date.strftime('%Y%m%d')
236
+ formatted_end_date = end_date.strftime('%Y%m%d')
237
+ format(WorldpacApi.wpc_url_rma_search, reason_code: reason_code, start: formatted_start_date, end: formatted_end_date, part_number: part_number)
238
+ end
239
+
240
+ def session_cookies(login_url, opts = {})
241
+ user_id = opts[:user_id] || WorldpacApi.wpc_login
242
+ data = {
243
+ 'user': user_id,
244
+ 'password': opts[:password] || WorldpacApi.wpc_password,
245
+ 'submit': 'Login',
246
+ 'remember': 'on',
247
+ 'offset': '0'
248
+ }
249
+ # Slight delay to avoid throttling/timeouts
250
+ sleep(opts[:delay]) if opts[:delay]
251
+ resp = RestClient.post(login_url, data)
252
+ j_session_id = resp.code >= 200 && resp.code < 300 ? resp.cookies['JSESSIONID'] : nil
253
+ cookies = {
254
+ 'JSESSIONID' => j_session_id,
255
+ 'sdx-user-settings' => user_id,
256
+ 'sdx-save-user-id' => 'true'
257
+ }
258
+ cookies
259
+ end
260
+
261
+ def format_url_wpc_invoice(from_date, days)
262
+ d0 = from_date.strftime('%-m/%-d/%y')
263
+ d1 = (from_date + days.day).strftime('%-m/%-d/%y')
264
+ start_d = CGI.escape d0
265
+ end_d = CGI.escape d1
266
+ format(WorldpacApi.wpc_url_tpl, start: start_d, end: end_d)
267
+ end
268
+
269
+ def find_wpc_rma(partnum, invoice_num, cookies, is_core_return)
270
+ execute_with_retry do
271
+ resp = RestClient.get(WorldpacApi.wpc_url_authorized_returns, cookies: cookies)
272
+ return if resp.code != 200
273
+
274
+ response = JSON.parse(resp.body)
275
+ part = if is_core_return
276
+ response.find do |x|
277
+ x['productID'] == partnum &&
278
+ x['invoiceNumber'] == invoice_num &&
279
+ x['returnReasonCode'] == WorldpacApi.wpc_rma_reason_core
280
+ end
281
+ else
282
+ response.find do |x|
283
+ x['productID'] == partnum &&
284
+ x['invoiceNumber'] == invoice_num
285
+ end
286
+ end
287
+ return if !part || part['rmaNumber'].blank?
288
+
289
+ part
290
+ end
291
+ end
292
+
293
+ def create_wpc_rma(partnum, invoice_num, cookies, responseq, reason_code, quantity)
294
+ execute_with_retry do
295
+ part = responseq.find { |x| x['productID'] == partnum && x['invoiceNumber'] == invoice_num }
296
+ return unless part
297
+
298
+ # create new RMA
299
+ rma_url = format(WorldpacApi.wpc_url_rma_create, reason_code: reason_code, invoice_number: invoice_num, search_lineID: part['invoiceLineID'], qty: quantity)
300
+ resp = RestClient.get(rma_url, cookies: cookies)
301
+ response = JSON.parse(resp.body)
302
+ if resp.code == 200 && response['status'] == 'OK'
303
+ return response['authorizedReturn']['rmaNumber'].strip
304
+ end
305
+
306
+ return nil
307
+ end
308
+ end
309
+ end
310
+ end
311
+ # rubocop:enable Metrics/BlockLength
312
+ # rubocop:enable Metrics/LineLength
313
+ # rubocop:enable Metrics/MethodLength
314
+ # rubocop:enable Metrics/AbcSize
315
+ # rubocop:enable Metrics/ModuleLength
316
+ # rubocop:enable Metrics/CyclomaticComplexity
317
+ # rubocop:enable Metrics/PerceivedComplexity
318
+ # rubocop:enable Metrics/ParameterLists
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/LineLength
4
+
5
+ lib = File.expand_path('lib', __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'worldpac_api/version'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'worldpac_api'
11
+ spec.version = WorldpacApi::VERSION
12
+ spec.authors = ['TruptiHosmani']
13
+ spec.email = ['dev@yourmechanic.com']
14
+
15
+ spec.summary = 'Gem to integrate Worldpac to manage Parts Ordering'
16
+ spec.description = 'Worldpac Gem to manage Parts Ordering & Returns'
17
+ spec.homepage = 'https://github.com/YourMechanic/worldpac_api'
18
+ spec.license = 'MIT'
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set
21
+ # the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing
23
+ # to any host.
24
+ if spec.respond_to?(:metadata)
25
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
26
+
27
+ spec.metadata['homepage_uri'] = spec.homepage
28
+ spec.metadata['source_code_uri'] = 'https://github.com/YourMechanic/worldpac_api'
29
+ spec.metadata['changelog_uri'] = 'https://github.com/YourMechanic/worldpac_api'
30
+ else
31
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
32
+ 'public gem pushes.'
33
+ end
34
+
35
+ # Specify which files should be added to the gem when it is released.
36
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
37
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
38
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
39
+ end
40
+ spec.bindir = 'exe'
41
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
42
+ spec.require_paths = ['lib']
43
+
44
+ spec.add_development_dependency 'activesupport'
45
+ spec.add_development_dependency 'bugsnag', '~> 2.0.0'
46
+ spec.add_development_dependency 'bundler', '~> 1.17'
47
+ spec.add_development_dependency 'nokogiri', '~> 1.8.2'
48
+ spec.add_development_dependency 'rake', '~> 10.0'
49
+ spec.add_development_dependency 'rest-client', '~> 2.1.0'
50
+ spec.add_development_dependency 'rspec', '~> 3.0'
51
+ spec.add_development_dependency 'rubocop'
52
+ end
53
+ # rubocop:enable Metrics/LineLength
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worldpac_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - TruptiHosmani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bugsnag
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Worldpac Gem to manage Parts Ordering & Returns
126
+ email:
127
+ - dev@yourmechanic.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".circleci/config.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rspec_status"
136
+ - ".rubocop.yml"
137
+ - ".rubocop_todo.yml"
138
+ - ".ruby-version"
139
+ - ".travis.yml"
140
+ - CODE_OF_CONDUCT.md
141
+ - Gemfile
142
+ - Gemfile.lock
143
+ - LICENSE
144
+ - README.md
145
+ - Rakefile
146
+ - bin/console
147
+ - bin/setup
148
+ - lib/worldpac_api.rb
149
+ - lib/worldpac_api/version.rb
150
+ - worldpac_api.gemspec
151
+ homepage: https://github.com/YourMechanic/worldpac_api
152
+ licenses:
153
+ - MIT
154
+ metadata:
155
+ allowed_push_host: https://rubygems.org
156
+ homepage_uri: https://github.com/YourMechanic/worldpac_api
157
+ source_code_uri: https://github.com/YourMechanic/worldpac_api
158
+ changelog_uri: https://github.com/YourMechanic/worldpac_api
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.5.2.3
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Gem to integrate Worldpac to manage Parts Ordering
179
+ test_files: []