hermes_api 0.5.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e400e9d1240ecc150a2874ba335cc33bd21c277fb73260669caabcddd80abaa
4
- data.tar.gz: f6518ec3b0f4f8dfad5ea3e628434cca6201a81da372472fb32fca8889232b90
3
+ metadata.gz: d5896cee8aed7835bdfdcbbd099b4be1f2c35decd1add36b08895745cbe22383
4
+ data.tar.gz: fac5b17bd6b39ef50c760dd943245dea3a534963fc31a9d20065474065363f12
5
5
  SHA512:
6
- metadata.gz: 4bc7d0a0e966bbfc27b3069ed5144093d9fdb5734d51c940977a1d2bc5552d6de432313c4cff7d8438cc8a6583742ed37b24a0fa99fcee6561ae192e82432420
7
- data.tar.gz: 5bcb49363c64277def2894e6abb8c2e9858956e71a64f41064fe54a74e574bf4a4afbd26c09678c3c6800b2de41067b526d94093272ecebfa2b587b82f916b9c
6
+ metadata.gz: 5d791e39c4062ffa6ad37d511bd25af49075e4b605adf4846e83c822465bb9e071fb275e69f17fcf8d38737a297c418a3dc39f373df2eb86511e8cbc9fadb1c1
7
+ data.tar.gz: 7a7eacbfba0a767478db31525cfbb37d97cd9ef55d3edf6b58054225450ce609c14ce630698fda85eccb70060dcfe7b0e165a9b517da0dae95bcc286d31919f9
data/Gemfile.lock CHANGED
@@ -1,14 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hermes_api (0.5.0)
4
+ hermes_api (0.7.1)
5
5
  activeresource (>= 4.1.0, < 6.0.0)
6
+ rexml (~> 3.2, >= 3.2.4)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- activemodel (6.1.4)
11
- activesupport (= 6.1.4)
11
+ activemodel (6.1.4.4)
12
+ activesupport (= 6.1.4.4)
12
13
  activemodel-serializers-xml (1.0.2)
13
14
  activemodel (> 5.x)
14
15
  activesupport (> 5.x)
@@ -17,7 +18,7 @@ GEM
17
18
  activemodel (>= 5.0, < 7)
18
19
  activemodel-serializers-xml (~> 1.0)
19
20
  activesupport (>= 5.0, < 7)
20
- activesupport (6.1.4)
21
+ activesupport (6.1.4.4)
21
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
22
23
  i18n (>= 1.6, < 2)
23
24
  minitest (>= 5.1)
@@ -47,14 +48,14 @@ GEM
47
48
  guard (~> 2.1)
48
49
  guard-compat (~> 1.1)
49
50
  rspec (>= 2.99.0, < 4.0)
50
- i18n (1.8.10)
51
+ i18n (1.8.11)
51
52
  concurrent-ruby (~> 1.0)
52
53
  listen (3.5.1)
53
54
  rb-fsevent (~> 0.10, >= 0.10.3)
54
55
  rb-inotify (~> 0.9, >= 0.9.10)
55
56
  lumberjack (1.2.8)
56
57
  method_source (1.0.0)
57
- minitest (5.14.4)
58
+ minitest (5.15.0)
58
59
  nenv (0.3.0)
59
60
  notiffany (0.1.3)
60
61
  nenv (~> 0.1)
@@ -111,9 +112,10 @@ GEM
111
112
  tzinfo (2.0.4)
112
113
  concurrent-ruby (~> 1.0)
113
114
  unicode-display_width (2.0.0)
114
- zeitwerk (2.4.2)
115
+ zeitwerk (2.5.3)
115
116
 
116
117
  PLATFORMS
118
+ arm64-darwin-21
117
119
  x86_64-darwin-19
118
120
 
119
121
  DEPENDENCIES
@@ -129,4 +131,4 @@ DEPENDENCIES
129
131
  standard
130
132
 
131
133
  BUNDLED WITH
