Class: Icss::Meta::Message

Inherits:
Object show all
Includes:
ReceiverModel
Defined in:
lib/icss/message.rb,
lib/icss/protocol.rb,
lib/icss/message/message_sample.rb

Overview

predefine so we can use below

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReceiverModel

included, #tree_merge!

Methods included from ReceiverModel::ActsAsTuple

included, #to_tuple

Methods included from RecordModel

#attr_set?, included, #receive!, #to_zaml

Methods included from ReceiverModel::ActsAsLoadable

#merge_from_file!

Methods included from ReceiverModel::ActsAsHash

#[], #[]=, #attributes, #delete, included, #keys

Instance Attribute Details

#protocolObject

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



33
34
35
# File 'lib/icss/message.rb', line 33

def protocol
  @protocol
end

Instance Method Details

#first_sample_request_paramObject



61
62
63
64
# File 'lib/icss/message.rb', line 61

def first_sample_request_param
  req = samples.first.request.first rescue nil
  req || {}
end

#fullnameObject



49
50
51
# File 'lib/icss/message.rb', line 49

def fullname
  "#{protocol.fullname}.#{basename}"
end

#geolocatorsObject



92
93
94
# File 'lib/icss/message.rb', line 92

def geolocators
  request_decorators[:anchors]
end

#is_a_geo?Boolean


GEO

Returns:



70
71
72
# File 'lib/icss/message.rb', line 70

def is_a_geo?
  geolocators.present?
end

#params_typeObject

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



57
58
59
# File 'lib/icss/message.rb', line 57

def params_type
  request.first ? request.first.type : {}
end

#pathObject



52
53
54
# File 'lib/icss/message.rb', line 52

def path
  fullname.gsub(%r{\.},'/')
end

#receive_is_geo(val) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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_hashObject

Conversion



99
100
101
102
103
104
105
106
107
108
109
# 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) ⇒ Object



110
# File 'lib/icss/message.rb', line 110

def to_json(*args) to_hash.to_json(*args) ; end