dhl_ecommerce_eu 0.1.3

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: cd73619df6578e9cc4411da701aad748c4c5e046b0a67827a3c9a40c5399a905
4
+ data.tar.gz: af8ed93db04dfe22d83d2341ef53388513fb3f22eeac4c6f68397cc35f2a6207
5
+ SHA512:
6
+ metadata.gz: a19fb08ea8adbb004d5688539ecf4f15f2818d026ea7abe31634b1dbc96e60ec3875df2b0c23ba3dcf8e20b338a5f6f45e791d4468e53f41d835f4fe64782b07
7
+ data.tar.gz: a137a4ea6edb6b134f83f8f550ca1f75243c460abf5024cac83abdd2187a61d46d97f2a18514f1bd4d289acf36f074077c166af45c5028f5b8b1e4470858e551
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-10
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 andygg1996personal@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_eu.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,177 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dhl_ecommerce_eu (0.1.0)
5
+ activesupport (>= 4.0.2)
6
+ http (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.1.0)
12
+ base64
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ mutex_m
20
+ tzinfo (~> 2.0)
21
+ addressable (2.8.5)
22
+ public_suffix (>= 2.0.2, < 6.0)
23
+ ast (2.4.2)
24
+ base64 (0.1.1)
25
+ bigdecimal (3.1.4)
26
+ byebug (11.1.3)
27
+ coderay (1.1.3)
28
+ concurrent-ruby (1.2.2)
29
+ connection_pool (2.4.1)
30
+ diff-lcs (1.5.0)
31
+ domain_name (0.5.20190701)
32
+ unf (>= 0.0.5, < 1.0.0)
33
+ dotenv (2.8.1)
34
+ drb (2.1.1)
35
+ ruby2_keywords
36
+ ffi (1.16.3)
37
+ ffi-compiler (1.0.1)
38
+ ffi (>= 1.0.0)
39
+ rake
40
+ formatador (1.1.0)
41
+ gem-release (2.2.2)
42
+ guard (2.18.1)
43
+ formatador (>= 0.2.4)
44
+ listen (>= 2.7, < 4.0)
45
+ lumberjack (>= 1.0.12, < 2.0)
46
+ nenv (~> 0.1)
47
+ notiffany (~> 0.0)
48
+ pry (>= 0.13.0)
49
+ shellany (~> 0.0)
50
+ thor (>= 0.18.1)
51
+ guard-compat (1.2.1)
52
+ guard-rspec (4.7.3)
53
+ guard (~> 2.1)
54
+ guard-compat (~> 1.1)
55
+ rspec (>= 2.99.0, < 4.0)
56
+ http (5.1.1)
57
+ addressable (~> 2.8)
58
+ http-cookie (~> 1.0)
59
+ http-form_data (~> 2.2)
60
+ llhttp-ffi (~> 0.4.0)
61
+ http-cookie (1.0.5)
62
+ domain_name (~> 0.5)
63
+ http-form_data (2.3.0)
64
+ httplog (1.6.2)
65
+ rack (>= 2.0)
66
+ rainbow (>= 2.0.0)
67
+ i18n (1.14.1)
68
+ concurrent-ruby (~> 1.0)
69
+ json (2.6.3)
70
+ language_server-protocol (3.17.0.3)
71
+ lint_roller (1.1.0)
72
+ listen (3.8.0)
73
+ rb-fsevent (~> 0.10, >= 0.10.3)
74
+ rb-inotify (~> 0.9, >= 0.9.10)
75
+ llhttp-ffi (0.4.0)
76
+ ffi-compiler (~> 1.0)
77
+ rake (~> 13.0)
78
+ lumberjack (1.2.9)
79
+ method_source (1.0.0)
80
+ minitest (5.20.0)
81
+ mutex_m (0.1.2)
82
+ nenv (0.3.0)
83
+ notiffany (0.1.3)
84
+ nenv (~> 0.1)
85
+ shellany (~> 0.0)
86
+ parallel (1.23.0)
87
+ parser (3.2.2.4)
88
+ ast (~> 2.4.1)
89
+ racc
90
+ pry (0.14.2)
91
+ coderay (~> 1.1)
92
+ method_source (~> 1.0)
93
+ pry-byebug (3.10.1)
94
+ byebug (~> 11.0)
95
+ pry (>= 0.13, < 0.15)
96
+ public_suffix (5.0.3)
97
+ racc (1.7.1)
98
+ rack (3.0.8)
99
+ rainbow (3.1.1)
100
+ rake (13.0.6)
101
+ rb-fsevent (0.11.2)
102
+ rb-inotify (0.10.1)
103
+ ffi (~> 1.0)
104
+ regexp_parser (2.8.1)
105
+ rexml (3.2.6)
106
+ rspec (3.12.0)
107
+ rspec-core (~> 3.12.0)
108
+ rspec-expectations (~> 3.12.0)
109
+ rspec-mocks (~> 3.12.0)
110
+ rspec-core (3.12.2)
111
+ rspec-support (~> 3.12.0)
112
+ rspec-expectations (3.12.3)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.12.0)
115
+ rspec-mocks (3.12.6)
116
+ diff-lcs (>= 1.2.0, < 2.0)
117
+ rspec-support (~> 3.12.0)
118
+ rspec-support (3.12.1)
119
+ rubocop (1.56.4)
120
+ base64 (~> 0.1.1)
121
+ json (~> 2.3)
122
+ language_server-protocol (>= 3.17.0)
123
+ parallel (~> 1.10)
124
+ parser (>= 3.2.2.3)
125
+ rainbow (>= 2.2.2, < 4.0)
126
+ regexp_parser (>= 1.8, < 3.0)
127
+ rexml (>= 3.2.5, < 4.0)
128
+ rubocop-ast (>= 1.28.1, < 2.0)
129
+ ruby-progressbar (~> 1.7)
130
+ unicode-display_width (>= 2.4.0, < 3.0)
131
+ rubocop-ast (1.29.0)
132
+ parser (>= 3.2.1.0)
133
+ rubocop-performance (1.19.1)
134
+ rubocop (>= 1.7.0, < 2.0)
135
+ rubocop-ast (>= 0.4.0)
136
+ ruby-progressbar (1.13.0)
137
+ ruby2_keywords (0.0.5)
138
+ shellany (0.0.1)
139
+ standard (1.31.1)
140
+ language_server-protocol (~> 3.17.0.2)
141
+ lint_roller (~> 1.0)
142
+ rubocop (~> 1.56.2)
143
+ standard-custom (~> 1.0.0)
144
+ standard-performance (~> 1.2)
145
+ standard-custom (1.0.2)
146
+ lint_roller (~> 1.0)
147
+ rubocop (~> 1.50)
148
+ standard-performance (1.2.0)
149
+ lint_roller (~> 1.1)
150
+ rubocop-performance (~> 1.19.0)
151
+ thor (1.2.2)
152
+ tzinfo (2.0.6)
153
+ concurrent-ruby (~> 1.0)
154
+ unf (0.1.4)
155
+ unf_ext
156
+ unf_ext (0.0.8.2)
157
+ unicode-display_width (2.5.0)
158
+ zeitwerk (2.6.12)
159
+
160
+ PLATFORMS
161
+ arm64-darwin-21
162
+
163
+ DEPENDENCIES
164
+ dhl_ecommerce_eu!
165
+ dotenv
166
+ gem-release
167
+ guard-rspec
168
+ httplog
169
+ pry
170
+ pry-byebug
171
+ rake (~> 13.0)
172
+ rspec (~> 3.0)
173
+ standard (~> 1.3)
174
+ zeitwerk
175
+
176
+ BUNDLED WITH
177
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Andy Chong
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,43 @@
1
+ # DHLEcommerceEU
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_eu`. 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_eu'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dhl_ecommerce_eu
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dhl_ecommerce_eu. 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_eu/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the DHLEcommerceEU project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dhl_ecommerce_eu/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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 "standard/rake"
9
+
10
+ task default: %i[spec standard]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pry'
5
+ require 'bundler/setup'
6
+ require 'dotenv/load'
7
+ require 'dev/zeitwerk_loader'
8
+ require 'dhl_ecommerce_eu'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ require 'pry'
14
+ Pry.start
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,19 @@
1
+ require 'zeitwerk'
2
+
3
+ loader = Zeitwerk::Loader.for_gem
4
+ loader.inflector.inflect(
5
+ 'dhl_ecommerce_eu' => 'DHLEcommerceEU'
6
+ )
7
+ loader.push_dir('./lib')
8
+ loader.collapse('./lib/dhl_ecommerce_eu/objects')
9
+ loader.ignore("#{__dir__}/../dhl_ecommerce_eu/cache.rb")
10
+ loader.enable_reloading
11
+ loader.log!
12
+ loader.setup
13
+
14
+ $__dhl_ecommerce_eu_loader__ = loader
15
+
16
+ def reload!
17
+ $__dhl_ecommerce_eu_loader__.reload
18
+ true
19
+ end
@@ -0,0 +1,5 @@
1
+ module DHLEcommerceEU
2
+ def self.cache
3
+ @cache ||= defined?(Rails) ? Rails.cache : ActiveSupport::Cache::MemoryStore.new
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ module DHLEcommerceEU
2
+ class Client
3
+ TEST_URL_BASE = 'https://api-sandbox.dhl.com/'
4
+ PROD_URL_BASE = 'https://api.dhl.com/'
5
+
6
+ attr_reader :url_base
7
+
8
+ def initialize(client_id, client_secret, env = nil)
9
+ @client_id = client_id
10
+ @client_secret = client_secret
11
+ @url_base = if env.nil? && defined?(Rails) && Rails.env.production?
12
+ PROD_URL_BASE
13
+ else
14
+ env == :production ? PROD_URL_BASE : TEST_URL_BASE
15
+ end
16
+ end
17
+
18
+ def connection
19
+ @connection ||= HTTP.headers(content_type: 'application/json', accept: 'application/json')
20
+ .auth("Bearer #{bearer_token}")
21
+ .timeout(10)
22
+ end
23
+
24
+ def shipment
25
+ ShipmentResource.new(self)
26
+ end
27
+
28
+ def label
29
+ LabelResource.new(self)
30
+ end
31
+
32
+ def tracking
33
+ TrackingResource.new(self)
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :client_id, :client_secret
39
+
40
+ def bearer_token
41
+ cache_key = "DHLEcommerceEU-session-#{Digest::SHA256.hexdigest("#{client_id}#{client_secret}")}"
42
+ cached_token = DHLEcommerceEU.cache.read(cache_key)
43
+ return cached_token if cached_token
44
+
45
+ client = HTTP.headers(content_type: 'application/json', accept: 'application/json')
46
+ .basic_auth(user: client_id, pass: client_secret)
47
+ response = client.get("#{url_base}ccc/v1/auth/accesstoken").parse
48
+ bearer_token = response['access_token']
49
+ DHLEcommerceEU.cache.write(cache_key, bearer_token, expires_in: response['expires_in'] - 60)
50
+ bearer_token
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ module DHLEcommerceEU
2
+ class BaseObject < OpenStruct
3
+ attr_reader :attributes
4
+
5
+ def initialize(attributes = {})
6
+ @attributes = attributes
7
+ ostruct = to_ostruct(attributes)
8
+ ostruct = ostruct.empty? ? nil : ostruct
9
+ super ostruct
10
+ end
11
+
12
+ private
13
+
14
+ def to_ostruct(obj)
15
+ if obj.is_a?(Hash)
16
+ OpenStruct.new(obj.map { |key, val| [key.to_s.underscore, to_ostruct(val)] }.to_h)
17
+ elsif obj.is_a?(Array)
18
+ obj.map { |o| to_ostruct(o) }
19
+ else # Assumed to be a primitive value
20
+ obj
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module DHLEcommerceEU
2
+ class Label < BaseObject
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module DHLEcommerceEU
2
+ class Shipment < BaseObject
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module DHLEcommerceEU
2
+ class Tracking < BaseObject
3
+ end
4
+ end
@@ -0,0 +1,54 @@
1
+ module DHLEcommerceEU
2
+ class BaseResource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.headers(headers).get(client.url_base + url, params: params)
13
+ end
14
+
15
+ def post_request(url, body:, params: {}, headers: {})
16
+ handle_response client.connection.headers(headers).post(client.url_base + url, params: params, json: body)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.headers(headers).patch(client.url_base + url, json: body)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.headers(headers).put(client.url_base + url, json: body)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.headers(headers).delete(client.url_base + url, params: params)
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Your request was malformed. #{response.parse['error']}"
35
+ when 401
36
+ raise Error, "You did not supply valid authentication credentials. #{response.parse['error']}"
37
+ when 403
38
+ raise Error, "You are not allowed to perform that action. #{response.parse['error']}"
39
+ when 404
40
+ raise Error, "No results were found for your request. #{response.parse['error']}"
41
+ when 429
42
+ raise Error, "Your request exceeded the API rate limit. #{response.parse['error']}"
43
+ when 500
44
+ raise Error, "We were unable to perform the request due to server-side problems. #{response.parse['error']}"
45
+ when 503
46
+ raise Error,
47
+ "You have been rate limited for sending more than 20 requests per second. #{response.parse['error']}"
48
+ end
49
+ response
50
+ rescue JSON::ParserError
51
+ raise Error, "We were unable to parse the response from the API. #{response}"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module DHLEcommerceEU
2
+ class LabelResource < BaseResource
3
+ #
4
+ # Retrieve label for a shipment
5
+ #
6
+ # @param [string] piece_id The shipment id
7
+ # @param [string] customer_id The customer id
8
+ #
9
+ # @return [Label] Label object
10
+ #
11
+ def retrieve(piece_id, customer_id)
12
+ Label.new get_request('ccc/label-reprint', params: { pieceId: piece_id, customerId: customer_id }).parse
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ module DHLEcommerceEU
2
+ class ShipmentResource < BaseResource
3
+ #
4
+ # Create a shipment
5
+ #
6
+ # @param [Hash] params params
7
+ # default: { generateLabel: true, labelFormat: 'pdf', labelSize: '10x15' }
8
+ # @param [Hash] **attributes attributes
9
+ # Example for return connect
10
+ # {
11
+ # "dataElement": {
12
+ # "parcelOriginOrganization": 'IT',
13
+ # "parcelDestinationOrganization": 'NL',
14
+ # "general": {
15
+ # "timestamp": '2022-07-01T13:05:05Z',
16
+ # "product": 'ParcelEurope.return.network'
17
+ # },
18
+ # "cPAN": {
19
+ # "addresses": {
20
+ # "sender": [
21
+ # {
22
+ # "type": 'default',
23
+ # "name": 'Tiziana Test',
24
+ # "additionalName": 'Buying Tests',
25
+ # "email": 'test@test.it',
26
+ # "street1": 'Teststrada 10',
27
+ # "postcode": '20123',
28
+ # "city": 'Milan',
29
+ # "country": 'IT',
30
+ # "customerIdentification": '5012345678', # The owner DHL account number
31
+ # "customerAccountNr1": '1234567890' # The owner DHL account number
32
+ # }
33
+ # ],
34
+ # "recipient": [
35
+ # {
36
+ # "type": 'doorstep',
37
+ # "name": 'Thijs Testbedrijf',
38
+ # "email": 'test@test.nl',
39
+ # "street1": 'Teststraat 10',
40
+ # "postcode": '9737 PE',
41
+ # "city": 'Groningen',
42
+ # "country": 'NL'
43
+ # }
44
+ # ]
45
+ # },
46
+ # "features": {
47
+ # "physical": {
48
+ # "grossWeight": '1.0',
49
+ # "length": '0.2',
50
+ # "height": '0.2',
51
+ # "width": '0.3'
52
+ # }
53
+ # }
54
+ # }
55
+ # }
56
+ # }
57
+ #
58
+ # @return [Shipment] Shipment object
59
+ #
60
+ def create(params: { generateLabel: true, labelFormat: 'pdf', labelSize: '10x15' }, **attributes)
61
+ response = post_request('ccc/send-cpan', params: params, body: attributes)
62
+ case response.headers['Content-Type']
63
+ when 'application/pdf'
64
+ Shipment.new id: response.headers['shipmentId'], label_blob: response.body.to_s
65
+ when 'application/json'
66
+ payload = response.parse
67
+ raise Error, "Your request was malformed. #{payload['error']}" if payload['error']
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ module DHLEcommerceEU
2
+ class TrackingResource < BaseResource
3
+ #
4
+ # Retrieve tracking information for a shipment
5
+ #
6
+ # @param [string] shipment_id Shipment ID
7
+ #
8
+ # @return [Tracking[]] An array of Tracking object
9
+ #
10
+ def retrieve(shipment_id)
11
+ payload = get_request('ccc/track-trace', params: { shipmentId: shipment_id }).parse
12
+ payload.map(&Tracking.method(:new))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DHLEcommerceEU
4
+ VERSION = '0.1.3'
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dhl_ecommerce_eu/version'
4
+ require 'active_support'
5
+ require 'digest'
6
+ require 'http'
7
+ # require 'httplog' # Uncomment this line to enable HTTP logging
8
+
9
+ module DHLEcommerceEU
10
+ require 'dhl_ecommerce_eu/cache'
11
+ autoload :Client, 'dhl_ecommerce_eu/client'
12
+
13
+ autoload :BaseResource, 'dhl_ecommerce_eu/resources/base_resource'
14
+ autoload :ShipmentResource, 'dhl_ecommerce_eu/resources/shipment_resource'
15
+ autoload :LabelResource, 'dhl_ecommerce_eu/resources/label_resource'
16
+ autoload :TrackingResource, 'dhl_ecommerce_eu/resources/tracking_resource'
17
+
18
+ autoload :BaseObject, 'dhl_ecommerce_eu/objects/base_object'
19
+ autoload :Shipment, 'dhl_ecommerce_eu/objects/shipment'
20
+ autoload :Label, 'dhl_ecommerce_eu/objects/label'
21
+ autoload :Tracking, 'dhl_ecommerce_eu/objects/tracking'
22
+
23
+ class Error < StandardError; end
24
+ end
@@ -0,0 +1,4 @@
1
+ module DHLEcommerceEU
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dhl_ecommerce_eu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Andy Chong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-12 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: 4.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem-release
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httplog
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
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
+ - !ruby/object:Gem::Dependency
126
+ name: zeitwerk
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Ruby API wrapper for DHL eCommerce EU. Currently only supports the Return
140
+ Connect product. Check [here](https://developer.dhl.com/api-reference/ecommerce-europe/)
141
+ for more info.
142
+ email:
143
+ - andygg1996personal@gmail.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".rspec"
149
+ - ".standard.yml"
150
+ - CHANGELOG.md
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - Gemfile.lock
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - bin/console
158
+ - bin/setup
159
+ - lib/dev/zeitwerk_loader.rb
160
+ - lib/dhl_ecommerce_eu.rb
161
+ - lib/dhl_ecommerce_eu/cache.rb
162
+ - lib/dhl_ecommerce_eu/client.rb
163
+ - lib/dhl_ecommerce_eu/objects/base_object.rb
164
+ - lib/dhl_ecommerce_eu/objects/label.rb
165
+ - lib/dhl_ecommerce_eu/objects/shipment.rb
166
+ - lib/dhl_ecommerce_eu/objects/tracking.rb
167
+ - lib/dhl_ecommerce_eu/resources/base_resource.rb
168
+ - lib/dhl_ecommerce_eu/resources/label_resource.rb
169
+ - lib/dhl_ecommerce_eu/resources/shipment_resource.rb
170
+ - lib/dhl_ecommerce_eu/resources/tracking_resource.rb
171
+ - lib/dhl_ecommerce_eu/version.rb
172
+ - sig/dhl_ecommerce_eu.rbs
173
+ homepage: https://github.com/PostCo/dhl_ecommerce_eu
174
+ licenses:
175
+ - MIT
176
+ metadata:
177
+ allowed_push_host: https://rubygems.org
178
+ homepage_uri: https://github.com/PostCo/dhl_ecommerce_eu
179
+ source_code_uri: https://github.com/PostCo/dhl_ecommerce_eu
180
+ changelog_uri: https://github.com/PostCo/dhl_ecommerce_eu/blob/main/CHANGELOG.md
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: 2.6.0
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubygems_version: 3.2.32
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Ruby API wrapper for DHL eCommerce EU
200
+ test_files: []