132
- 2.2.24
134
+ 2.3.4
data/bin/console CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "pry"
4
5
  require "bundler/setup"
5
6
  require "dotenv/load"
6
7
  require "dev/zeitwerk_loader"
@@ -11,5 +12,4 @@ require "hermes_api"
11
12
  set_config
12
13
 
13
14
  # (If you use this, don't forget to add pry to your Gemfile!)
14
- require "pry"
15
15
  Pry.start
data/hermes_api.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_dependency "activeresource", ">= 4.1.0", "< 6.0.0"
33
+ spec.add_dependency "rexml", "~> 3.2", ">= 3.2.4"
33
34
 
34
35
  spec.add_development_dependency "rspec", "~> 3.2"
35
36
  spec.add_development_dependency "dotenv"
data/lib/dev/config.rb CHANGED
@@ -2,7 +2,9 @@ require "dotenv/load"
2
2
 
3
3
  def set_config
4
4
  HermesAPI.configure do |config|
5
- config.env = :production
5
+ config.env = :test
6
+ # Set to production when testing HermesAPI::TrackingEvent resource
7
+ # config.env = :production
6
8
  config.proxy = ENV["HERMES_API_PROXY"]
7
9
  end
8
10
  end
@@ -1,10 +1,5 @@
1
1
  module HermesAPI
2
2
  mattr_accessor :cache
3
3
 
4
- self.cache = if defined?(Rails) && Rails.respond_to?(:cache) &&
5
- Rails.cache.is_a?(ActiveSupport::Cache::Store)
6
- Rails.cache
7
- else
8
- ActiveSupport::Cache::MemoryStore.new
9
- end
10
- end
4
+ self.cache = ActiveSupport::Cache::MemoryStore.new
5
+ end
@@ -25,6 +25,10 @@ module HermesAPI
25
25
 
26
26
  HermesAPI::JsonBase.site = config.env.to_s == "production" ? JSON_PRODUCTION_SITE : JSON_TESTING_SITE
27
27
  HermesAPI::OAuth.site = config.env.to_s == "production" ? OAUTH_PRODUCTION_SITE : OAUTH_TESTING_SITE
28
+
29
+ if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache.is_a?(ActiveSupport::Cache::Store)
30
+ HermesAPI.cache = Rails.cache
31
+ end
28
32
  end
29
33
 
30
34
  def configure
@@ -4,18 +4,50 @@ module HermesAPI
4
4
  ActiveResource::Formats::XmlFormat.decode(@response.body)
5
5
  end
6
6
 
7
- def to_s
8
- response = ActiveResource::Formats::XmlFormat.decode(@response.body)
9
- entries = response.dig("routingResponseEntries", "routingResponseEntry")
7
+ def code
8
+ if entries.is_a? Array
9
+ entries.map do |entry|
10
+ entry.dig("errorMessages", "errorCode")
11
+ end
12
+ else
13
+ entries.dig("errorMessages", "errorCode")
14
+ end
15
+ end
16
+
17
+ alias_method :codes, :code
18
+
19
+ def description
20
+ unless entries.is_a? Array
21
+ entries.dig("errorMessages", "errorDescription")
22
+ end
23
+ end
24
+
25
+ def code_with_descriptions
10
26
  if entries.is_a? Array
11
27
  entries.map do |entry|
12
- error = entry.dig("errorMessages")
13
- "Something went wrong, Error Code: #{error["errorCode"]}, Error Description: #{error["errorDescription"]}."
14
- end.to_s
28
+ code = entry.dig("errorMessages", "errorCode")
29
+ description = entry.dig("errorMessages", "errorDescription")
30
+ "#{code}: #{description}"
31
+ end
32
+ end
33
+ end
34
+
35
+ def to_s
36
+ if entries.is_a? Array
37
+ "#{code_with_descriptions.join(", ")}."
15
38
  else
16
- error = entries.dig("errorMessages")
17
- "Something went wrong. Error Code: #{error["errorCode"]} Error Description: #{error["errorDescription"]}"
39
+ "#{code}: #{description}."
18
40
  end
