Sha256: 7a981dc66ce15f83fbac06f537c3c4a414d0c79fec3ee33cb11a719f52d0079a

Contents?: true

Size: 1.99 KB

Versions: 35

Compression:

Stored size: 1.99 KB

Contents

# soap/attachment.rb: SOAP4R - SwA implementation.
# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.

# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.


require 'soap/baseData'
require 'soap/mapping'


module SOAP


class SOAPAttachment < SOAPExternalReference
  attr_reader :data

  def initialize(value)
    super()
    @data = value
  end

private

  def external_contentid
    @data.contentid
  end
end


class Attachment
  attr_reader :io
  attr_accessor :contenttype

  def initialize(string_or_readable = nil)
    @string_or_readable = string_or_readable
    @contenttype = "application/octet-stream"
    @contentid = nil
    @content = nil
  end

  def contentid
    @contentid ||= Attachment.contentid(self)
  end

  def contentid=(contentid)
    @contentid = contentid
  end

  def mime_contentid
    '<' + contentid + '>'
  end

  def content
    if @content == nil and @string_or_readable != nil
      @content = @string_or_readable.respond_to?(:read) ?
	@string_or_readable.read : @string_or_readable
    end
    @content
  end

  def to_s
    content
  end

  def write(out)
    out.write(content)
  end

  def save(filename)
    File.open(filename, "wb") do |f|
      write(f)
    end
  end

  def self.contentid(obj)
    # this needs to be fixed
    [obj.__id__.to_s, Process.pid.to_s].join('.')
  end

  def self.mime_contentid(obj)
    '<' + contentid(obj) + '>'
  end
end


module Mapping
  class AttachmentFactory < SOAP::Mapping::Factory
    def obj2soap(soap_class, obj, info, map)
      soap_obj = soap_class.new(obj)
      mark_marshalled_obj(obj, soap_obj)
      soap_obj
    end

    def soap2obj(obj_class, node, info, map)
      obj = node.data
      mark_unmarshalled_obj(node, obj)
      return true, obj
    end
  end

  DefaultRegistry.add(::SOAP::Attachment, ::SOAP::SOAPAttachment,
    AttachmentFactory.new, nil)
end


end

Version data entries

35 entries across 35 versions & 15 rubygems

Version Path
mumboe-soap4r-1.6.0.pre.beta lib/soap/attachment.rb
DefV-soap4r-1.5.8.2 lib/soap/attachment.rb
mumboe-soap4r-1.5.8.7 lib/soap/attachment.rb
soap2r-1.5.8 lib/soap/attachment.rb
teo-soap4r-1.5.9b lib/soap/attachment.rb
mumboe-soap4r-1.5.8.6 lib/soap/attachment.rb
soap4r-spox-1.6.0 lib/soap/attachment.rb
soap4r-r19-1.5.9 lib/soap/attachment.rb
mumboe-soap4r-1.5.8.5 lib/soap/attachment.rb
soap4r-ruby1.9-2.0.5 lib/soap/attachment.rb
soap4r-sgonyea-1.6.0 lib/soap/attachment.rb
soap4r-straightjacket-1.5.9 lib/soap/attachment.rb
soap4r-straightjacket-1.5.8 lib/soap/attachment.rb
soap4r-ruby1.9-2.0.3 lib/soap/attachment.rb
soap4r-ruby1.9-2.0.2 lib/soap/attachment.rb
soap4r-ruby1.9-2.0.1 lib/soap/attachment.rb
mumboe-soap4r-1.5.8.4 lib/soap/attachment.rb
railsware-soap4r-1.5.8.1 lib/soap/attachment.rb
soap4r-ruby1.9-2.0.0 lib/soap/attachment.rb
hands-soap4r-1.5.8.4 lib/soap/attachment.rb