class Icss::Meta::Message
Describes an Avro Message
A message has attributes:
-
doc: an optional description of the message,
-
request: a list of named, typed parameter schemas (this has the same form as the fields of a record declaration);
-
response: a valid schema for the response
-
errors: an optional union of error schemas.
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
this is defined in sample_message_call.rb – since we don't do referenced types yet
Public Instance Methods
# File lib/icss/message.rb, line 61 def first_sample_request_param req = samples.first.request.first rescue nil req || {} end
# File lib/icss/message.rb, line 49 def fullname "#{protocol.fullname}.#{basename}" end
# File lib/icss/message.rb, line 92 def geolocators request_decorators[:anchors] end
GEO
# File lib/icss/message.rb, line 70 def is_a_geo? geolocators.present? end
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
# File lib/icss/message.rb, line 52 def path fullname.gsub(%r{\.},'/') end
# 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
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
# File lib/icss/message.rb, line 110 def to_json(*args) to_hash.to_json(*args) ; end
Private Instance Methods
# 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
# 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