Module: Nutella::Framework::Net

Defined in:
lib/nutella_lib/framework_net.rb

Framework-level communication APIs collapse

Framework-level APIs to communicate at the run-level collapse

Framework-level APIs to communicate at the run-level (broadcast) collapse

Framework-level APIs to communicate at the application-level collapse

Framework-level APIs to communicate at the application-level (broadcast) collapse

Class Method Summary collapse

Class Method Details

.async_request(channel, message = nil, callback) ⇒ Object

Performs an asynchronous request at the framework-level

Parameters:

  • channel (String)

    the framework-level channel we want to make the request to. CANNOT contain wildcard(s)!

  • message (Object) (defaults to: nil)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.

  • callback (Proc)

    the callback that is fired whenever a response is received. It takes one parameter (response).



56
57
58
# File 'lib/nutella_lib/framework_net.rb', line 56

def self.async_request ( channel, message=nil, callback )
  Nutella::Net.async_request_to(channel, message, callback, nil, nil)
end

.async_request_to_all_apps(channel, request, callback) ⇒ Object

Allows framework-level APIs to send a request to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    the app-level channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.

  • callback (Proc)

    the callback that is fired whenever a response is received. It takes one parameter (response).



461
462
463
464
465
# File 'lib/nutella_lib/framework_net.rb', line 461

def self.async_request_to_all_apps(channel, request, callback)
  Nutella.runlist.all_runs.each do |app_id, _|
    Nutella::Net.async_request_to(channel, request, callback, app_id, nil)
  end
end

.async_request_to_all_runs(channel, request, callback) ⇒ Object

Allows framework-level APIs to send a request to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    the run-level channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.

  • callback (Proc)

    the callback that is fired whenever a response is received. It takes one parameter (response).



235
236
237
238
239
240
241
# File 'lib/nutella_lib/framework_net.rb', line 235

def self.async_request_to_all_runs(channel, request, callback)
  Nutella.runlist.all_runs.each do |app_id, _|
    Nutella.runlist.runs_for_app(app_id).each do |run_id|
      Nutella::Net.async_request_to(channel, request, callback, app_id, run_id)
    end
  end
end

.async_request_to_app(app_id, channel, request, callback) ⇒ Object

Allows framework-level APIs to make an asynchronous request to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are making the request to

  • run_id (String)

    the specific run we are making the request to

  • channel (String)

    the channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.

  • callback (Proc)

    the callback that is fired whenever a response is received. It takes one parameter (response).



371
372
373
# File 'lib/nutella_lib/framework_net.rb', line 371

def self.async_request_to_app( app_id, channel, request, callback)
  Nutella::Net.async_request_to(channel, request, callback, app_id, nil)
end

.async_request_to_run(app_id, run_id, channel, request, callback) ⇒ Object

Allows framework-level APIs to make an asynchronous request to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are making the request to

  • run_id (String)

    the specific run we are making the request to

  • channel (String)

    the channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.

  • callback (Proc)

    the callback that is fired whenever a response is received. It takes one parameter (response).



136
137
138
# File 'lib/nutella_lib/framework_net.rb', line 136

def self.async_request_to_run( app_id, run_id, channel, request, callback)
  Nutella::Net.async_request_to(channel, request, callback, app_id, run_id)
end

.catch_requests_on_all_runs_wildcard(callback) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/nutella_lib/framework_net.rb', line 283

def self.catch_requests_on_all_runs_wildcard(callback)
  # Pad channel
  padded_channel = Nutella::Net.pad_channel("#", '+', '+')
  mqtt_cb = lambda do |request, mqtt_channel|
    begin
      # Extract nutella fields
      type, from, payload, id = Nutella::Net.extract_fields_from_message request
      app_id, run_id = self.extract_run_id_and_app_id mqtt_channel
      # Only handle requests that have proper id set
      return if type!='request' || id.nil?
      # Execute callback and send response
      regex = Regexp.new '/nutella/apps/[^"\/"]+/runs/[^"\/"]+/'
      unpadded_channel = mqtt_channel.gsub(regex, '')
      callback.call( unpadded_channel, payload, app_id, run_id, from)
    rescue JSON::ParserError
      # Make sure that request contains JSON, if not drop the message
      return
    rescue ArgumentError
      # Check the passed callback has the right number of arguments
      STDERR.puts "The callback you passed to subscribe has the #{$!}: it needs 'request', 'app_id', 'run_id' and 'from'"
    end
  end
  # Subscribe to the channel
  Nutella.mqtt.subscribe( padded_channel, mqtt_cb )