19
41
  end
42
+
43
+ private
44
+
45
+ def decoded_response
46
+ ActiveResource::Formats::XmlFormat.decode(@response.body)
47
+ end
48
+
49
+ def entries
50
+ decoded_response.dig("routingResponseEntries", "routingResponseEntry")
51
+ end
20
52
  end
21
53
  end
@@ -29,8 +29,13 @@ module HermesAPI
29
29
  super
30
30
  end
31
31
 
32
+ def load(attributes, remove_root = false, persisted = false)
33
+ attributes.deep_transform_keys! { |k| k.to_s.underscore }
34
+ super
35
+ end
36
+
32
37
  def to_xml(options = {})
33
- super({root: self.class.root}.merge(options))
38
+ super({root: self.class.root, camelize: :lower}.merge(options))
34
39
  end
35
40
  end
36
41
  end
@@ -0,0 +1,166 @@
1
+ module HermesAPI
2
+ class DropOffReturnLabel < Base
3
+ # Create return label(s) wheredrop off at ParcelShops.
4
+ # HermesUK doc: https://drive.google.com/file/d/1lVuHd2o4nDWrGkacG0GrvNm7LYVL_bFd/view?usp=sharing
5
+ # You can choose to create a batch of return labels by passing in multiple collectionRoutingRequestEntry.
6
+ # Example:
7
+ # HermesAPI::Base.with_session("username", "password") do
8
+ # request_body = {client_id: "1234",
9
+ # client_name: "Leggings",
10
+ # child_client_id: "",
11
+ # child_client_name: "",
12
+ # source_of_request: "CLIENTWS",
13
+ # collection_routing_request_entries: [{ # collectionRoutingRequestEntry
14
+ # customer: {
15
+ # address: {
16
+ # first_name: "Leonie", lastame: "E", houseName: "2", streetName: "Street",
17
+ # addressLine1: "2 Street", addressLine2: "Fulham", postCode: "SW6 6EL",
18
+ # city: "London", region: "", countryCode: "GB"
19
+ # },
20
+ # mobilePhoneNo: "+447884571522",
21
+ # email: "leonie@london.com",
22
+ # customerReference1: "8284"
23
+ # },
24
+ # countryOfOrigin: "GB"
25
+ # }]}
26
+ # @order = HermesAPI::DropOffReturnLabel.new(request_body)
27
+ # @order.save
28
+
29
+ # # Request for a single print in store QR code by wrapping in an oauth session block, only work with 1 label.
30
+ # # To request a batch of QR codes, use the HermesAPI::PrintInStoreQrCode#create directly.
31
+
32
+ # HermesAPI::PrintInStoreQrCode.with_oauth_session("api_key", "client_id/auth_id", "client_secret/auth_secret") do
33
+ # @order.request_print_in_store_qr_code(
34
+ # delivery_address: {
35
+ # name: "Andy",
36
+ # address_line1: "7 Street",
37
+ # address_line2: "Fulham",
38
+ # country_code: "GB",
39
+ # postcode: "SW6 6EL"
40
+ # },
41
+ # dimensions: {
42
+ # depth: 15,
43
+ # length: 20,
44
+ # width: 15,
45
+ # weight: 1
46
+ # },
47
+ # value: {
48
+ # currency: "GBP",
49
+ # amount: 10
50
+ # }
51
+ # )
52
+ # end
53
+ # end
54
+
55
+ include ReturnLabelHelper
56
+
57
+ self.prefix = "/routing/service/rest/v4/createReturnBarcodeAndLabel"
58
+ self.element_name = ""
59
+
60
+ DEFAULT_ATTRS = {
61
+ client_id: "",
62
+ client_name: "",
63
+ child_client_id: "",
64
+ child_client_name: "",
65
+ source_of_request: "",
66
+ collection_routing_request_entries: [{
67
+ customer: {
68
+ address: {
69
+ first_name: "",
70
+ last_name: "",
71
+ house_name: "",
72
+ street_name: "",
73
+ address_line1: "",
74
+ post_code: "",
75
+ city: "",
76
+ region: "",
77
+ country_code: ""
78
+ },
79
+ mobile_phone_no: "",
80
+ email: "",
81
+ customer_reference1: ""
82
+ },
83
+ country_of_origin: ""
84
+ }]
85
+ }
86
+
87
+ def request_print_in_store_qr_code(**attrs)
88
+ if missing_required_qr_code_attributes?(attrs)
89
+ raise ArgumentError, request_print_in_store_qr_code_error_message
90
+ end
91
+
92
+ return nil if attributes["routing_response_entries"].blank?
93
+
94
+ entries = routing_response_entries.routing_response_entry
95
+ entry = entries.is_a?(Array) ? entries[0] : entries
96
+ carrier = entry.inbound_carriers.carrier1
97
+ barcode = carrier.barcode1
98
+ customer = collection_routing_request_entries[0].customer
99
+ address = customer.address
100
+
101
+ self.print_in_store_qr_code = PrintInStoreQrCode.create(
102
+ customer: {
103
+ customer_reference1: customer.customer_reference1
104
+ },
105
+ label_type: "RETURN",
106
+ barcode: {
107
+ barcode: barcode.barcode_number,
108
+ barcode_display: barcode.barcode_display
109
+ },
110
+ client: {
111
+ client_id: client_id,
112
+ client_name: client_name
113
+ },
114
+ routing: {
115
+ delivery_method: {
116
+ delivery_method_id: carrier.delivery_method_code,
117
+ delivery_method_description: carrier.delivery_method_desc
118
+ },
119
+ sort_levels: {
120
+ sort_level1: carrier.sort_level1.strip,
121
+ sort_level2: carrier.sort_level2
122
+ }
123
+ },
124
+ service_offers: [],
125
+ **attrs
126
+ )
127
+ end
128
+
129
+ private
130
+
131
+ def missing_required_qr_code_attributes?(attrs)
132
+ ([:dimensions, :value, :delivery_address] - attrs.keys).length > 0
133
+ end
134
+
135
+ def request_print_in_store_qr_code_error_message
136
+ <<~ERR_MESSAGE
137
+ Missing required attributes
138
+ Example:
139
+
140
+ label = HermesAPI::DropOffReturnLabel.new(...)
141
+
142
+ if label.save
143
+ label.request_print_in_store_qr_code(
144
+ dimensions: {
145
+ depth: 15,
146
+ length: 20,
147
+ width: 15,
148
+ weight: 1
149
+ },
150
+ value: {
151
+ currency: 'GBP',
152
+ amount: 10
153
+ },
154
+ delivery_address: {
155
+ name: 'Don Joe',
156
+ address_line1: 'Real Logic',
157
+ address_line2: '4-4 Ridings Park, Eastern Way',
158
+ country_code: 'GB',
159
+ postcode: 'WS117FJ'
160
+ }
161
+ )
162
+ end
163
+ ERR_MESSAGE
164
+ end
165
+ end
166
+ end
@@ -6,5 +6,15 @@ module HermesAPI
6
6
  def self.inherited(subclass)
