diff options
| author | Luc Donnet | 2015-04-27 14:17:12 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2015-04-27 14:17:12 +0200 | 
| commit | e470b78a10672fd927de4cd9b3ac6cae0097e12a (patch) | |
| tree | cd4231eb52ddb42099e0779f4579a7e58354e4f1 /lib/ievkit | |
| parent | 8a51a1dbaede1ad6bc4e39b7c28639d43e83d7c7 (diff) | |
| download | chouette-core-e470b78a10672fd927de4cd9b3ac6cae0097e12a.tar.bz2 | |
Fix import request to IEV
Diffstat (limited to 'lib/ievkit')
| -rw-r--r-- | lib/ievkit/client.rb | 3 | ||||
| -rw-r--r-- | lib/ievkit/serializer.rb | 22 | 
2 files changed, 22 insertions, 3 deletions
| 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 | 