end

.handle_requests(channel, callback) ⇒ Object

Handles requests on a certain framework-level channel

Parameters:

  • channel (String)

    tha framework-level channel we want to listen for requests on. Can contain wildcard(s).

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      the received message (payload). Messages that are not JSON are discarded.

    • Hash

      the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)

    • returns Hash

      The response sent back to the client that performed the request. Whatever is returned by the callback is marshaled into a JSON string and sent via MQTT.



69
70
71
# File 'lib/nutella_lib/framework_net.rb', line 69

def self.handle_requests( channel, callback )
  Nutella::Net.handle_requests_on(channel, callback, nil, nil)
end

.handle_requests_on_all_apps(channel, callback) ⇒ Object

Allows framework-level APIs to handle requests to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    tha app-level channel we want to listen for requests on. Can contain wildcard(s).

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      the received message (request). Messages that are not JSON are discarded.

    • String

      app_id: the app_id of the channel the request was sent on

    • Hash

      the sender’s identifiers (from containing, run_id, app_id, component_id and optionally resource_id)

    • returns Hash

      The response sent back to the client that performed the request. Whatever is returned by the callback is marshaled into a JSON string and sent via MQTT.



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/nutella_lib/framework_net.rb', line 477

def self.handle_requests_on_all_apps(channel, callback)
  # Check the passed callback has the right number of arguments
  raise 'You need to pass a callback with 3 parameters (request, run_id, from) when handling requests!' if callback.parameters.length!=3
  # Pad channel
  padded_channel = Nutella::Net.pad_channel(channel, '+', nil)
  mqtt_cb = lambda do |request, mqtt_channel|
    begin
      # Extract nutella fields
      type, from, payload, id = Nutella::Net.extract_fields_from_message request
      app_id  = self.extract_app_id mqtt_channel
      # Only handle requests that have proper id set
      return if type!='request' || id.nil?
      # Execute callback and send response
      m = Nutella::Net.prepare_message_for_response( callback.call( payload, app_id, from), id )
      Nutella.mqtt.publish( mqtt_channel, m )
    rescue JSON::ParserError
      # Make sure that request contains JSON, if not drop the message
      return
    rescue ArgumentError
      # Check the passed callback has the right number of arguments
      STDERR.puts "The callback you passed to subscribe has the #{$!}: it needs 'request', 'app_id' and 'from'"
    end
  end
  # Subscribe to the channel
  Nutella.mqtt.subscribe( padded_channel, mqtt_cb )
  # Notify subscription
  Nutella::Net.publish_to('subscriptions', {'type' => 'handle_requests', 'channel' => padded_channel}, nil, nil)
end

.handle_requests_on_all_runs(channel, callback) ⇒ Object

Allows framework-level APIs to handle requests to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    tha run-level channel we want to listen for requests on. Can contain wildcard(s).

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      the received message (request). Messages that are not JSON are discarded.

    • String

      app_id: the app_id of the channel the request was sent on

    • String

      run_id: the run_id of the channel the request was sent on

    • Hash

      the sender’s identifiers (from containing, run_id, app_id, component_id and optionally resource_id)

    • returns Hash

      The response sent back to the client that performed the request. Whatever is returned by the callback is marshaled into a JSON string and sent via MQTT.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/nutella_lib/framework_net.rb', line 254

