dhl_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: 1b9e7851e32f915f557f1f81c90d0e2b7b9ef7f5eae20e9d8613ccff62de0d77
4
+ data.tar.gz: 3888aef749658440d8190416d2ff1b82e5b725b974f6634457ab40d7e9d952ea
5
+ SHA512:
6
+ metadata.gz: 286fd63847484916402a2ad6edb8f67325e283fd22f48415e91279bad0ad1b38310ffb4ca85757f556a86aa4aff2692163698ce59ce32dc1d522e7932b6bd29a
7
+ data.tar.gz: 617b1f4841fe8721f79e7210485bd74b53452330304a1663b21fc45eab66fe1bdd763e671a4d9a876adb75fe6d4b01187bf1922ecddfdb85f2f603b3f60b397d
data/.env.sample ADDED
@@ -0,0 +1 @@
1
+ API_KEY=
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-06-22
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 andy@youdontknow.me. 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.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,157 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dhl (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.0.2.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ addressable (2.8.4)
17
+ public_suffix (>= 2.0.2, < 6.0)
18
+ ast (2.4.2)
19
+ byebug (11.1.3)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.10)
22
+ diff-lcs (1.5.0)
23
+ domain_name (0.5.20190701)
24
+ unf (>= 0.0.5, < 1.0.0)
25
+ dotenv (2.8.1)
26
+ ffi (1.15.5)
27
+ ffi-compiler (1.0.1)
28
+ ffi (>= 1.0.0)
29
+ rake
30
+ formatador (1.1.0)
31
+ gem-release (2.2.2)
32
+ guard (2.18.0)
33
+ formatador (>= 0.2.4)
34
+ listen (>= 2.7, < 4.0)
35
+ lumberjack (>= 1.0.12, < 2.0)
36
+ nenv (~> 0.1)
37
+ notiffany (~> 0.0)
38
+ pry (>= 0.13.0)
39
+ shellany (~> 0.0)
40
+ thor (>= 0.18.1)
41
+ guard-compat (1.2.1)
42
+ guard-rspec (4.7.3)
43
+ guard (~> 2.1)
44
+ guard-compat (~> 1.1)
45
+ rspec (>= 2.99.0, < 4.0)
46
+ http (5.1.1)
47
+ addressable (~> 2.8)
48
+ http-cookie (~> 1.0)
49
+ http-form_data (~> 2.2)
50
+ llhttp-ffi (~> 0.4.0)
51
+ http-cookie (1.0.5)
52
+ domain_name (~> 0.5)
53
+ http-form_data (2.3.0)
54
+ i18n (1.10.0)
55
+ concurrent-ruby (~> 1.0)
56
+ json (2.6.3)
57
+ language_server-protocol (3.17.0.3)
58
+ lint_roller (1.0.0)
59
+ listen (3.8.0)
60
+ rb-fsevent (~> 0.10, >= 0.10.3)
61
+ rb-inotify (~> 0.9, >= 0.9.10)
62
+ llhttp-ffi (0.4.0)
63
+ ffi-compiler (~> 1.0)
64
+ rake (~> 13.0)
65
+ lumberjack (1.2.8)
66
+ method_source (1.0.0)
67
+ minitest (5.15.0)
68
+ nenv (0.3.0)
69
+ notiffany (0.1.3)
70
+ nenv (~> 0.1)
71
+ shellany (~> 0.0)
72
+ parallel (1.23.0)
73
+ parser (3.2.2.3)
74
+ ast (~> 2.4.1)
75
+ racc
76
+ pry (0.14.2)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
79
+ pry-byebug (3.10.1)
80
+ byebug (~> 11.0)
81
+ pry (>= 0.13, < 0.15)
82
+ public_suffix (5.0.1)
83
+ racc (1.7.1)
84
+ rainbow (3.1.1)
85
+ rake (13.0.6)
86
+ rb-fsevent (0.11.2)
87
+ rb-inotify (0.10.1)
88
+ ffi (~> 1.0)
89
+ regexp_parser (2.8.1)
90
+ rexml (3.2.5)
91
+ rspec (3.12.0)
92
+ rspec-core (~> 3.12.0)
93
+ rspec-expectations (~> 3.12.0)
94
+ rspec-mocks (~> 3.12.0)
95
+ rspec-core (3.12.2)
96
+ rspec-support (~> 3.12.0)
97
+ rspec-expectations (3.12.3)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.12.0)
100
+ rspec-mocks (3.12.5)
101
+ diff-lcs (>= 1.2.0, < 2.0)
102
+ rspec-support (~> 3.12.0)
103
+ rspec-support (3.12.0)
104
+ rubocop (1.52.1)
105
+ json (~> 2.3)
106
+ parallel (~> 1.10)
107
+ parser (>= 3.2.2.3)
108
+ rainbow (>= 2.2.2, < 4.0)
109
+ regexp_parser (>= 1.8, < 3.0)
110
+ rexml (>= 3.2.5, < 4.0)
111
+ rubocop-ast (>= 1.28.0, < 2.0)
112
+ ruby-progressbar (~> 1.7)
113
+ unicode-display_width (>= 2.4.0, < 3.0)
114
+ rubocop-ast (1.29.0)
115
+ parser (>= 3.2.1.0)
116
+ rubocop-performance (1.18.0)
117
+ rubocop (>= 1.7.0, < 2.0)
118
+ rubocop-ast (>= 0.4.0)
119
+ ruby-progressbar (1.13.0)
120
+ shellany (0.0.1)
121
+ standard (1.29.0)
122
+ language_server-protocol (~> 3.17.0.2)
123
+ lint_roller (~> 1.0)
124
+ rubocop (~> 1.52.0)
125
+ standard-custom (~> 1.0.0)
126
+ standard-performance (~> 1.1.0)
127
+ standard-custom (1.0.1)
128
+ lint_roller (~> 1.0)
129
+ standard-performance (1.1.0)
130
+ lint_roller (~> 1.0)
131
+ rubocop-performance (~> 1.18.0)
132
+ thor (1.2.2)
133
+ tzinfo (2.0.4)
134
+ concurrent-ruby (~> 1.0)
135
+ unf (0.1.4)
136
+ unf_ext
137
+ unf_ext (0.0.8.2)
138
+ unicode-display_width (2.4.2)
139
+ zeitwerk (2.6.8)
140
+
141
+ PLATFORMS
142
+ arm64-darwin-21
143
+
144
+ DEPENDENCIES
145
+ dhl!
146
+ dotenv
147
+ gem-release
148
+ guard-rspec
149
+ pry
150
+ pry-byebug
151
+ rake (~> 13.0)
152
+ rspec (~> 3.0)
153
+ standard (~> 1.3)
154
+ zeitwerk
155
+
156
+ BUNDLED WITH
157
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Andy
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,99 @@
1
+ # DHL
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`. 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'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dhl
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ DHL.configure do |config|
27
+ config.api_key = "your api key"
28
+ config.testing = true # or false
29
+ end
30
+
31
+ # DHL Retoure
32
+ #
33
+ retoure_client = DHL::RetoureClient.new(username: 'retoure username', password: 'retoure password')
34
+ #
35
+ # OR if you only creating label for 1 account all the time,
36
+ # you can set the ENV variables: DHL_RETOURE_USERNAME, DHL_RETOURE_PASSWORD,
37
+ # and then just initialize the client like below:
38
+ #
39
+ # retoure_client = DHL::RetoureClient.new
40
+
41
+ label = retoure_client.create_label(
42
+ "receiver_id": 'deu',
43
+ "customer_reference": 'Kundenreferenz',
44
+ "shipment_reference": 'Sendungsreferenz',
45
+ "shipper": {
46
+ "name1": 'Absender Retoure Zeile 1',
47
+ "name2": 'Absender Retoure Zeile 2',
48
+ "name3": 'Absender Retoure Zeile 3',
49
+ "address_street": 'Charles-de-Gaulle Str.',
50
+ "address_house": '20',
51
+ "city": 'Bonn',
52
+ "email": 'Max.Mustermann@dhl.local',
53
+ "phone": '+49 421 987654321',
54
+ "postal_code": '53113',
55
+ "state": 'NRW'
56
+ },
57
+ "item_weight": {
58
+ "uom": 'g',
59
+ "value": 1000
60
+ },
61
+ "item_value": {
62
+ "currency": 'EUR',
63
+ "value": 100
64
+ }
65
+ )
66
+
67
+ # DHL Tracking
68
+ #
69
+ track_client=DHL::TrackingClient.new
70
+ # Also accept service:, origin_country_code:, requester_country_code:
71
+ tracking = track_client.track(tracking_number: 611665700181)
72
+
73
+ # You can access the raw response by calling by calling the #response:
74
+ retoure_client.response
75
+ tracking_client.response
76
+ # It is a HTTP::Response object. See https://github.com/httprb/http/wiki/Response-Handling for more info.
77
+
78
+ # You can access the raw attributes before the keys is parsed to snake_case by calling the #attributes:
79
+ label.attributes
80
+ tracking.attributes
81
+ ```
82
+
83
+ ## Development
84
+
85
+ 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.
86
+
87
+ 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).
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/postco/dhl. 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/postco/dhl/blob/main/CODE_OF_CONDUCT.md).
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
96
+
97
+ ## Code of Conduct
98
+
99
+ Everyone interacting in the DHL project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/postco/dhl/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,20 @@
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 'dev/config'
9
+ require 'dhl'
10
+
11
+ # You can add fixtures and/or initialization code here to make experimenting
12
+ # with your gem easier. You can also use a different console, if you like.
13
+
14
+ set_config
15
+
16
+ # (If you use this, don't forget to add pry to your Gemfile!)
17
+ Pry.start
18
+
19
+ # require 'irb'
20
+ # 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
data/lib/dev/config.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'dotenv/load'
2
+
3
+ def set_config
4
+ DHL.configure do |config|
5
+ config.api_key = ENV['API_KEY']
6
+ end
7
+ 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' => 'DHL'
7
+ )
8
+ loader.push_dir('./lib')
9
+ loader.collapse('./lib/dhl/clients')
10
+ loader.collapse('./lib/dhl/objects')
11
+ loader.ignore("#{__dir__}/config.rb")
12
+ loader.enable_reloading
13
+ # loader.log!
14
+ loader.setup
15
+
16
+ $__dhl_loader__ = loader
17
+
18
+ def reload!
19
+ $__dhl_loader__.reload
20
+ set_config
21
+ true
22
+ end
@@ -0,0 +1,45 @@
1
+ require 'http'
2
+
3
+ module DHL
4
+ class BaseClient
5
+ attr_writer :http_client
6
+ attr_reader :response
7
+
8
+ def connection
9
+ @connection ||= HTTP.headers(content_type: 'application/json', dhl_api_key: DHL.config.api_key)
10
+ end
11
+
12
+ private
13
+
14
+ attr_writer :response
15
+
16
+ def url
17
+ DHL.config.testing ? self.class::TEST_URL : self.class::URL
18
+ end
19
+
20
+ def handle_response
21
+ error_message = response.body
22
+
23
+ case response.status
24
+ when 400
25
+ raise Error, "A bad request or a validation exception has occurred. #{error_message}"
26
+ when 401
27
+ raise Error, "Invalid authorization credentials. #{error_message}"
28
+ when 403
29
+ raise Error, "Connection doesn't have permission to access the resource. #{error_message}"
30
+ when 404
31
+ raise Error, "The resource you have specified cannot be found. #{error_message}"
32
+ when 429
33
+ raise Error, "The API rate limit for your application has been exceeded. #{error_message}"
34
+ when 500
35
+ raise Error,
36
+ "An unhandled error with the . Contact the DHL team if problems persist. #{error_message}"
37
+ when 503
38
+ raise Error,
39
+ "API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
40
+ end
41
+
42
+ response
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ module DHL
2
+ class RetoureClient < BaseClient
3
+ URL = 'https://api-eu.dhl.com/parcel/de/shipping/returns/v1/orders'
4
+ TEST_URL = 'https://api-sandbox.dhl.com/parcel/de/shipping/returns/v1/orders'
5
+
6
+ def initialize(username: nil, password: nil, label_type: 'BOTH')
7
+ @username = username
8
+ @password = password
9
+ @label_type = label_type
10
+ end
11
+
12
+ # @overload label_type
13
+ # Read the label type. Default to 'BOTH'
14
+ # @return [string] The label type you will to receive
15
+ # @overload label_type=(value)
16
+ # @param value [String] possible values: 'BOTH', 'SHIPMENT_LABEL', 'QR_LABEL'
17
+ attr_accessor :label_type
18
+
19
+ def create_label(attributes = {})
20
+ self.response = connection.post(url, json: attributes, params: { labelType: label_type })
21
+ RetoureLabel.new handle_response.parse
22
+ end
23
+
24
+ def connection
25
+ super.basic_auth(user: username, pass: password)
26
+ end
27
+
28
+ private
29
+
30
+ def username
31
+ @username ||= ENV['DHL_RETOURE_USERNAME']
32
+ end
33
+
34
+ def password
35
+ @password ||= ENV['DHL_RETOURE_PASSWORD']
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,12 @@
1
+ module DHL
2
+ class TrackingClient < BaseClient
3
+ URL = 'https://api-eu.dhl.com/track/shipments'
4
+ TEST_URL = 'https://api-test.dhl.com/track/shipments'
5
+
6
+ def track(attributes = {})
7
+ attributes = attributes.deep_transform_keys { |key| key.to_s.camelize(:lower) }
8
+ self.response = connection.get(url, params: attributes)
9
+ Tracking.new handle_response.parse
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module DHL
2
+ class Configuration
3
+ attr_accessor :api_key, :testing
4
+ end
5
+
6
+ class << self
7
+ def config
8
+ @config ||= Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield config
13
+ after_configure
14
+ end
15
+
16
+ def after_configure
17
+ config.testing ||= false
18
+
19
+ # register special mime type for DHL error responses
20
+ HTTP::MimeType.register_adapter 'application/problem+json', HTTP::MimeType::JSON
21
+ end
22
+ end
23
+ end
data/lib/dhl/error.rb ADDED
@@ -0,0 +1,3 @@
1
+ module DHL
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,22 @@
1
+ module DHL
2
+ class BaseObject < OpenStruct
3
+ attr_reader :attributes
4
+
5
+ def initialize(attributes = {})
6
+ @attributes = attributes
7
+ super to_ostruct(attributes)
8
+ end
9
+
10
+ private
11
+
12
+ def to_ostruct(obj)
13
+ if obj.is_a?(Hash)
14
+ OpenStruct.new(obj.map { |key, val| [key.to_s.underscore, to_ostruct(val)] }.to_h)
15
+ elsif obj.is_a?(Array)
16
+ obj.map { |o| to_ostruct(o) }
17
+ else # Assumed to be a primitive value
18
+ obj
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module DHL
2
+ class RetoureLabel < BaseObject
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module DHL
2
+ class Tracking < BaseObject
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DHL
4
+ VERSION = '0.1.0'
5
+ end
data/lib/dhl.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dhl/version'
4
+ require 'active_support/core_ext/hash/keys'
5
+ require 'active_support/core_ext/string/inflections'
6
+
7
+ require 'http'
8
+
9
+ module DHL
10
+ require 'dhl/configuration'
11
+
12
+ autoload :Error, 'dhl/error'
13
+
14
+ autoload :BaseClient, 'dhl/clients/base_client'
15
+ autoload :RetoureClient, 'dhl/clients/retoure_client'
16
+ autoload :TrackingClient, 'dhl/clients/tracking_client'
17
+
18
+ autoload :BaseObject, 'dhl/objects/base_object'
19
+ autoload :RetoureLabel, 'dhl/objects/retoure_label'
20
+ autoload :Tracking, 'dhl/objects/tracking'
21
+
22
+ end
data/sig/dhl_api.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module DHL
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dhl_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Chong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-26 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: pry
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-byebug
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: zeitwerk
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:
126
+ email:
127
+ - andy@youdontknow.me
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".env.sample"
133
+ - ".rspec"
134
+ - ".standard.yml"
135
+ - CHANGELOG.md
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/dev/config.rb
145
+ - lib/dev/zeitwerk_loader.rb
146
+ - lib/dhl.rb
147
+ - lib/dhl/clients/base_client.rb
148
+ - lib/dhl/clients/retoure_client.rb
149
+ - lib/dhl/clients/tracking_client.rb
150
+ - lib/dhl/configuration.rb
151
+ - lib/dhl/error.rb
152
+ - lib/dhl/objects/base_object.rb
153
+ - lib/dhl/objects/retoure_label.rb
154
+ - lib/dhl/objects/tracking.rb
155
+ - lib/dhl/version.rb
156
+ - sig/dhl_api.rbs
157
+ homepage: https://github.com/PostCo/dhl
158
+ licenses:
159
+ - MIT
160
+ metadata:
161
+ allowed_push_host: https://rubygems.org
162
+ homepage_uri: https://github.com/PostCo/dhl
163
+ source_code_uri: https://github.com/PostCo/dhl
164
+ changelog_uri: https://github.com/PostCo/dhl/blob/main/CHANGELOG.md
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 2.6.0
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.2.32
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Ruby API Wrapper for DHL
184
+ test_files: []