7
7
  subclass.extend(BearerAuth)
8
8
  end
9
+
10
+ def load(attributes, remove_root = false, persisted = false)
11
+ attributes.deep_transform_keys! { |k| k.to_s.underscore }
12
+ super
13
+ end
14
+
15
+ def to_json(options = {})
16
+ attributes.as_json.deep_transform_keys { |k| k.to_s.camelize(:lower) }
17
+ .to_json(include_root_in_json ? {root: self.class.element_name}.merge(options) : options)
18
+ end
9
19
  end
10
20
  end
@@ -0,0 +1,85 @@
1
+ module HermesAPI
2
+ class PickupReturnLabel < Base
3
+ # Create return label(s) with courier pickup request.
4
+ # HermesUK doc: https://drive.google.com/file/d/1lVuHd2o4nDWrGkacG0GrvNm7LYVL_bFd/view?usp=sharing
5
+ # You can choose to create a batch of return labels by passing in multiple collectionRoutingRequestEntry.
6
+ # Example:
7
+ # HermesAPI::Base.with_session("username", "password") do
8
+ # request_body = {clientId: "249",
9
+ # clientName: "Leggings",
10
+ # childClientId: "",
11
+ # childClientName: "",
12
+ # sourceOfRequest: "CLIENTWS",
13
+ # routingStartDate: Time.now.tomorrow.strftime("%Y-%m-%dT%H:%M:%S"),
14
+ # collectionRoutingRequestEntries: [{ # collectionRoutingRequestEntry
15
+ # customer: {
16
+ # address: {
17
+ # firstName: "Leonie", lastName: "E", houseName: "2", streetName: "Street",
18
+ # addressLine1: "2 Street", addressLine2: "Fulham", postCode: "SW6 6EL",
19
+ # city: "London", region: "", countryCode: "GB"
20
+ # },
21
+ # mobilePhoneNo: "+447884571522",
22
+ # email: "leonie@london.com",
23
+ # customerReference1: "8284"
24
+ # },
25
+ # parcel: {
26
+ # weight: 1,
27
+ # length: 10,
28
+ # width: 10,
29
+ # depth: 10,
30
+ # girth: 0,
31
+ # combinedDimension: 0,
32
+ # volume: 0,
33
+ # value: 10,
34
+ # description: "Parcel"
35
+ # },
36
+ # countryOfOrigin: "GB"
37
+ # }]}
38
+ # @order = HermesAPI::PickupReturnLabel.new(request_body)
39
+ # @order.save
40
+ # end
41
+
42
+ include ReturnLabelHelper
43
+
44
+ self.prefix = "/routing/service/rest/v4/routeCollectionCreatePreadviceReturnBarcodeAndLabel"
45
+ self.element_name = ""
46
+
47
+ DEFAULT_ATTRS = {
48
+ client_id: "",
49
+ client_name: "",
50
+ child_client_id: "",
51
+ child_client_name: "",
52
+ source_of_request: "",
53
+ collection_routing_request_entries: [{
54
+ customer: {
55
+ address: {
56
+ first_name: "",
57
+ last_name: "",
58
+ house_name: "",
59
+ street_name: "",
60
+ address_line1: "",
61
+ post_code: "",
62
+ city: "",
63
+ region: "",
64
+ country_code: ""
65
+ },
66
+ parcel: {
67
+ weight: 1,
68
+ length: 10,
69
+ width: 10,
70
+ depth: 10,
71
+ girth: 0,
72
+ combined_dimension: 0,
73
+ volume: 0,
74
+ value: 10,
75
+ description: "Parcel"
76
+ },
77
+ mobile_phone_no: "",
78
+ email: "",
79
+ customer_reference1: ""
80
+ },
81
+ country_of_origin: ""
82
+ }]
83
+ }
84
+ end
85
+ end
@@ -9,8 +9,8 @@ module HermesAPI
9
9
  super