def self.handle_requests_on_all_runs(channel, callback)
  # Check the passed callback has the right number of arguments
  raise 'You need to pass a callback with 4 parameters (request, run_id, from) when handling requests!' if callback.parameters.length!=4
  # Pad channel
  padded_channel = Nutella::Net.pad_channel(channel, '+', '+')
  mqtt_cb = lambda do |request, mqtt_channel|
    begin
      # Extract nutella fields
      type, from, payload, id = Nutella::Net.extract_fields_from_message request
      app_id, run_id = self.extract_run_id_and_app_id mqtt_channel
      # Only handle requests that have proper id set
      return if type!='request' || id.nil?
      # Execute callback and send response
      m = Nutella::Net.prepare_message_for_response( callback.call( payload, app_id, run_id, from), id )
      Nutella.mqtt.publish( mqtt_channel, m )
    rescue JSON::ParserError
      # Make sure that request contains JSON, if not drop the message
      return
    rescue ArgumentError
      # Check the passed callback has the right number of arguments
      STDERR.puts "The callback you passed to subscribe has the #{$!}: it needs 'request', 'app_id', 'run_id' and 'from'"
    end
  end
  # Subscribe to the channel
  Nutella.mqtt.subscribe( padded_channel, mqtt_cb )
  # Notify subscription
  Nutella::Net.publish_to('subscriptions', {'type' => 'handle_requests', 'channel' => padded_channel}, nil, nil)
end

.handle_requests_on_app(app_id, channel, callback) ⇒ Object

Allows framework-level APIs to handle requests on a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application requests are coming from

  • run_id (String)

    the specific run requests are coming from

  • channel (String)

    we want to listen for requests on. Can contain wildcard(s).

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      the received message (payload). Messages that are not JSON are discarded.

    • Hash

      the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)

    • returns Hash

      The response sent back to the client that performed the request. Whatever is returned by the callback is marshaled into a JSON string and sent via MQTT.



386
387
388
# File 'lib/nutella_lib/framework_net.rb', line 386

def self.handle_requests_on_app(app_id, channel, callback)
  Nutella::Net.handle_requests_on(channel, callback, app_id, nil)
end

.handle_requests_on_run(app_id, run_id, channel, callback) ⇒ Object

Allows framework-level APIs to handle requests on a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application requests are coming from

  • run_id (String)

    the specific run requests are coming from

  • channel (String)

    we want to listen for requests on. Can contain wildcard(s).

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      the received message (payload). Messages that are not JSON are discarded.

    • Hash

      the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)

    • returns Hash

      The response sent back to the client that performed the request. Whatever is returned by the callback is marshaled into a JSON string and sent via MQTT.



151
152
153
# File 'lib/nutella_lib/framework_net.rb', line 151

def self.handle_requests_on_run( app_id, run_id, channel, callback )
  Nutella::Net.handle_requests_on(channel, callback, app_id, run_id)
end

.listenObject

Listens for incoming messages. All this function does is to put the thread to sleep and wait for something to happen over the network to wake up.



515
516
517
# File 'lib/nutella_lib/framework_net.rb', line 515

def self.listen
  Nutella::Net.listen
end

.publish(channel, message = nil) ⇒ Object

Publishes a message to an framework-level channel

Parameters:

  • channel (String)

    the framework-level channel we want to publish the message to. CANNOT contain wildcard(s)!

  • message (Object) (defaults to: nil)

    the message we are publishing. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



35
36
37
# File 'lib/nutella_lib/framework_net.rb', line 35

def self.publish(channel, message=nil)
  Nutella::Net.publish_to(channel, message, nil, nil)
end

.publish_to_all_apps(channel, message) ⇒ Object

Allows framework-level APIs to publish a message to an app-level channel *for ALL apps*

Parameters:

  • channel (String)

    the app-level channel we want to publish the message to. CANNOT contain wildcard(s)!

  • message (Object)

    the message we are publishing. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



448
449
450
451
452
# File 'lib/nutella_lib/framework_net.rb', line 448

def self.publish_to_all_apps(channel, message)
  Nutella.runlist.all_runs.each do |app_id, _|
    Nutella::Net.publish_to(channel, message, app_id, nil)
  end
end

.publish_to_all_runs(channel, message) ⇒ Object

Allows framework-level APIs to publish a message to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    the run-level channel we want to publish the message to. CANNOT contain wildcard(s)!

  • message (Object)

    the message we are publishing. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



