Module: Savon::Global

Included in:
Savon
Defined in:
lib/savon/global.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#env_namespaceObject

Returns the global env_namespace.



88
89
90
# File 'lib/savon/global.rb', line 88

def env_namespace
  @env_namespace
end

#log(message) ⇒ Object

Logs a given message.



32
33
34
# File 'lib/savon/global.rb', line 32

def log(message)
  logger.send log_level, filtered(message) if log?
end

#log_filterObject

Returns the log filter. Defaults to blank.



40
41
42
# File 'lib/savon/global.rb', line 40

def log_filter
  @log_filter ||= ''
end

#log_levelObject

Returns the log level. Defaults to :debug.



27
28
29
# File 'lib/savon/global.rb', line 27

def log_level
  @log_level ||= :debug
end

#loggerObject

Returns the logger. Defaults to an instance of Logger writing to STDOUT.



19
20
21
# File 'lib/savon/global.rb', line 19

def logger
  @logger ||= ::Logger.new STDOUT
end

#raise_errors=(value) ⇒ Object (writeonly)

Sets whether to raise HTTP errors and SOAP faults.



56
57
58
# File 'lib/savon/global.rb', line 56

def raise_errors=(value)
  @raise_errors = value
end

#soap_headerObject

Returns the global soap_header.



94
95
96
# File 'lib/savon/global.rb', line 94

def soap_header
  @soap_header
end

Instance Method Details

#deprecate(message) ⇒ Object

Expects a message and raises a warning if configured.



100
101
102
# File 'lib/savon/global.rb', line 100

def deprecate(message)
  warn("Deprecation: #{message}") if deprecate?
end

#deprecate=(deprecate) ⇒ Object

Sets whether to warn about deprecations.



105
106
107
# File 'lib/savon/global.rb', line 105

def deprecate=(deprecate)
  @deprecate = deprecate
end

#deprecate?Boolean

Returns whether to warn about deprecation.

Returns:

  • (Boolean)


110
111
112
# File 'lib/savon/global.rb', line 110

def deprecate?
  @deprecate != false
end

#filtered(message) ⇒ Object

Filters Message based on log filter



45
46
47
48
49
50
51
52
53
# File 'lib/savon/global.rb', line 45

def filtered(message)
  xml = Nokogiri::XML(message)
  return message if @log_filter.empty? || !xml.errors.empty?

  @log_filter.each do |filter|
    xml.xpath("//*[local-name()='#{filter}']").map { |node| node.content = '***FILTERED***' }
  end
  return xml.root.to_s
end

#log?Boolean

Returns whether to log HTTP requests. Defaults to true.

Returns:

  • (Boolean)


11
12
13
# File 'lib/savon/global.rb', line 11

def log?
  @log != false
end

#raise_errors?Boolean

Returns whether to raise errors. Defaults to true.

Returns:

  • (Boolean)


59
60
61
# File 'lib/savon/global.rb', line 59

def raise_errors?
  @raise_errors != false
end

#reset_config!Object

Reset to default configuration.



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/savon/global.rb', line 115

def reset_config!
  self.log = true
  self.logger = ::Logger.new STDOUT
  self.log_level = :debug
  self.raise_errors = true
  self.soap_version = SOAP::DefaultVersion
  self.strip_namespaces = true
  self.env_namespace = nil
  self.soap_header = {}
  self.log_filter = ''
end

#soap_versionObject

Returns SOAP version. Defaults to DefaultVersion.



70
71
72
# File 'lib/savon/global.rb', line 70

def soap_version
  @version ||= SOAP::DefaultVersion
end

#soap_version=(version) ⇒ Object

Sets the global SOAP version.

Raises:

  • (ArgumentError)


64
65
66
67
# File 'lib/savon/global.rb', line 64

def soap_version=(version)
  raise ArgumentError, "Invalid SOAP version: #{version}" unless SOAP::Versions.include? version
  @version = version
end

#strip_namespaces=(strip) ⇒ Object

Sets whether to strip namespaces in a SOAP response Hash.



82
83
84
85
# File 'lib/savon/global.rb', line 82

def strip_namespaces=(strip)
  Savon.deprecate("use Nori.strip_namespaces= instead of Savon.strip_namespaces=")
  Nori.strip_namespaces = strip
end

#strip_namespaces?Boolean

Returns whether to strip namespaces in a SOAP response Hash. Defaults to true.

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/savon/global.rb', line 76

def strip_namespaces?
  Savon.deprecate("use Nori.strip_namespaces? instead of Savon.strip_namespaces?")
  Nori.strip_namespaces?
end