Skip to content

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlok committed May 16, 2013
1 parent 8e4de58 commit b508916
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/zuora/soap_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
Zuora::Api.instance.request(:create) do |xml|
xml.__send__(zns, :zObjects, 'xsi:type' => "#{ons}:#{remote_name}") do |a|
@model.to_hash.each do |k,v|
a.__send__(ons, k.to_s.zuora_camelize.to_sym, v) unless v.nil?
a.__send__(ons, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil?
end
generate_complex_objects(a, :create)
end
Expand All @@ -32,7 +32,7 @@ def update
a.__send__(ons, :Id, obj_id)
change_syms = @model.changed.map(&:to_sym)
obj_attrs.reject{|k,v| @model.read_only_attributes.include?(k) }.each do |k,v|
a.__send__(ons, k.to_s.zuora_camelize.to_sym, v) if change_syms.include?(k)
a.__send__(ons, k.to_s.zuora_camelize.to_sym, convert_value(v)) if change_syms.include?(k)
end
generate_complex_objects(a, :update)
end
Expand All @@ -43,7 +43,7 @@ def generate
Zuora::Api.instance.request(:generate) do |xml|
xml.__send__(zns, :zObjects, 'xsi:type' => "#{ons}:#{remote_name}") do |a|
@model.to_hash.each do |k, v|
a.__send__(ons, k.to_s.zuora_camelize.to_sym, v) unless v.nil?
a.__send__(ons, k.to_s.zuora_camelize.to_sym, convert_value(v)) unless v.nil?
end
end
end
Expand Down Expand Up @@ -89,6 +89,15 @@ def parse_attributes(type, attrs={})

protected

# Zuora doesn't like the default string format of ruby dates/times
def convert_value(value)
if [Date, Time, DateTime].any? { |klass| value.is_a?(klass) }
value.strftime('%FT%T')
else
value
end
end

# generate complex objects for inclusion when creating and updating records
def generate_complex_objects(builder, action)
@model.complex_attributes.each do |var, scope|
Expand Down

0 comments on commit b508916

Please sign in to comment.