220
221
222
223
224
225
226
# File 'lib/nutella_lib/framework_net.rb', line 220

def self.publish_to_all_runs( channel, message )
  Nutella.runlist.all_runs.each do |app_id, _|
    Nutella.runlist.runs_for_app(app_id).each do |run_id|
      Nutella::Net.publish_to(channel, message, app_id, run_id)
    end
  end
end

.publish_to_app(app_id, channel, message) ⇒ Object

Allows framework-level APIs to publish to an app-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are publishing to

  • channel (String)

    the run-level channel we want to publish the message to. CANNOT contain wildcard(s)!

  • message (String)

    the message we are publishing. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



346
347
348
# File 'lib/nutella_lib/framework_net.rb', line 346

def self.publish_to_app(app_id, channel, message)
  Nutella::Net.publish_to(channel, message, app_id, nil)
end

.publish_to_run(app_id, run_id, channel, message) ⇒ Object

Allows framework-level APIs to publish to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are publishing to

  • run_id (String)

    the specific run we are publishing to

  • channel (String)

    the run-level channel we want to publish the message to. CANNOT contain wildcard(s)!

  • message (String)

    the message we are publishing. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



111
112
113
# File 'lib/nutella_lib/framework_net.rb', line 111

def self.publish_to_run( app_id, run_id, channel, message )
  Nutella::Net.publish_to(channel, message, app_id, run_id)
end

.subscribe(channel, callback) ⇒ Object

Subscribes to a channel or to a set of channels at the framework-level.

Parameters:

  • channel (String)

    the framework-level channel or filter we are subscribing to. Can contain wildcard(s)

  • callback (Proc)

    a lambda expression that is fired whenever a message is received. The passed callback takes the following parameters:

    • String

      message: the received message. Messages that are not JSON are discarded.

    • String

      channel: the framework-level channel the message was received on (optional, only for wildcard subscriptions)

    • Hash

      from: the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)



17
18
19
# File 'lib/nutella_lib/framework_net.rb', line 17

def self.subscribe (channel, callback)
  Nutella::Net.subscribe_to(channel, callback, nil, nil)
end

.subscribe_to_all_apps(channel, callback) ⇒ Object

Allows framework-level APIs to subscribe to an app-level channel *for ALL apps*

Parameters:

  • channel (String)

    the app-level channel we are subscribing to. Can be wildcard.

  • callback (Proc)

    the callback that is fired whenever a message is received on the channel. The passed callback takes the following parameters:

    • String

      message: the received message. Messages that are not JSON are discarded.

    • String

      app_id: the app_id of the channel the message was sent on

    • Hash

      from: the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/nutella_lib/framework_net.rb', line 408

def self.subscribe_to_all_apps(channel, callback)
  # Check the passed callback has the right number of arguments
  raise 'You need to pass a callback with 3 parameters (payload, app_id, from) when subscribing to all apps!' if callback.parameters.length!=3
  # Pad channel
  padded_channel = Nutella::Net.pad_channel(channel, '+', nil)
  mqtt_cb = lambda do |mqtt_message, mqtt_channel|
    begin
      type, from, payload, _ = Nutella::Net.extract_fields_from_message mqtt_message
      app_id = self.extract_app_id mqtt_channel
      callback.call(payload, app_id, from) if type=='publish'
    rescue JSON::ParserError
      # Make sure the message is JSON, if not drop the message
      return
    rescue ArgumentError
      # Check the passed callback has the right number of arguments
      STDERR.puts "The callback you passed to subscribe has the #{$!}: it needs 'payload', 'app_id' and 'from'"
    end
  end
  # Add to subscriptions, save mqtt callback and subscribe
  Nutella::Net.subscriptions.push padded_channel
  Nutella::Net.callbacks.push mqtt_cb
  Nutella.mqtt.subscribe( padded_channel, mqtt_cb )
  # Notify subscription
  Nutella::Net.publish_to('subscriptions', {'type' => 'subscribe', 'channel' => padded_channel}, nil, nil)
