dhl_api 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b9e7851e32f915f557f1f81c90d0e2b7b9ef7f5eae20e9d8613ccff62de0d77
4
- data.tar.gz: 3888aef749658440d8190416d2ff1b82e5b725b974f6634457ab40d7e9d952ea
3
+ metadata.gz: 926c694d2d3c2c5f278c62e10f8aa014b86480f8d2f3207f7fe42ab8891febd0
4
+ data.tar.gz: 838f29f55a1693c6d007537b65c970a1e59e5c4ce45d54775eb818f658668b1f
5
5
  SHA512:
6
- metadata.gz: 286fd63847484916402a2ad6edb8f67325e283fd22f48415e91279bad0ad1b38310ffb4ca85757f556a86aa4aff2692163698ce59ce32dc1d522e7932b6bd29a
7
- data.tar.gz: 617b1f4841fe8721f79e7210485bd74b53452330304a1663b21fc45eab66fe1bdd763e671a4d9a876adb75fe6d4b01187bf1922ecddfdb85f2f603b3f60b397d
6
+ metadata.gz: bc318898989145a21275132969bf2e891d86e9cba18117f58ba2db428152d1b249099595828b4a9c9b9ddffab65a057d3290ce22c5ac9e664a36e1084898c559
7
+ data.tar.gz: 6dd5d180bb173446a7bde4e21188c2d50ae0ee8e697141bf22ef4e56fa4fd191f0048e762f8b51299d23aa39d0dccd246eb7fcc34d51046f8a9daf9308a584f1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
- ## [Unreleased]
1
+ ## [0.1.2] - 2023-06-27
2
2
 
3
- ## [0.1.0] - 2023-06-22
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in dhl.gemspec
5
+ # Specify your gem's dependencies in dhl_api.gemspec
6
6
  gemspec
7
7
 
8
8
  gem 'rake', '~> 13.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dhl (0.1.0)
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
- dhl!
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
- 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
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 'dhl'
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 dhl
19
+ $ gem install dhl_api
22
20
 
23
21
  ## Usage
24
22
 
25
23
  ```ruby
26
- DHL.configure do |config|
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 = DHL::RetoureClient.new(username: 'retoure username', password: 'retoure password')
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: DHL_RETOURE_USERNAME, DHL_RETOURE_PASSWORD,
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 = DHL::RetoureClient.new
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@dhl.local',
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
- # DHL Tracking
65
+ # Tracking (https://developer.dhl.com/api-reference/shipment-tracking)
68
66
  #
69
- track_client=DHL::TrackingClient.new
67
+ track_client=DHLAPI::TrackingClient.new
70
68
  # Also accept service:, origin_country_code:, requester_country_code:
71
- tracking = track_client.track(tracking_number: 611665700181)
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
- tracking_client.response
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/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).
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 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).
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 'dhl'
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
@@ -1,7 +1,7 @@
1
1
  require 'dotenv/load'
2
2
 
3
3
  def set_config
4
- DHL.configure do |config|
4
+ DHLAPI.configure do |config|
5
5
  config.api_key = ENV['API_KEY']
6
6
  end
7
7
  end
@@ -3,11 +3,11 @@ require_relative 'config'
3
3
 
4
4
  loader = Zeitwerk::Loader.for_gem
5
5
  loader.inflector.inflect(
6
- 'dhl' => 'DHL'
6
+ 'dhl_api' => 'DHLAPI'
7
7
  )
8
8
  loader.push_dir('./lib')
9
- loader.collapse('./lib/dhl/clients')
10
- loader.collapse('./lib/dhl/objects')
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 DHL
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: DHL.config.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
- DHL.config.testing ? self.class::TEST_URL : self.class::URL
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 DHL team if problems persist. #{error_message}"
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 DHL
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
- self.response = connection.post(url, json: attributes, params: { labelType: label_type })
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['DHL_RETOURE_USERNAME']
32
+ @username ||= ENV['DHLAPI_RETOURE_USERNAME']
32
33
  end
33
34
 
34
35
  def password
35
- @password ||= ENV['DHL_RETOURE_PASSWORD']
36
+ @password ||= ENV['DHLAPI_RETOURE_PASSWORD']
36
37
  end
37
38
  end
38
39
  end
@@ -1,4 +1,4 @@
1
- module DHL
1
+ module DHLAPI
2
2
  class TrackingClient < BaseClient
3
3
  URL = 'https://api-eu.dhl.com/track/shipments'
4
4
  TEST_URL = 'https://api-test.dhl.com/track/shipments'
@@ -1,4 +1,4 @@
1
- module DHL
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 DHL error responses
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
@@ -1,3 +1,3 @@
1
- module DHL
1
+ module DHLAPI
2
2
  class Error < StandardError; end
3
3
  end
@@ -1,4 +1,4 @@
1
- module DHL
1
+ module DHLAPI
2
2
  class BaseObject < OpenStruct
3
3
  attr_reader :attributes
4
4
 
@@ -1,4 +1,4 @@
1
- module DHL
1
+ module DHLAPI
2
2
  class RetoureLabel < BaseObject
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
- module DHL
1
+ module DHLAPI
2
2
  class Tracking < BaseObject
3
3
  end
4
4
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module DHL
4
- VERSION = '0.1.0'
3
+ module DHLAPI
4
+ VERSION = '0.1.2'
5
5
  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
@@ -1,4 +1,4 @@
1
- module DHL
1
+ module DHLAPI
2
2
  VERSION: String
3
3
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
4
  end
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.0
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-26 00:00:00.000000000 Z
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/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
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/dhl
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/dhl
163
- source_code_uri: https://github.com/PostCo/dhl
164
- changelog_uri: https://github.com/PostCo/dhl/blob/main/CHANGELOG.md
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