lib/soapy_cake/client.rb in soapy_cake-1.15.0 vs lib/soapy_cake/client.rb in soapy_cake-1.16.0
- old
+ new
@@ -1,14 +1,17 @@
module SoapyCake
class Client
- attr_reader :domain, :api_key, :time_offset
+ attr_reader :domain, :api_key, :time_converter
def initialize(opts = {})
@domain = opts.fetch(:domain, ENV['CAKE_DOMAIN']) || fail(Error, 'Cake domain missing')
@api_key = opts.fetch(:api_key, ENV['CAKE_API_KEY']) || fail(Error, 'Cake API key missing')
- @time_offset = opts.fetch(:time_offset, ENV['CAKE_TIME_OFFSET']) ||
- fail(Error, 'Cake time offset missing')
+
+ time_offset = opts.fetch(:time_offset, ENV['CAKE_TIME_OFFSET'])
+ time_zone = opts.fetch(:time_zone, ENV['CAKE_TIME_ZONE'])
+ @time_converter = TimeConverter.new(time_zone, time_offset)
+
@opts = opts
end
def xml_response?
opts[:xml_response] == true
@@ -18,14 +21,13 @@
attr_reader :opts
def run(request)
request.api_key = api_key
- request.time_offset = time_offset
+ request.time_converter = time_converter
- Response
- .new(response_body(request), request.short_response?, time_offset)
- .public_send(:"to_#{xml_response? ? 'xml' : 'enum'}")
+ response = Response.new(response_body(request), request.short_response?, time_converter)
+ xml_response? ? response.to_xml : response.to_enum
end
private
def response_body(request)