10
10
  end
11
11
 
12
- def qr_code
13
- base64_data = as_json.dig("qrCode", "base64EncodedBytes")
12
+ def qr_code_image
13
+ base64_data = as_json.dig("qr_code", "base64_encoded_bytes")
14
14
  Base64.decode64(base64_data) if base64_data
15
15
  end
16
16
  end
@@ -1,11 +1,11 @@
1
1
  module HermesAPI
2
2
  class TrackingEvent < JsonBase
3
- # # Retrieve TrackingEvents by wrapping in an oauth session block
3
+ # # Retrieve TrackingEvents by wrapping in an oauth session block
4
+ #
5
+ # HermesAPI::TrackingEvent.with_oauth_session("api_key", "client_id/auth_id", "client_secret/auth_secret") do
6
+ # HermesAPI::TrackingEvent.where(barcode: "123456789")
7
+ # end
4
8
  #
5
- # HermesAPI::TrackingEvent.with_oauth_session("api_key", "client_id/auth_id", "client_secret/auth_secret") do
6
- # HermesAPI::TrackingEvent.where(barcode: "123456789")
7
- # end
8
-
9
9
  self.element_name = ""
10
10
  self.prefix = "/client-tracking-api/v1/events"
11
11
 
@@ -1,5 +1,9 @@
1
1
  module HermesAPI