end

.subscribe_to_all_runs(channel, callback) ⇒ Object

Allows framework-level APIs to subscribe to a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    the run-level channel we are subscribing to. Can be wildcard.

  • callback (Proc)

    the callback that is fired whenever a message is received on the channel. The passed callback takes the following parameters:

    • String

      message: the received message. Messages that are not JSON are discarded.

    • String

      app_id: the app_id of the channel the message was sent on

    • String

      run_id: the run_id of the channel the message was sent on

    • Hash

      from: the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/nutella_lib/framework_net.rb', line 170

def self.subscribe_to_all_runs( channel, callback )
  # Check the passed callback has the right number of arguments
  raise 'You need to pass a callback with 4 parameters (payload, app_id, run_id, from) when subscribing to all runs!' if callback.parameters.length!=4 && callback.parameters.length!=5
  # Pad channel
  padded_channel = Nutella::Net.pad_channel(channel, '+', '+')
  mqtt_cb = lambda do |mqtt_message, mqtt_channel|
    begin
      type, from, payload, _ = Nutella::Net.extract_fields_from_message mqtt_message
      app_id, run_id = self.extract_run_id_and_app_id mqtt_channel
      if channel.include?('#')
        unpadded_channel = un_pad_wildcard_channel(mqtt_channel)
        callback.call(unpadded_channel, payload, app_id, run_id, from) if type=='publish'
      else
        callback.call(payload, app_id, run_id, from) if type=='publish'
      end
    rescue JSON::ParserError
      # Make sure the message is JSON, if not drop the message
      return
    rescue ArgumentError
      # Check the passed callback has the right number of arguments
      STDERR.puts "The callback you passed to subscribe has the #{$!}: it needs 'payload', 'app_id', 'run_id' and 'from'"
    end
  end
  # Add to subscriptions, save mqtt callback and subscribe
  Nutella::Net.subscriptions.push padded_channel
  Nutella::Net.callbacks.push mqtt_cb
  Nutella.mqtt.subscribe( padded_channel, mqtt_cb )
  # Notify subscription
  Nutella::Net.publish_to('subscriptions', {'type' => 'subscribe', 'channel' => padded_channel}, nil, nil)
end

.subscribe_to_app(app_id, channel, callback) ⇒ Object

Allows framework-level APIs to subscribe to an app-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are subscribing to

  • channel (String)

    the run-level channel we are subscribing to. Can be wildcard.

  • callback (Proc)

    the callback that is fired whenever a message is received on the channel. The passed callback takes the following parameters:

    • String

      message: the received message. Messages that are not JSON are discarded.

    • String

      channel: the framework-level channel the message was received on (optional, only for wildcard subscriptions)

    • Hash

      from: the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)



325
326
327
# File 'lib/nutella_lib/framework_net.rb', line 325

def self.subscribe_to_app(app_id, channel, callback)
  Nutella::Net.subscribe_to(channel, callback, app_id, nil)
end

.subscribe_to_run(app_id, run_id, channel, callback) ⇒ Object

Allows framework-level APIs to subscribe to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are subscribing to

  • run_id (String)

    the specific run we are subscribing to

  • channel (String)

    the run-level channel we are subscribing to. Can be wildcard.

  • callback (Proc)

    the callback that is fired whenever a message is received on the channel. The passed callback takes the following parameters:

    • String

      message: the received message. Messages that are not JSON are discarded.

    • String

      channel: the framework-level channel the message was received on (optional, only for wildcard subscriptions)

    • Hash

      from: the sender’s identifiers (run_id, app_id, component_id and optionally resource_id)



89
90
91
# File 'lib/nutella_lib/framework_net.rb', line 89

def self.subscribe_to_run( app_id, run_id, channel, callback )
  Nutella::Net.subscribe_to(channel, callback, app_id, run_id)
end

.sync_request(channel, message = nil) ⇒ Object

Performs a synchronous request at the framework-level

Parameters:

  • channel (String)

    the framework-level channel we want to make the request to. CANNOT contain wildcard(s)!

  • message (Object) (defaults to: nil)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



