From e470b78a10672fd927de4cd9b3ac6cae0097e12a Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Mon, 27 Apr 2015 14:17:12 +0200 Subject: Fix import request to IEV --- lib/ievkit/client.rb | 3 +++ lib/ievkit/serializer.rb | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'lib/ievkit') diff --git a/lib/ievkit/client.rb b/lib/ievkit/client.rb index e35bbd0b3..5df3ca1d2 100644 --- a/lib/ievkit/client.rb +++ b/lib/ievkit/client.rb @@ -150,8 +150,11 @@ module Ievkit # # @return [Sawyer::Agent] def multipart_agent + sawyer_options[:serializer] = Ievkit::Serializer.multipart + @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http| http.headers[:accept] = default_media_type + http.headers[:content_type] = "multipart/form-data" http.headers[:user_agent] = user_agent # Activate if authentication is needed diff --git a/lib/ievkit/serializer.rb b/lib/ievkit/serializer.rb index c9a0247ef..8110ab3b5 100644 --- a/lib/ievkit/serializer.rb +++ b/lib/ievkit/serializer.rb @@ -31,6 +31,21 @@ module Ievkit rescue LoadError end + def self.multipart + new(IevMultipart) + rescue LoadError + end + + class IevMultipart + def self.dump(data) + data + end + + def self.load(data) + data + end + end + # Public: Wraps a serialization format for Sawyer. Nested objects are # prepared for serialization (such as changing Times to ISO 8601 Strings). # Any serialization format that responds to #dump and #load will work. @@ -46,9 +61,8 @@ module Ievkit # # Returns an encoded String. def encode(data) - data #@dump.call(encode_object(data)) + @dump.call(encode_object(data)) end - alias dump encode # Public: Decodes a String into an Object (usually a Hash or Array of @@ -78,8 +92,10 @@ module Ievkit when Date then hash[key] = value.to_time.utc.xmlschema when Time then hash[key] = value.utc.xmlschema when Hash then hash[key] = encode_hash(value) + when UploadIO then hash[key] = value end end + puts "hash #{hash.inspect}" hash end @@ -107,7 +123,7 @@ module Ievkit value end elsif value.is_a?(Integer) || value.is_a?(Float) - Time.at(value) + Time.at(value) else value end -- cgit v1.2.3