dhl_api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +15 -15
- 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 +3 -3
- 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 +16 -16
- 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: 38fd924f15b98dc8f683c50ae9f377b7d79ab3dec1f0cbfc5d3641653a51350d
|
4
|
+
data.tar.gz: 1d7d0afcf7949e90026ea3b2ee81912423f3c61a71f6a3b97b7b36082a29d56f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12709605fc3a4c59c9be84afd4764c14d72c75b88e544d77436f7b670bd89bbc90e7e84aa1f1d505d0201cd2289f847336066a32d75713f0b04ca49469eb5715
|
7
|
+
data.tar.gz: d65f5bdeae686f719320815e817b183ccaca6be69869919600c754fc11f779b0a5f6002fff557e93e89818f89258a853364f10446b7a6e07d2c7c166b9b396e3
|
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,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# DHLAPI
|
2
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/
|
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_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
5
|
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'dhl_api'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,25 +18,25 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install dhl_api
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
|
26
|
+
DHLAPI.configure do |config|
|
27
27
|
config.api_key = "your api key"
|
28
28
|
config.testing = true # or false
|
29
29
|
end
|
30
30
|
|
31
|
-
# DHL Retoure
|
31
|
+
# DHL Retoure (https://developer.dhl.com/api-reference/dhl-parcel-de-returns-post-parcel-germany)
|
32
32
|
#
|
33
|
-
retoure_client =
|
33
|
+
retoure_client = DHLAPI::RetoureClient.new(username: 'retoure username', password: 'retoure password')
|
34
34
|
#
|
35
35
|
# OR if you only creating label for 1 account all the time,
|
36
|
-
# you can set the ENV variables:
|
36
|
+
# you can set the ENV variables: DHLAPI_RETOURE_USERNAME, DHLAPI_RETOURE_PASSWORD,
|
37
37
|
# and then just initialize the client like below:
|
38
38
|
#
|
39
|
-
# retoure_client =
|
39
|
+
# retoure_client = DHLAPI::RetoureClient.new
|
40
40
|
|
41
41
|
label = retoure_client.create_label(
|
42
42
|
"receiver_id": 'deu',
|
@@ -49,7 +49,7 @@ label = retoure_client.create_label(
|
|
49
49
|
"address_street": 'Charles-de-Gaulle Str.',
|
50
50
|
"address_house": '20',
|
51
51
|
"city": 'Bonn',
|
52
|
-
"email": 'Max.Mustermann@
|
52
|
+
"email": 'Max.Mustermann@dhl_api.local',
|
53
53
|
"phone": '+49 421 987654321',
|
54
54
|
"postal_code": '53113',
|
55
55
|
"state": 'NRW'
|
@@ -64,11 +64,11 @@ label = retoure_client.create_label(
|
|
64
64
|
}
|
65
65
|
)
|
66
66
|
|
67
|
-
#
|
67
|
+
# Tracking (https://developer.dhl.com/api-reference/shipment-tracking)
|
68
68
|
#
|
69
|
-
track_client=
|
69
|
+
track_client=DHLAPI::TrackingClient.new
|
70
70
|
# Also accept service:, origin_country_code:, requester_country_code:
|
71
|
-
tracking = track_client.track(tracking_number:
|
71
|
+
tracking = track_client.track(tracking_number: '420025369374810912402173942693')
|
72
72
|
|
73
73
|
# You can access the raw response by calling by calling the #response:
|
74
74
|
retoure_client.response
|
@@ -88,7 +88,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
88
88
|
|
89
89
|
## Contributing
|
90
90
|
|
91
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/postco/
|
91
|
+
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
92
|
|
93
93
|
## License
|
94
94
|
|
@@ -96,4 +96,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
96
96
|
|
97
97
|
## Code of Conduct
|
98
98
|
|
99
|
-
Everyone interacting in the
|
99
|
+
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'
|
@@ -28,11 +28,11 @@ module DHL
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def username
|
31
|
-
@username ||= ENV['
|
31
|
+
@username ||= ENV['DHLAPI_RETOURE_USERNAME']
|
32
32
|
end
|
33
33
|
|
34
34
|
def password
|
35
|
-
@password ||= ENV['
|
35
|
+
@password ||= ENV['DHLAPI_RETOURE_PASSWORD']
|
36
36
|
end
|
37
37
|
end
|
38
38
|
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,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Chong
|
@@ -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
|