dhl_api 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +16 -18
- data/bin/console +1 -1
- data/lib/dev/config.rb +1 -1
- data/lib/dev/zeitwerk_loader.rb +3 -3
- data/lib/{dhl → dhl_api}/clients/base_client.rb +4 -4
- data/lib/{dhl → dhl_api}/clients/retoure_client.rb +5 -4
- data/lib/{dhl → dhl_api}/clients/tracking_client.rb +1 -1
- data/lib/{dhl → dhl_api}/configuration.rb +2 -2
- data/lib/{dhl → dhl_api}/error.rb +1 -1
- data/lib/{dhl → dhl_api}/objects/base_object.rb +1 -1
- data/lib/{dhl → dhl_api}/objects/retoure_label.rb +1 -1
- data/lib/{dhl → dhl_api}/objects/tracking.rb +1 -1
- data/lib/{dhl → dhl_api}/version.rb +2 -2
- data/lib/dhl_api.rb +21 -0
- data/sig/dhl_api.rbs +1 -1
- metadata +17 -17
- data/lib/dhl.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 926c694d2d3c2c5f278c62e10f8aa014b86480f8d2f3207f7fe42ab8891febd0
|
4
|
+
data.tar.gz: 838f29f55a1693c6d007537b65c970a1e59e5c4ce45d54775eb818f658668b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc318898989145a21275132969bf2e891d86e9cba18117f58ba2db428152d1b249099595828b4a9c9b9ddffab65a057d3290ce22c5ac9e664a36e1084898c559
|
7
|
+
data.tar.gz: 6dd5d180bb173446a7bde4e21188c2d50ae0ee8e697141bf22ef4e56fa4fd191f0048e762f8b51299d23aa39d0dccd246eb7fcc34d51046f8a9daf9308a584f1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
## [
|
1
|
+
## [0.1.2] - 2023-06-27
|
2
2
|
|
3
|
-
|
3
|
+
- Transform payload keys to lowerCamel before send.
|
4
|
+
|
5
|
+
## [0.1.1] - 2023-06-26
|
6
|
+
|
7
|
+
- Rename DHL constant to DHLAPI
|
8
|
+
- Rename dhl to dhl_api
|
9
|
+
|
10
|
+
## [0.1.0] - 2023-06-26
|
4
11
|
|
5
12
|
- Initial release
|
13
|
+
- Add Retoure label creation
|
14
|
+
- Add Unified Tracking
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
dhl_api (0.1.0)
|
5
5
|
activesupport (>= 4.0.2)
|
6
6
|
http (~> 5.0)
|
7
7
|
|
@@ -142,7 +142,7 @@ PLATFORMS
|
|
142
142
|
arm64-darwin-21
|
143
143
|
|
144
144
|
DEPENDENCIES
|
145
|
-
|
145
|
+
dhl_api!
|
146
146
|
dotenv
|
147
147
|
gem-release
|
148
148
|
guard-rspec
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
# DHL
|
1
|
+
# DHL API
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a Ruby API wrapper for DHL. Right now, we only cover Retoure & Tracking. Feel free to extend the gem t cover more DHL services.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem '
|
10
|
+
gem 'dhl_api'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -18,25 +16,25 @@ And then execute:
|
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
$ gem install
|
19
|
+
$ gem install dhl_api
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
23
|
```ruby
|
26
|
-
|
24
|
+
DHLAPI.configure do |config|
|
27
25
|
config.api_key = "your api key"
|
28
26
|
config.testing = true # or false
|
29
27
|
end
|
30
28
|
|
31
|
-
# DHL Retoure
|
29
|
+
# DHL Retoure (https://developer.dhl.com/api-reference/dhl-parcel-de-returns-post-parcel-germany)
|
32
30
|
#
|
33
|
-
retoure_client =
|
31
|
+
retoure_client = DHLAPI::RetoureClient.new(username: 'retoure username', password: 'retoure password')
|
34
32
|
#
|
35
33
|
# OR if you only creating label for 1 account all the time,
|
36
|
-
# you can set the ENV variables:
|
34
|
+
# you can set the ENV variables: DHLAPI_RETOURE_USERNAME, DHLAPI_RETOURE_PASSWORD,
|
37
35
|
# and then just initialize the client like below:
|
38
36
|
#
|
39
|
-
# retoure_client =
|
37
|
+
# retoure_client = DHLAPI::RetoureClient.new
|
40
38
|
|
41
39
|
label = retoure_client.create_label(
|
42
40
|
"receiver_id": 'deu',
|
@@ -49,7 +47,7 @@ label = retoure_client.create_label(
|
|
49
47
|
"address_street": 'Charles-de-Gaulle Str.',
|
50
48
|
"address_house": '20',
|
51
49
|
"city": 'Bonn',
|
52
|
-
"email": 'Max.Mustermann@
|
50
|
+
"email": 'Max.Mustermann@dhl_api.local',
|
53
51
|
"phone": '+49 421 987654321',
|
54
52
|
"postal_code": '53113',
|
55
53
|
"state": 'NRW'
|
@@ -64,15 +62,15 @@ label = retoure_client.create_label(
|
|
64
62
|
}
|
65
63
|
)
|
66
64
|
|
67
|
-
#
|
65
|
+
# Tracking (https://developer.dhl.com/api-reference/shipment-tracking)
|
68
66
|
#
|
69
|
-
track_client=
|
67
|
+
track_client=DHLAPI::TrackingClient.new
|
70
68
|
# Also accept service:, origin_country_code:, requester_country_code:
|
71
|
-
tracking = track_client.track(tracking_number:
|
69
|
+
tracking = track_client.track(tracking_number: '420025369374810912402173942693')
|
72
70
|
|
73
71
|
# You can access the raw response by calling by calling the #response:
|
74
72
|
retoure_client.response
|
75
|
-
|
73
|
+
track_client.response
|
76
74
|
# It is a HTTP::Response object. See https://github.com/httprb/http/wiki/Response-Handling for more info.
|
77
75
|
|
78
76
|
# You can access the raw attributes before the keys is parsed to snake_case by calling the #attributes:
|
@@ -88,7 +86,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
88
86
|
|
89
87
|
## Contributing
|
90
88
|
|
91
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/postco/
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/postco/dhl_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/postco/dhl_api/blob/main/CODE_OF_CONDUCT.md).
|
92
90
|
|
93
91
|
## License
|
94
92
|
|
@@ -96,4 +94,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
96
94
|
|
97
95
|
## Code of Conduct
|
98
96
|
|
99
|
-
Everyone interacting in the
|
97
|
+
Everyone interacting in the DHLAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/postco/dhl_api/blob/main/CODE_OF_CONDUCT.md).
|
data/bin/console
CHANGED
@@ -6,7 +6,7 @@ require 'bundler/setup'
|
|
6
6
|
require 'dotenv/load'
|
7
7
|
require 'dev/zeitwerk_loader'
|
8
8
|
require 'dev/config'
|
9
|
-
require '
|
9
|
+
require 'dhl_api'
|
10
10
|
|
11
11
|
# You can add fixtures and/or initialization code here to make experimenting
|
12
12
|
# with your gem easier. You can also use a different console, if you like.
|
data/lib/dev/config.rb
CHANGED
data/lib/dev/zeitwerk_loader.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative 'config'
|
|
3
3
|
|
4
4
|
loader = Zeitwerk::Loader.for_gem
|
5
5
|
loader.inflector.inflect(
|
6
|
-
'
|
6
|
+
'dhl_api' => 'DHLAPI'
|
7
7
|
)
|
8
8
|
loader.push_dir('./lib')
|
9
|
-
loader.collapse('./lib/
|
10
|
-
loader.collapse('./lib/
|
9
|
+
loader.collapse('./lib/dhl_api/clients')
|
10
|
+
loader.collapse('./lib/dhl_api/objects')
|
11
11
|
loader.ignore("#{__dir__}/config.rb")
|
12
12
|
loader.enable_reloading
|
13
13
|
# loader.log!
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'http'
|
2
2
|
|
3
|
-
module
|
3
|
+
module DHLAPI
|
4
4
|
class BaseClient
|
5
5
|
attr_writer :http_client
|
6
6
|
attr_reader :response
|
7
7
|
|
8
8
|
def connection
|
9
|
-
@connection ||= HTTP.headers(content_type: 'application/json', dhl_api_key:
|
9
|
+
@connection ||= HTTP.headers(content_type: 'application/json', dhl_api_key: DHLAPI.config.api_key)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -14,7 +14,7 @@ module DHL
|
|
14
14
|
attr_writer :response
|
15
15
|
|
16
16
|
def url
|
17
|
-
|
17
|
+
DHLAPI.config.testing ? self.class::TEST_URL : self.class::URL
|
18
18
|
end
|
19
19
|
|
20
20
|
def handle_response
|
@@ -33,7 +33,7 @@ module DHL
|
|
33
33
|
raise Error, "The API rate limit for your application has been exceeded. #{error_message}"
|
34
34
|
when 500
|
35
35
|
raise Error,
|
36
|
-
"An unhandled error with the . Contact the
|
36
|
+
"An unhandled error with the . Contact the DHLAPI team if problems persist. #{error_message}"
|
37
37
|
when 503
|
38
38
|
raise Error,
|
39
39
|
"API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module DHLAPI
|
2
2
|
class RetoureClient < BaseClient
|
3
3
|
URL = 'https://api-eu.dhl.com/parcel/de/shipping/returns/v1/orders'
|
4
4
|
TEST_URL = 'https://api-sandbox.dhl.com/parcel/de/shipping/returns/v1/orders'
|
@@ -17,7 +17,8 @@ module DHL
|
|
17
17
|
attr_accessor :label_type
|
18
18
|
|
19
19
|
def create_label(attributes = {})
|
20
|
-
|
20
|
+
payload = attributes.deep_transform_keys { |key| key.to_s.camelize(:lower) }
|
21
|
+
self.response = connection.post(url, json: payload, params: { labelType: label_type })
|
21
22
|
RetoureLabel.new handle_response.parse
|
22
23
|
end
|
23
24
|
|
@@ -28,11 +29,11 @@ module DHL
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def username
|
31
|
-
@username ||= ENV['
|
32
|
+
@username ||= ENV['DHLAPI_RETOURE_USERNAME']
|
32
33
|
end
|
33
34
|
|
34
35
|
def password
|
35
|
-
@password ||= ENV['
|
36
|
+
@password ||= ENV['DHLAPI_RETOURE_PASSWORD']
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module DHLAPI
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_key, :testing
|
4
4
|
end
|
@@ -16,7 +16,7 @@ module DHL
|
|
16
16
|
def after_configure
|
17
17
|
config.testing ||= false
|
18
18
|
|
19
|
-
# register special mime type for
|
19
|
+
# register special mime type for DHLAPI error responses
|
20
20
|
HTTP::MimeType.register_adapter 'application/problem+json', HTTP::MimeType::JSON
|
21
21
|
end
|
22
22
|
end
|
data/lib/dhl_api.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'dhl_api/version'
|
4
|
+
require 'active_support/core_ext/hash/keys'
|
5
|
+
require 'active_support/core_ext/string/inflections'
|
6
|
+
|
7
|
+
require 'http'
|
8
|
+
|
9
|
+
module DHLAPI
|
10
|
+
require 'dhl_api/configuration'
|
11
|
+
|
12
|
+
autoload :Error, 'dhl_api/error'
|
13
|
+
|
14
|
+
autoload :BaseClient, 'dhl_api/clients/base_client'
|
15
|
+
autoload :RetoureClient, 'dhl_api/clients/retoure_client'
|
16
|
+
autoload :TrackingClient, 'dhl_api/clients/tracking_client'
|
17
|
+
|
18
|
+
autoload :BaseObject, 'dhl_api/objects/base_object'
|
19
|
+
autoload :RetoureLabel, 'dhl_api/objects/retoure_label'
|
20
|
+
autoload :Tracking, 'dhl_api/objects/tracking'
|
21
|
+
end
|
data/sig/dhl_api.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhl_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -143,25 +143,25 @@ files:
|
|
143
143
|
- bin/setup
|
144
144
|
- lib/dev/config.rb
|
145
145
|
- lib/dev/zeitwerk_loader.rb
|
146
|
-
- lib/
|
147
|
-
- lib/
|
148
|
-
- lib/
|
149
|
-
- lib/
|
150
|
-
- lib/
|
151
|
-
- lib/
|
152
|
-
- lib/
|
153
|
-
- lib/
|
154
|
-
- lib/
|
155
|
-
- lib/
|
146
|
+
- lib/dhl_api.rb
|
147
|
+
- lib/dhl_api/clients/base_client.rb
|
148
|
+
- lib/dhl_api/clients/retoure_client.rb
|
149
|
+
- lib/dhl_api/clients/tracking_client.rb
|
150
|
+
- lib/dhl_api/configuration.rb
|
151
|
+
- lib/dhl_api/error.rb
|
152
|
+
- lib/dhl_api/objects/base_object.rb
|
153
|
+
- lib/dhl_api/objects/retoure_label.rb
|
154
|
+
- lib/dhl_api/objects/tracking.rb
|
155
|
+
- lib/dhl_api/version.rb
|
156
156
|
- sig/dhl_api.rbs
|
157
|
-
homepage: https://github.com/PostCo/
|
157
|
+
homepage: https://github.com/PostCo/dhl_api
|
158
158
|
licenses:
|
159
159
|
- MIT
|
160
160
|
metadata:
|
161
161
|
allowed_push_host: https://rubygems.org
|
162
|
-
homepage_uri: https://github.com/PostCo/
|
163
|
-
source_code_uri: https://github.com/PostCo/
|
164
|
-
changelog_uri: https://github.com/PostCo/
|
162
|
+
homepage_uri: https://github.com/PostCo/dhl_api
|
163
|
+
source_code_uri: https://github.com/PostCo/dhl_api
|
164
|
+
changelog_uri: https://github.com/PostCo/dhl_api/blob/main/CHANGELOG.md
|
165
165
|
post_install_message:
|
166
166
|
rdoc_options: []
|
167
167
|
require_paths:
|
@@ -180,5 +180,5 @@ requirements: []
|
|
180
180
|
rubygems_version: 3.2.32
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
|
-
summary: Ruby API Wrapper for DHL
|
183
|
+
summary: Ruby API Wrapper for DHL API
|
184
184
|
test_files: []
|
data/lib/dhl.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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
|