45
46
47
# File 'lib/nutella_lib/framework_net.rb', line 45

def self.sync_request ( channel, message=nil )
  Nutella::Net.sync_request_to(channel, message, nil, nil)
end

.sync_request_to_app(app_id, channel, request) ⇒ Object

Allows framework-level APIs to make a synchronous request to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are making the request to

  • run_id (String)

    the specific run we are making the request to

  • channel (String)

    the channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



358
359
360
# File 'lib/nutella_lib/framework_net.rb', line 358

def self.sync_request_to_app( app_id, channel, request)
  Nutella::Net.sync_request_to(channel, request, app_id, nil)
end

.sync_request_to_run(app_id, run_id, channel, request) ⇒ Object

Allows framework-level APIs to make a synchronous request to a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are making the request to

  • run_id (String)

    the specific run we are making the request to

  • channel (String)

    the channel we want to make the request to. CANNOT contain wildcard(s)!

  • request (Object)

    the body of request. This can be, nil/empty (default), a string, a hash and, in general, anything with a .to_json method.



123
124
125
# File 'lib/nutella_lib/framework_net.rb', line 123

def self.sync_request_to_run( app_id, run_id, channel, request)
  Nutella::Net.sync_request_to(channel, request, app_id, run_id)
end

.un_pad_wildcard_channel(channel) ⇒ Object



201
202
203
204
# File 'lib/nutella_lib/framework_net.rb', line 201

def self.un_pad_wildcard_channel(channel)
  regex = Regexp.new '/nutella/apps/[^"\/"]+/runs/[^"\/"]+/'
  channel.gsub(regex, '')
end

.unsubscribe(channel) ⇒ Object

Un-subscribes from a framework-level channel

Parameters:

  • channel (String)

    the framework-level channel we want to unsubscribe from. Can contain wildcard(s).



25
26
27
# File 'lib/nutella_lib/framework_net.rb', line 25

def self.unsubscribe( channel )
  Nutella::Net.unsubscribe_to(channel, nil, nil)
end

.unsubscribe_from_all_apps(channel) ⇒ Object

Allows framework-level APIs to unsubscribe from an app-level channel *for ALL apps*

Parameters:

  • channel (String)

    the run-level channel we want to unsubscribe from. Can contain wildcard(s).



438
439
440
# File 'lib/nutella_lib/framework_net.rb', line 438

def self.unsubscribe_from_all_apps( channel )
  Nutella::Net.unsubscribe_to(channel, '+', nil)
end

.unsubscribe_from_all_runs(channel) ⇒ Object

Allows framework-level APIs to unsubscribe from a run-level channel *for ALL runs*

Parameters:

  • channel (String)

    the run-level channel we want to unsubscribe from. Can contain wildcard(s).



210
211
212
# File 'lib/nutella_lib/framework_net.rb', line 210

def self.unsubscribe_from_all_runs( channel )
  Nutella::Net.unsubscribe_to(channel, '+', '+')
end

.unsubscribe_to_app(app_id, channel) ⇒ Object

Allows framework-level APIs to unsubscribe from an app-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are un-subscribing from

  • run_id (String)

    the specific run we are un-subscribing from

  • channel (String)

    the run-level channel we want to unsubscribe from. Can contain wildcard(s).



335
336
337
# File 'lib/nutella_lib/framework_net.rb', line 335

def self.unsubscribe_to_app( app_id, channel )
  Nutella::Net.unsubscribe_to(channel, app_id, nil)
end

.unsubscribe_to_run(app_id, run_id, channel) ⇒ Object

Allows framework-level APIs to unsubscribe from a run-level channel within a specific run

Parameters:

  • app_id (String)

    the specific application we are un-subscribing from

  • run_id (String)

    the specific run we are un-subscribing from

  • channel (String)

    the run-level channel we want to unsubscribe from. Can contain wildcard(s).



99
100
101
# File 'lib/nutella_lib/framework_net.rb', line 99

def self.unsubscribe_to_run( app_id, run_id, channel )
  Nutella::Net.unsubscribe_to(channel, app_id, run_id)
end