dhl_ecommerce_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6997d6fa361fe163afb7ce2d69325ad6cd20f8d3902cbc6b51c891b910766160
4
+ data.tar.gz: 231ba82b1d8507a15b1b3e4883451473ddd8d431726aece3c755d5ff523a7b9d
5
+ SHA512:
6
+ metadata.gz: 30db0bcf3d8c54f66923af39e39f38996a7de36943d4834fd20ee716dd915a2cd84f147bfd589e8644fc1e7381190e59b3b7c25b97d2753bb2a13c8901a76a31
7
+ data.tar.gz: '08607e7d379b167cd469f43a4bded2606b4dedc6994bc5a8f24fe40f094c6c9d1a68ca9dd04afdbea091a5afb84d7a7e908535150aad8277207d2cb377e8d681'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-02-14
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at erwhey@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dhl_ecommerce_api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem "webmock"
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dhl_ecommerce_api (0.1.0)
5
+ activeresource (>= 4.1.0, < 6.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.1.4.6)
11
+ activesupport (= 6.1.4.6)
12
+ activemodel-serializers-xml (1.0.2)
13
+ activemodel (> 5.x)
14
+ activesupport (> 5.x)
15
+ builder (~> 3.1)
16
+ activeresource (5.1.1)
17
+ activemodel (>= 5.0, < 7)
18
+ activemodel-serializers-xml (~> 1.0)
19
+ activesupport (>= 5.0, < 7)
20
+ activesupport (6.1.4.6)
21
+ concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ tzinfo (~> 2.0)
25
+ zeitwerk (~> 2.3)
26
+ addressable (2.8.0)
27
+ public_suffix (>= 2.0.2, < 5.0)
28
+ ast (2.4.2)
29
+ builder (3.2.4)
30
+ coderay (1.1.3)
31
+ concurrent-ruby (1.1.9)
32
+ crack (0.4.5)
33
+ rexml
34
+ diff-lcs (1.5.0)
35
+ dotenv (2.7.6)
36
+ ffi (1.15.5)
37
+ formatador (1.1.0)
38
+ gem-release (2.2.2)
39
+ guard (2.18.0)
40
+ formatador (>= 0.2.4)
41
+ listen (>= 2.7, < 4.0)
42
+ lumberjack (>= 1.0.12, < 2.0)
43
+ nenv (~> 0.1)
44
+ notiffany (~> 0.0)
45
+ pry (>= 0.13.0)
46
+ shellany (~> 0.0)
47
+ thor (>= 0.18.1)
48
+ guard-compat (1.2.1)
49
+ guard-rspec (4.7.3)
50
+ guard (~> 2.1)
51
+ guard-compat (~> 1.1)
52
+ rspec (>= 2.99.0, < 4.0)
53
+ hashdiff (1.0.1)
54
+ i18n (1.10.0)
55
+ concurrent-ruby (~> 1.0)
56
+ listen (3.7.1)
57
+ rb-fsevent (~> 0.10, >= 0.10.3)
58
+ rb-inotify (~> 0.9, >= 0.9.10)
59
+ lumberjack (1.2.8)
60
+ method_source (1.0.0)
61
+ minitest (5.15.0)
62
+ nenv (0.3.0)
63
+ notiffany (0.1.3)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ parallel (1.21.0)
67
+ parser (3.1.0.0)
68
+ ast (~> 2.4.1)
69
+ pry (0.14.1)
70
+ coderay (~> 1.1)
71
+ method_source (~> 1.0)
72
+ public_suffix (4.0.6)
73
+ rainbow (3.1.1)
74
+ rake (13.0.6)
75
+ rb-fsevent (0.11.1)
76
+ rb-inotify (0.10.1)
77
+ ffi (~> 1.0)
78
+ regexp_parser (2.2.1)
79
+ rexml (3.2.5)
80
+ rspec (3.11.0)
81
+ rspec-core (~> 3.11.0)
82
+ rspec-expectations (~> 3.11.0)
83
+ rspec-mocks (~> 3.11.0)
84
+ rspec-core (3.11.0)
85
+ rspec-support (~> 3.11.0)
86
+ rspec-expectations (3.11.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.11.0)
89
+ rspec-mocks (3.11.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.11.0)
92
+ rspec-support (3.11.0)
93
+ rubocop (1.25.1)
94
+ parallel (~> 1.10)
95
+ parser (>= 3.1.0.0)
96
+ rainbow (>= 2.2.2, < 4.0)
97
+ regexp_parser (>= 1.8, < 3.0)
98
+ rexml
99
+ rubocop-ast (>= 1.15.1, < 2.0)
100
+ ruby-progressbar (~> 1.7)
101
+ unicode-display_width (>= 1.4.0, < 3.0)
102
+ rubocop-ast (1.15.2)
103
+ parser (>= 3.0.1.1)
104
+ rubocop-performance (1.13.2)
105
+ rubocop (>= 1.7.0, < 2.0)
106
+ rubocop-ast (>= 0.4.0)
107
+ ruby-progressbar (1.11.0)
108
+ shellany (0.0.1)
109
+ standard (1.7.2)
110
+ rubocop (= 1.25.1)
111
+ rubocop-performance (= 1.13.2)
112
+ thor (1.2.1)
113
+ tzinfo (2.0.4)
114
+ concurrent-ruby (~> 1.0)
115
+ unicode-display_width (2.1.0)
116
+ webmock (3.14.0)
117
+ addressable (>= 2.8.0)
118
+ crack (>= 0.3.2)
119
+ hashdiff (>= 0.4.0, < 2.0.0)
120
+ zeitwerk (2.5.4)
121
+
122
+ PLATFORMS
123
+ arm64-darwin-21
124
+
125
+ DEPENDENCIES
126
+ dhl_ecommerce_api!
127
+ dotenv
128
+ gem-release
129
+ guard-rspec
130
+ pry (~> 0.14.1)
131
+ rake (~> 13.0)
132
+ rspec (~> 3.0)
133
+ rubocop (~> 1.21)
134
+ standard
135
+ webmock
136
+
137
+ BUNDLED WITH
138
+ 2.3.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Er Whey
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # DHLEcommerceAPI
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/dhl_ecommerce_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 'dhl_ecommerce_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dhl_ecommerce_api
22
+
23
+ ## Configuration
24
+ In `config/initializers` create a `dhl_ecommerce_api.rb` config file
25
+ ```ruby
26
+ DHLEcommerceAPI.configure do |config|
27
+ config.env = ENV["DHL_ECOMMERCE_API_ENV"]
28
+ config.client_id = ENV["DHL_ECOMMERCE_API_CLIENT_ID"]
29
+ config.password = ENV["DHL_ECOMMERCE_API_PASSWORD"]
30
+ end
31
+ ```
32
+ ## Usage
33
+ ### Create Shipment
34
+ ```ruby
35
+ DHLEcommerceAPI::Shipment.create(params)
36
+ ```
37
+ ### Create Pickup
38
+ ```ruby
39
+ DHLEcommerceAPI::Pickup.create(params)
40
+ ```
41
+
42
+ ### Tracking
43
+ ```ruby
44
+ DHLEcommerceAPI::Tracking.track(array_of_string_tracking_numbers)
45
+ ```
46
+
47
+
48
+ ## Development
49
+
50
+ 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.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dhl_ecommerce_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]/dhl_ecommerce_api/blob/master/CODE_OF_CONDUCT.md).
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the DHLEcommerceAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dhl_ecommerce_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/lib/dev/config.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "dotenv/load"
2
+
3
+ def set_config
4
+ DHLEcommerceAPI.configure do |config|
5
+ config.client_id = ENV["DHL_ECOMMERCE_API_CLIENT_ID"]
6
+ config.password = ENV["DHL_ECOMMERCE_API_PASSWORD"]
7
+ config.pickup_account_id = ENV["DHL_ECOMMERCE_API_PICKUP_ACCOUNT_ID"]
8
+ config.sold_to_account_id = ENV["DHL_ECOMMERCE_API_SOLD_TO_ACCOUNT_ID"]
9
+ config.env = ENV["DHL_ECOMMERCE_API_ENV"] || "sandbox"
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require "zeitwerk"
2
+ require_relative "config"
3
+
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.inflector.inflect(
6
+ "dhl_ecommerce_api" => "DHLEcommerceAPI"
7
+ )
8
+ loader.push_dir("./lib")
9
+ loader.collapse("./lib/dhl_ecommerce_api/resources")
10
+ loader.ignore("#{__dir__}/config.rb")
11
+ loader.ignore("./lib/dhl_ecommerce_api/cache.rb")
12
+ loader.enable_reloading
13
+ # loader.log!
14
+ loader.setup
15
+
16
+ $__hermes_api_loader__ = loader
17
+
18
+ def reload!
19
+ $__hermes_api_loader__.reload
20
+ set_config
21
+ true
22
+ end
@@ -0,0 +1,5 @@
1
+ module DHLEcommerceAPI
2
+ mattr_accessor :cache
3
+
4
+ self.cache = ActiveSupport::Cache::MemoryStore.new
5
+ end
@@ -0,0 +1,51 @@
1
+ module DHLEcommerceAPI
2
+ class Configuration
3
+ attr_accessor :client_id, :password, :env, :pickup_account_id, :sold_to_account_id, :env
4
+ end
5
+
6
+ PRODUCTION_SITE = "#"
7
+ PRE_PRODUCTION_SITE = "https://apitest.dhlecommerce.asia"
8
+ SANDBOX_SITE = "https://sandbox.dhlecommerce.asia"
9
+
10
+ class << self
11
+ def config
12
+ @config ||= Configuration.new
13
+ end
14
+
15
+ def after_configure
16
+ site = get_url(config.env)
17
+
18
+ if defined?(Rails) &&
19
+ # set cache
20
+ if Rails.respond_to?(:cache) && Rails.cache.is_a?(ActiveSupport::Cache::Store)
21
+ DHLEcommerceAPI.cache = Rails.cache
22
+ end
23
+ # set env if defined
24
+ if Rails.respond_to?(:env)
25
+ site = get_url(Rails.env)
26
+ end
27
+ end
28
+
29
+ DHLEcommerceAPI::Base.site = site
30
+ DHLEcommerceAPI::Authentication.site = site
31
+ end
32
+
33
+ def get_url(env)
34
+ case env
35
+ when "production"
36
+ PRODUCTION_SITE
37
+ when "staging"
38
+ PRE_PRODUCTION_SITE
39
+ when "preproduction"
40
+ PRE_PRODUCTION_SITE
41
+ else
42
+ SANDBOX_SITE
43
+ end
44
+ end
45
+
46
+ def configure
47
+ yield config
48
+ after_configure
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ module DHLEcommerceAPI
2
+ class Connection < ActiveResource::Connection
3
+ def request(method, path, *arguments)
4
+ result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
5
+ payload[:method] = method
6
+ payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
7
+ payload[:result] = http.send(method, path, *arguments)
8
+ # debug outgoing request here if needed
9
+ end
10
+
11
+ handle_response(result)
12
+ rescue Timeout::Error => e
13
+ raise TimeoutError.new(e.message)
14
+ rescue OpenSSL::SSL::SSLError => e
15
+ raise SSLError.new(e.message)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module DHLEcommerceAPI
2
+ class Authentication < ActiveResource::Base
3
+ # self.prefix set in configuration.rb
4
+ def self.get_token
5
+ token = DHLEcommerceAPI.cache.read("DHLEcommerceAPI::AuthenticationToken")
6
+ if token.present?
7
+ return token
8
+ else
9
+ path = "/rest/v1/OAuth/AccessToken?clientId=#{DHLEcommerceAPI.config.client_id}&password=#{DHLEcommerceAPI.config.password}&returnFormat=json"
10
+ response = connection.get(path)
11
+ response_body = JSON.parse(response.body)["accessTokenResponse"]
12
+ DHLEcommerceAPI.cache.write("DHLEcommerceAPI::AuthenticationToken", response_body["token"], {expires_in: 12.hours})
13
+ return response_body["token"]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,80 @@
1
+ module DHLEcommerceAPI
2
+ class Base < ActiveResource::Base
3
+ # info returned - delivery_confirmation_no, delivery_depot_code, primary_sort_code, secondary_sort_code
4
+
5
+ self.include_format_in_path = false
6
+ self.connection_class = Connection
7
+
8
+ # by default convert to lowerCamelcase before sending request
9
+ def to_json(options = {})
10
+ attributes.as_json
11
+ .deep_transform_keys { |k| k.to_s.camelize(:lower) }
12
+ .to_json(include_root_in_json ? { root: self.class.element_name }.merge(options) : options)
13
+ end
14
+
15
+ # by default convert to snake_case when initializing
16
+ def load(attributes, remove_root = false, persisted = false)
17
+ # convert loaded attributes to underscore, then symbolize
18
+ attributes.deep_transform_keys! { |k| k.to_s.underscore.to_sym }
19
+
20
+ # merge default_attrs(symbols) with incoming attributes
21
+ if defined?(self.class::DEFAULT_ATTRIBUTES)
22
+ attributes = self.class::DEFAULT_ATTRIBUTES.merge(attributes)
23
+ end
24
+ super
25
+ end
26
+
27
+
28
+ def attributes_with_account_ids
29
+ account_ids.merge(attributes)
30
+ end
31
+
32
+ def account_ids
33
+ {
34
+ pickup_account_id: DHLEcommerceAPI.config.pickup_account_id,
35
+ sold_to_account_id: DHLEcommerceAPI.config.sold_to_account_id,
36
+ }
37
+ end
38
+
39
+ def handle_errors(code, error_messages)
40
+ errors.add(:base, "#{code} - #{error_messages.join(", ")}")
41
+ end
42
+
43
+ # Since request_data isnt the same as object attributes.
44
+ # We have to write our own method to format the request data
45
+ def formatted_request_data(request_data)
46
+ request_data.as_json
47
+ .deep_transform_keys {|key| custom_key_format(key)}.to_json
48
+ end
49
+
50
+ # custom keys that arent following lowerCamel convention
51
+ def custom_key_format(key)
52
+ case key
53
+ when "shipment_id"
54
+ "shipmentID"
55
+ when "total_weight_uom"
56
+ "totalWeightUOM"
57
+ when "dimension_uom"
58
+ "dimensionUOM"
59
+ when "order_url"
60
+ "orderURL"
61
+ when "location_id"
62
+ "locationID"
63
+ when "piece_id"
64
+ "pieceID"
65
+ when "weight_uom"
66
+ "weightUOM"
67
+ when "marketplace_url"
68
+ "marketplaceURL"
69
+ when "handover_id"
70
+ "handoverID"
71
+ when "email_id"
72
+ "emailID"
73
+ when "e_pod_required"
74
+ "ePODRequired"
75
+ else
76
+ key.to_s.camelize(:lower)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ module DHLEcommerceAPI
2
+ class Event < Base
3
+ STATUS_CODES = {
4
+ "71005": "awaiting_parcel_handover_to_dhl_data_submitted",
5
+ "77123": "awaiting_parcel_handover_to_dhl_shipment_data_received",
6
+ "77206": "shipment_picked_up",
7
+ "77015": "processed_at_facility",
8
+ "77027": "sorted_to_delivery_facility",
9
+ "77169": "departed_from_facility",
10
+ "77178": "arrived_at_facility",
11
+ "77184": "processed_at_delivery_facility",
12
+ "77090": "out_for_delivery",
13
+ "77093": "successfully_delivered",
14
+ }
15
+
16
+ def initialize(attributes = {}, persisted = false)
17
+ super
18
+ end
19
+
20
+ def status_slug
21
+ binding.pry
22
+ STATUS_CODES[status.to_sym]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ module DHLEcommerceAPI
2
+ class Pickup::HandoverItem < Base
3
+ def initialize(attributes = {}, persisted = false)
4
+ status = attributes["response_status"]
5
+ if status.present? && status["code"] != "200"
6
+ error_messages = status["message_details"].map{|err| err["message_detail"]}
7
+ handle_errors(status["code"], error_messages)
8
+ end
9
+ super
10
+ end
11
+ end
12
+ end