class Icss::Meta::Message

Describes an Avro Message

A message has attributes:

A request parameter list is processed equivalently to an anonymous record. Since record field lists may vary between reader and writer, request parameters may also differ between the caller and responder, and such differences are resolved in the same manner as record field differences.

predefine so we can use below

Attributes

protocol[RW]

this is defined in sample_message_call.rb – since we don't do referenced types yet

Public Instance Methods

first_sample_request_param() click to toggle source
# File lib/icss/message.rb, line 61
def first_sample_request_param
  req = samples.first.request.first rescue nil
  req || {}
end
fullname() click to toggle source
# File lib/icss/message.rb, line 49
def fullname
  "#{protocol.fullname}.#{basename}"
end
geolocators() click to toggle source
# File lib/icss/message.rb, line 92
def geolocators
  request_decorators[:anchors]
end
is_a_geo?() click to toggle source

GEO

# File lib/icss/message.rb, line 70
def is_a_geo?
  geolocators.present?
end
params_type() click to toggle source

the type of the message's params (by convention, its first request field)

# File lib/icss/message.rb, line 57
def params_type
  request.first ? request.first.type : {}
end
path() click to toggle source
# File lib/icss/message.rb, line 52
def path
  fullname.gsub(%r{\.},'/')
end
receive_is_geo(val) click to toggle source
# File lib/icss/message.rb, line 75
def receive_is_geo(val)
  return unless val
  unless defined?(Icss::Meta::Req::Geolocator) then
    warn "View helpers can\'t help with geolocators: Icss::Meta::Req::Geolocator type is missing. Is the catalog loaded properly?"
    return
  end
  self.request_decorators = {
    :anchors => [
      Icss::Meta::Req::PointWithRadiusGeolocator,
      Icss::Meta::Req::AddressTextGeolocator,
      Icss::Meta::Req::TileXYZoomGeolocator,
      Icss::Meta::Req::BoundingBoxGeolocator,
      Icss::Meta::Req::IpAddressGeolocator
    ],
  }
end
to_hash() click to toggle source

Conversion

# File lib/icss/message.rb, line 99
def to_hash()
  {
    :request  => summary_of_request_attr,
    :response => summary_of_response_attr,
    :doc      => doc,
    :errors   => (errors.blank? ? nil : errors),
    :samples  => samples.map(&:to_hash).map(&:compact_blank),
    :initial_free_qty => initial_free_qty,
    :price_per_k_in_cents => price_per_k_in_cents,
  }.compact
end
to_json(*args) click to toggle source
# File lib/icss/message.rb, line 110
def to_json(*args) to_hash.to_json(*args) ; end

Private Instance Methods

summary_of_request_attr() click to toggle source
# File lib/icss/message.rb, line 120
def summary_of_request_attr
  request.map do |req|
    case
    when req.blank?        then req
    # Is there a case where this needs to be a string and not a hash?
    # when req.is_reference? then req.type.fullname
    else                        req.to_schema.compact_blank
    end
  end
end
summary_of_response_attr() click to toggle source
# File lib/icss/message.rb, line 113
def summary_of_response_attr
  case
  when response.blank?        then response
  when @response_referenceness then response.fullname
  else response.to_schema.compact_blank
  end
end