2
2
  class WebTracking < ActiveResource::Base
3
+ # # Retrieve TrackingEvents from web site: https://www.myhermes.co.uk/track
4
+
5
+ # HermesAPI::WebTracking.find("1234512345")
6
+
3
7
  self.element_name = ""
4
8
  self.site = "https://api.hermesworld.co.uk"
5
9
  self.prefix = "/enterprise-tracking-api/v1/parcels"
@@ -18,11 +22,14 @@ module HermesAPI
18
22
 
19
23
  def load(attributes, remove_root = false, persisted = false)
20
24
  attributes = attributes.dig("results", 0)
21
- super(attributes)
25
+ attributes.deep_transform_keys! { |k| k.to_s.underscore }
26
+ super
22
27
  end
23
28
 
24
29
  def self.find(barcode)
25
30
  uniqueId = format.decode(connection.get("#{prefix}/search/#{barcode}", headers).body).first
31
+ return nil if uniqueId.nil?
32
+
26
33
  find_single("", params: {uniqueIds: uniqueId})
27
34
  end
28
35
  end
@@ -0,0 +1,41 @@
1
+ module HermesAPI
2
+ module ReturnLabelHelper
3
+ module ClassMethods
4
+ def root
5
+ :collectionRoutingRequest
6
+ end
7
+ end
8
+
9
+ def self.included(base_klass)
10
+ base_klass.extend(ClassMethods)
11
+ end
12
+
13
+ def labels
14
+ entries = routing_response_entries.routing_response_entry
15
+ if entries.is_a?(Array)
16
+ entries.map do |entry|
17
+ Base64.decode64(entry.inbound_carriers.label_image)
18
+ end
19
+ else
20
+ Base64.decode64(entries.inbound_carriers.label_image)
21
+ end
22
+ rescue NameError
23
+ end
24
+
25
+ alias_method :label, :labels
26
+
27
+ def tracking_numbers
28
+ entries = routing_response_entries.routing_response_entry
29
+ if entries.is_a?(Array)
30
+ entries.map do |entry|
31
+ entry.inbound_carriers.carrier1.barcode1.barcode_number
32
+ end
33
+ else
34
+ entries.inbound_carriers.carrier1.barcode1.barcode_number
35
+ end
36
+ rescue NameError
37
+ end
38
+
39
+ alias_method :tracking_number, :tracking_numbers
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HermesAPI
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.2"
5
5
  end
data/lib/hermes_api.rb CHANGED
@@ -2,19 +2,22 @@
2
2
 
3
3
  require_relative "hermes_api/version"
4
4
  require "active_resource"
5
+ require "rexml/document"
5
6
 
6
7
  module HermesAPI
7
- require "hermes_api/cache"
8
8
  require "hermes_api/bearer_auth"
9
+ require "hermes_api/cache"
9
10
  require "hermes_api/configuration"
10
- require "hermes_api/creation_error"
11
11
  require "hermes_api/connection"
12
+ require "hermes_api/creation_error"
12
13
 
13
- require "hermes_api/resources/base"
14
- require "hermes_api/resources/return_label"
14
+ require "hermes_api/shared/return_label_helper"
15
15
 
16
- require "hermes_api/resources/o_auth"
16
+ require "hermes_api/resources/base"
17
+ require "hermes_api/resources/drop_off_return_label"
17
18
  require "hermes_api/resources/json_base"
19
+ require "hermes_api/resources/o_auth"
20
+ require "hermes_api/resources/pickup_return_label"
18
21
  require "hermes_api/resources/print_in_store_qr_code"
