From e1aef46b0474865ea69934a5a33a2ce104143350 Mon Sep 17 00:00:00 2001 From: Daniel von Strauss <8156309+dvstrauss@users.noreply.github.com> Date: Wed, 17 May 2023 16:27:26 +0200 Subject: [PATCH] :alien: Update transit times api --- lib/postnord/base.rb | 12 ++++++++---- lib/postnord/client.rb | 20 ++++++++++++-------- lib/postnord/transport.rb | 21 +++++++++++++++++++++ lib/postnord/version.rb | 2 +- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/postnord/base.rb b/lib/postnord/base.rb index 2811e65..e638273 100644 --- a/lib/postnord/base.rb +++ b/lib/postnord/base.rb @@ -9,7 +9,7 @@ def self.call(params) end def self.client - @client ||= Client.new + @client ||= Client.new(options) end private @@ -23,15 +23,19 @@ def self.validate_params(params) end def self.action - self.name.split('::').last.tap { |e| e[0] = e[0].downcase } + self.name.split("::").last.tap { |e| e[0] = e[0].downcase } end def self.mandatory_params - fail NotImplementedError, 'mandatory_params' + fail NotImplementedError, "mandatory_params" end def self.endpoint - fail NotImplementedError, 'endpoint' + fail NotImplementedError, "endpoint" + end + + def self.options + {} end end end diff --git a/lib/postnord/client.rb b/lib/postnord/client.rb index 7120112..8c3a096 100644 --- a/lib/postnord/client.rb +++ b/lib/postnord/client.rb @@ -6,7 +6,11 @@ def initialize(options={}) @api_key = options[:api_key] || Config.api_key @api_endpoint = options[:api_endpoint] || Config.api_endpoint @locale = options[:locale] || Config.locale - @return_type = options[:return_type] || Config.return_type + @return_type = if options.has_key?(:return_type) + options[:return_type] + else + Config.return_type + end end def do_request(service, endpoint, params={}) @@ -27,13 +31,13 @@ def do_request(service, endpoint, params={}) private def build_uri(service, endpoint) - URI( - @api_endpoint + - '/' + service + - '/' + @api_version + - '/' + endpoint + - '.' + @return_type - ) + url = @api_endpoint + + "/" + service + + "/" + @api_version + + "/" + endpoint + url += "." + @return_type if @return_type + + URI(url) end end end diff --git a/lib/postnord/transport.rb b/lib/postnord/transport.rb index f27a2eb..a335732 100644 --- a/lib/postnord/transport.rb +++ b/lib/postnord/transport.rb @@ -12,6 +12,27 @@ def self.endpoint end end + class AddressToAddress < Transport + def self.mandatory_params + [ + "startTime", + "serviceGroup", + "originPostCode", + "originCountryCode", + "destinationPostCode", + "destinationCountryCode", + ] + end + + def self.action + self.name.split('::').last.downcase + end + + def self.options + { return_type: nil } + end + end + class GetTransitTimeInformation < Transport def self.mandatory_params [ diff --git a/lib/postnord/version.rb b/lib/postnord/version.rb index 73e082d..318fee5 100644 --- a/lib/postnord/version.rb +++ b/lib/postnord/version.rb @@ -1,3 +1,3 @@ module Postnord - VERSION = "0.3.0" + VERSION = "1.0.0" end