Module: Audiences
- Included in:
- Streamdal::Client, Streamdal::TestObj
- Defined in:
- lib/audiences.rb
Instance Method Summary collapse
- #_add_audience(aud) ⇒ Object
- #_add_audiences ⇒ Object
- #_seen_audience(aud) ⇒ Object
- #aud_to_str(aud) ⇒ Object
- #str_to_aud(str) ⇒ Object
Instance Method Details
#_add_audience(aud) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/audiences.rb', line 21 def _add_audience(aud) # Add an audience to the local cache map and send to server if _seen_audience(aud) return end @audiences[aud_to_str(aud)] = aud req = Streamdal::Protos::NewAudienceRequest.new req.session_id = @session_id req.audience = aud @stub.new_audience(req, metadata: ) end |
#_add_audiences ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/audiences.rb', line 35 def _add_audiences # This method is used to re-announce audiences after a disconnect @audiences.each do |aud| req = Streamdal::Protos::NewAudienceRequest.new req.session_id = @session_id req.audience = aud @stub.new_audience(req, metadata: ) end end |
#_seen_audience(aud) ⇒ Object
17 18 19 |
# File 'lib/audiences.rb', line 17 def _seen_audience(aud) @audiences.key?(aud_to_str(aud)) end |
#aud_to_str(aud) ⇒ Object
2 3 4 |
# File 'lib/audiences.rb', line 2 def aud_to_str(aud) "#{aud.service_name}.#{aud.component_name}.#{aud.operation_type}.#{aud.operation_name}" end |
#str_to_aud(str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/audiences.rb', line 6 def str_to_aud(str) # TODO: move to common package parts = str.split(".") aud = Streamdal::Protos::Audience.new aud.service_name = parts[0] aud.component_name = parts[1] aud.operation_type = parts[2] aud.operation_name = parts[3] aud end |