19
22
  require "hermes_api/resources/tracking_event"
20
23
  require "hermes_api/resources/web_tracking"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.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: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rexml
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.4
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.2.4
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: rspec
35
55
  requirement: !ruby/object:Gem::Requirement
@@ -157,12 +177,14 @@ files:
157
177
  - lib/hermes_api/connection.rb
158
178
  - lib/hermes_api/creation_error.rb
159
179
  - lib/hermes_api/resources/base.rb
180
+ - lib/hermes_api/resources/drop_off_return_label.rb
160
181
  - lib/hermes_api/resources/json_base.rb
161
182
  - lib/hermes_api/resources/o_auth.rb
183
+ - lib/hermes_api/resources/pickup_return_label.rb
162
184
  - lib/hermes_api/resources/print_in_store_qr_code.rb
163
- - lib/hermes_api/resources/return_label.rb
164
185
  - lib/hermes_api/resources/tracking_event.rb
165
186
  - lib/hermes_api/resources/web_tracking.rb
187
+ - lib/hermes_api/shared/return_label_helper.rb
166
188
  - lib/hermes_api/version.rb
167
189
  homepage: https://github.com/PostCo/hermes_api
168
190
  licenses:
@@ -187,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
209
  - !ruby/object:Gem::Version
188
210
  version: '0'
189
211
  requirements: []
190
- rubygems_version: 3.2.22
212
+ rubygems_version: 3.2.32
191
213
  signing_key:
192
214
  specification_version: 4
193
215
  summary: Unofficial Ruby object based Hermes UK API wrapper.
