Skip to content

Commit

Permalink
👽 Update transit times api
Browse files Browse the repository at this point in the history
  • Loading branch information
dvstrauss committed May 17, 2023
1 parent 55ee72a commit e1aef46
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
12 changes: 8 additions & 4 deletions lib/postnord/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.call(params)
end

def self.client
@client ||= Client.new
@client ||= Client.new(options)
end

private
Expand All @@ -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
20 changes: 12 additions & 8 deletions lib/postnord/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand All @@ -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
21 changes: 21 additions & 0 deletions lib/postnord/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
2 changes: 1 addition & 1 deletion lib/postnord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Postnord
VERSION = "0.3.0"
VERSION = "1.0.0"
end

0 comments on commit e1aef46

Please sign in to comment.