dpd_ie_api 0.2.1 → 0.3.0
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 +4 -4
- data/README.md +48 -5
- data/lib/dpd_ie_api/client.rb +4 -0
- data/lib/dpd_ie_api/objects/locator.rb +8 -0
- data/lib/dpd_ie_api/resources/locator.rb +69 -0
- data/lib/dpd_ie_api/version.rb +1 -1
- data/lib/dpd_ie_api.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b5b88bb8e13571ef8c0c054f91249ce27b2e8b96c150502f7c221857f3ee8ee
|
|
4
|
+
data.tar.gz: bd6ca4477ced7a57505a6160505a9f21da1a375745bed39aeb62b64265f0a58c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0d6555fc183eae6676c651aab5c4a2c31767db9d83cd071c2604d88c15a7a1f831bc5cbe16601570f8ba46e5d185cb47fb886c095f17b71a4ecbec57f6ab826
|
|
7
|
+
data.tar.gz: 1a95e8bbcd680bfba8759a01ca8b20d2cea89f75156a6b5bfe9bf71c3d86ed784ddc0ff39166ee51967932635469af7e7b61e3a1595343dd85f9dfaf4ddb78d5
|
data/README.md
CHANGED
|
@@ -20,11 +20,12 @@ gem install dpd_ie_api
|
|
|
20
20
|
|
|
21
21
|
The gem provides a **uniform Ruby interface** across all endpoints. You always work with Ruby hashes and objects — the gem picks the best format (JSON or XML) for each endpoint internally:
|
|
22
22
|
|
|
23
|
-
| Endpoint
|
|
24
|
-
|
|
25
|
-
| Authorize | JSON
|
|
26
|
-
| PreAdvice | XML
|
|
27
|
-
| Track
|
|
23
|
+
| Endpoint | Request Format | Response Format |
|
|
24
|
+
| --------- | -------------- | --------------- |
|
|
25
|
+
| Authorize | JSON | JSON |
|
|
26
|
+
| PreAdvice | XML | XML |
|
|
27
|
+
| Track | XML | JSON |
|
|
28
|
+
| Locator | JSON | JSON |
|
|
28
29
|
|
|
29
30
|
JSON is used wherever the DPD API supports it (simpler, no XML parsing overhead). XML is used only where the API requires it. This is entirely invisible to gem consumers.
|
|
30
31
|
|
|
@@ -161,6 +162,48 @@ The `tracking_type` defaults to `"consignment"` but can be overridden:
|
|
|
161
162
|
tracking = client.track.find("800436802", tracking_type: "parcel")
|
|
162
163
|
```
|
|
163
164
|
|
|
165
|
+
### Locator
|
|
166
|
+
|
|
167
|
+
#### List
|
|
168
|
+
|
|
169
|
+
Retrieve DPD Ireland drop-off locations. Test and deactivated locations are automatically filtered out.
|
|
170
|
+
|
|
171
|
+
```ruby
|
|
172
|
+
locations = client.locator.list
|
|
173
|
+
|
|
174
|
+
locations.each do |location|
|
|
175
|
+
puts location.location_name
|
|
176
|
+
puts location.location_type # "Pickup" or "Depot" or "Locker"
|
|
177
|
+
puts location.location_id
|
|
178
|
+
puts location.location_address_line1
|
|
179
|
+
puts location.location_code
|
|
180
|
+
puts location.county
|
|
181
|
+
puts location.country
|
|
182
|
+
puts location.gps_lat
|
|
183
|
+
puts location.gps_long
|
|
184
|
+
puts location.depot_no
|
|
185
|
+
puts location.province
|
|
186
|
+
puts location.facilities
|
|
187
|
+
puts location.group_pudo_id
|
|
188
|
+
end
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Filter by type or specific location ID:
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
194
|
+
# Only depots
|
|
195
|
+
locations = client.locator.list(type: "Depot")
|
|
196
|
+
|
|
197
|
+
# Only pickups
|
|
198
|
+
locations = client.locator.list(type: "Pickup")
|
|
199
|
+
|
|
200
|
+
# Only lockers
|
|
201
|
+
locations = client.locator.list(type: "Locker")
|
|
202
|
+
|
|
203
|
+
# Specific location
|
|
204
|
+
locations = client.locator.list(location_id: "5308")
|
|
205
|
+
```
|
|
206
|
+
|
|
164
207
|
### Response Objects
|
|
165
208
|
|
|
166
209
|
All endpoints return response objects that provide:
|
data/lib/dpd_ie_api/client.rb
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module DpdIeApi
|
|
6
|
+
module Resources
|
|
7
|
+
class Locator
|
|
8
|
+
LOCATOR_PATH = '/common/api/dpdlocation'
|
|
9
|
+
|
|
10
|
+
def initialize(client)
|
|
11
|
+
@client = client
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def list(type: nil, location_id: nil)
|
|
15
|
+
response = post_request(type, location_id)
|
|
16
|
+
parsed = parse_response(response)
|
|
17
|
+
filter_locations(parsed)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def post_request(type, location_id)
|
|
23
|
+
response = @client.connection.post(LOCATOR_PATH) do |req|
|
|
24
|
+
req.headers['Content-Type'] = 'application/json'
|
|
25
|
+
req.headers['Accept'] = 'application/json'
|
|
26
|
+
req.body = {
|
|
27
|
+
'CountryCode' => 'IE',
|
|
28
|
+
'Type' => type.to_s,
|
|
29
|
+
'LocationID' => location_id.to_s
|
|
30
|
+
}.to_json
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
unless response.success?
|
|
34
|
+
raise DpdIeApi::Error.new(
|
|
35
|
+
"Failed to fetch locations: #{response.status} - #{response.body}",
|
|
36
|
+
response_http_code: response.status,
|
|
37
|
+
response_body: response.body
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
response
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def parse_response(response)
|
|
45
|
+
parsed = JSON.parse(response.body)
|
|
46
|
+
|
|
47
|
+
if parsed['Status'] != 'OK'
|
|
48
|
+
raise DpdIeApi::Error.new(
|
|
49
|
+
"Locator error: #{parsed['Status']}",
|
|
50
|
+
response_http_code: response.status,
|
|
51
|
+
response_body: response.body
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
parsed
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def filter_locations(parsed)
|
|
59
|
+
locations = parsed['Location']
|
|
60
|
+
locations = [locations] if locations.is_a?(Hash)
|
|
61
|
+
locations = [] if locations.nil?
|
|
62
|
+
|
|
63
|
+
locations
|
|
64
|
+
.reject { |loc| loc['locationName']&.match?(/test|do not reactivate/i) }
|
|
65
|
+
.map { |loc| Objects::Locator.new(loc) }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/lib/dpd_ie_api/version.rb
CHANGED
data/lib/dpd_ie_api.rb
CHANGED
|
@@ -5,12 +5,14 @@ require_relative 'dpd_ie_api/objects/base'
|
|
|
5
5
|
require_relative 'dpd_ie_api/objects/auth'
|
|
6
6
|
require_relative 'dpd_ie_api/objects/preadvice'
|
|
7
7
|
require_relative 'dpd_ie_api/objects/track'
|
|
8
|
+
require_relative 'dpd_ie_api/objects/locator'
|
|
8
9
|
require_relative 'dpd_ie_api/xml_builder'
|
|
9
10
|
require_relative 'dpd_ie_api/xml_parser'
|
|
10
11
|
require_relative 'dpd_ie_api/auth'
|
|
11
12
|
require_relative 'dpd_ie_api/client'
|
|
12
13
|
require_relative 'dpd_ie_api/resources/preadvice'
|
|
13
14
|
require_relative 'dpd_ie_api/resources/track'
|
|
15
|
+
require_relative 'dpd_ie_api/resources/locator'
|
|
14
16
|
|
|
15
17
|
module DpdIeApi
|
|
16
18
|
class Error < StandardError
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dpd_ie_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Linh Ho
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -99,8 +99,10 @@ files:
|
|
|
99
99
|
- lib/dpd_ie_api/client.rb
|
|
100
100
|
- lib/dpd_ie_api/objects/auth.rb
|
|
101
101
|
- lib/dpd_ie_api/objects/base.rb
|
|
102
|
+
- lib/dpd_ie_api/objects/locator.rb
|
|
102
103
|
- lib/dpd_ie_api/objects/preadvice.rb
|
|
103
104
|
- lib/dpd_ie_api/objects/track.rb
|
|
105
|
+
- lib/dpd_ie_api/resources/locator.rb
|
|
104
106
|
- lib/dpd_ie_api/resources/preadvice.rb
|
|
105
107
|
- lib/dpd_ie_api/resources/track.rb
|
|
106
108
|
- lib/dpd_ie_api/version.rb
|