@@ -1,185 +0,0 @@
1
- module HermesAPI
2
- class ReturnLabel < Base
3
- # Create return label(s).
4
- # You can choose to create a batch of return labels by passing in multiple collectionRoutingRequestEntry.
5
- # Example:
6
- # HermesAPI::Base.with_session("username", "password") do
7
- # request_body = {clientId: "1234",
8
- # clientName: "Life",
9
- # childClientId: "",
10
- # childClientName: "",
11
- # sourceOfRequest: "CLIENTWS",
12
- # collectionRoutingRequestEntries: [{ #collectionRoutingRequestEntry
13
- # customer: {
14
- # address: {
15
- # firstName: "Leonie", lastName: "E", houseName: "2", streetName: "Street",
16
- # addressLine1: "2 Street", addressLine2: "Fulham", postCode: "SW6 6EL",
17
- # city: "London", region: "", countryCode: "GB"
18
- # },
19
- # mobilePhoneNo: "+447884571522",
20
- # email: "leonie@london.com",
21
- # customerReference1: "8284"
22
- # },
23
- # countryOfOrigin: "GB"
24
- # }]}
25
- # @order = HermesAPI::ReturnLabel.new(request_body)
26
- # @order.save
27
- #
28
- # # Request for a single print in store QR code by wrapping in an oauth session block, only work with 1 label.
29
- # # To request a batch of QR codes, use the HermesAPI::PrintInStoreQrCode#create directly.
30
- #
31
- # HermesAPI::PrintInStoreQrCode.with_oauth_session("api_key", "client_id/auth_id", "client_secret/auth_secret") do
32
- # @order.request_print_in_store_qr_code(
33
- # deliveryAddress: {
34
- # name: "Andy",
35
- # addressLine1: "7 Street",
36
- # addressLine2: "Fulham",
37
- # countryCode: "GB",
38
- # postcode: "SW6 6EL"
39
- # },
40
- # dimensions: {
41
- # depth: 15,
42
- # length: 20,
43
- # width: 15,
44
- # weight: 1
45
- # },
46
- # value: {
47
- # currency: "GBP",
48
- # amount: 10
49
- # }
50
- # )
51
- # end
52
- # end
53
- #
54
- self.prefix = "/routing/service/rest/v4/createReturnBarcodeAndLabel"
55
- self.element_name = ""
56
-
57
- DEFAULT_ATTRS = {
58
- clientId: "",
59
- clientName: "",
60
- childClientId: "",
61
- childClientName: "",
62
- sourceOfRequest: "",
63
- collectionRoutingRequestEntries: [{
64
- customer: {
65
- address: {
66
- firstName: "",
67
- lastName: "",
68
- houseName: "",
69
- streetName: "",
70
- addressLine1: "",
71
- postCode: "",
72
- city: "",
73
- region: "",
74
- countryCode: ""
75
- },
76
- mobilePhoneNo: "",
77
- email: "",
78
- customerReference1: ""
79
- },
80
- countryOfOrigin: ""
81
- }]
82
- }
83
-
84
- def self.root
85
- :collectionRoutingRequest
86
- end
87
-
88
- def labels
89
- entries = routingResponseEntries.routingResponseEntry
90
- if entries.is_a?(Array)
91
- entries.map do |entry|
92
- Base64.decode64(entry.inboundCarriers.labelImage)
93
- end
94
- else
95
- Base64.decode64(entries.inboundCarriers.labelImage)
96
- end
97
- rescue NameError
98
- end
99
-
100
- alias_method :label, :labels
101
-
102
- def tracking_numbers
103
- entries = routingResponseEntries.routingResponseEntry
104
- if entries.is_a?(Array)
105
- entries.map do |entry|
106
- entry.inboundCarriers.carrier1.barcode1.barcodeNumber
107
- end
108
- else
109
- entries.inboundCarriers.carrier1.barcode1.barcodeNumber
110
- end
111
- rescue NameError
112
- end
113
-
114
- alias_method :tracking_number, :tracking_numbers
115
-
116
- def request_print_in_store_qr_code(**attrs)
117
- if ([:dimensions, :value, :deliveryAddress] - attrs.keys).length > 0
118
- raise ArgumentError, request_print_in_store_qr_code_error_message
119
- end
120
-
121
- return nil if attributes["routingResponseEntries"].blank?
122
-
123
- entries = routingResponseEntries.routingResponseEntry
124
- entry = entries.is_a?(Array) ? entries[0] : entries
125
- carrier = entry.inboundCarriers.carrier1
126
- barcode = carrier.barcode1
127
- customer = collectionRoutingRequestEntries[0].customer
128
- address = customer.address
129
- self.print_in_store_qr_code = PrintInStoreQrCode.create(
130
- customer: {
131
- customerReference1: customer.customerReference1
132
- },
133
- labelType: "RETURN",
134
- barcode: {
135
- barcode: barcode.barcodeNumber,
136
- barcodeDisplay: barcode.barcodeDisplay
137
- },
138
- client: {
139
- clientId: clientId,
140
- clientName: clientName
141
- },
142
- routing: {
143
- deliveryMethod: {
144
- deliveryMethodId: carrier.deliveryMethodCode,
145
- deliveryMethodDescription: carrier.deliveryMethodDesc
146
- },
147
- sortLevels: {
148
- sortLevel1: carrier.sortLevel1.strip,
149
- sortLevel2: carrier.sortLevel2
150
- }
151
- },
152
- serviceOffers: [],
153
- **attrs
154
- )
155
- end
156
-
157
- private
158
-
159
- def request_print_in_store_qr_code_error_message
160
- <<~HEREDOC
161
- Missing attributes
162
- Example:
163
- HermesAPI::ReturnLabel#request_print_in_store_qr_code(
164
- dimensions: {
165
- depth: 15,
166
- length: 20,
167
- width: 15,
168
- weight: 1
169
- },
170
- value: {
171
- currency: 'GBP',
172
- amount: 10
173
- },
174
- deliveryAddress: {
175
- name: 'Don Joe',
176
- addressLine1: 'Real Logic',
177
- addressLine2: '4-4 Ridings Park, Eastern Way',
178
- countryCode: 'GB',
179
- postcode: 'WS117FJ'
180
- }
181
- )
182
- HEREDOC
183
- end
184
- end
185
- end