class Expedition::Response

Attributes

body[R]
raw[R]
status[R]

Public Class Methods

new(normalized, raw) click to toggle source
# File lib/expedition/response.rb, line 20
def initialize(normalized, raw)
  @body   = normalized
  @raw    = raw
  @status = Status.new(raw['STATUS'])
end
parse(raw) { |normalized| ... } click to toggle source
# File lib/expedition/response.rb, line 14
def self.parse(raw)
  normalized = normalize(raw)
  normalized = yield normalized if block_given?
  new(normalized, raw)
end

Private Class Methods

normalize(value) click to toggle source
# File lib/expedition/response.rb, line 45
def self.normalize(value)
  case value
  when Hash
    Hash[value.collect { |k, v| [normalize_key(k), normalize(v)] }].with_indifferent_access
  when Array
    value.collect { |v| normalize(v) }
  else
    value
  end
end
normalize_key(key) click to toggle source
# File lib/expedition/response.rb, line 56
def self.normalize_key(key)
  key = key.gsub(/(\w)%/, '\\1_percent').gsub('%', 'percent').gsub(/[^\w]+/, ' ')
  key.strip.gsub(/\s+/, '_').downcase
end

Public Instance Methods

method_missing(method_name, *arguments, &block) click to toggle source
Calls superclass method
# File lib/expedition/response.rb, line 35
def method_missing(method_name, *arguments, &block)
  if respond_to_missing?(method_name)
    body.send(method_name, *arguments, &block)
  else
    super
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/expedition/response.rb, line 31
def respond_to_missing?(method_name, include_private = false)
  body.respond_to?(method_name) || super
end