run the same method across multiple controllers

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

run the same method across multiple controllers

Lloyd Hughes
Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Justin Aiken
You could always monkeypatch the Call object:

module Adhearsion
  class Call
    def initialize(offer = nil)
      super
      on_end { SomeModule.some_cdr_creating_method self }
    end
  end
end

(or there might be better places to patch in, like Call#register_initial_handlers)

-Justin

On Jul 10, 2014, at 2:01 PM, Lloyd <[hidden email]> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Ben Klang-2
In reply to this post by Lloyd Hughes
You can assign the `on_end` event to any call object, including OutboundCalls. Here’s an example from an app that I wrote:

  outbound_call = Adhearsion::OutboundCall.new.tap do |call|
     call.execute_controller_or_router_on_answer MyController, metadata
  end
outbound_call.on_end { # stuff }
outbound_call.dial to, opts

Where `to` and `opts` are the normal options you would pass to OutboundCall#originate

/BAK/

-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

On Jul 10, 2014, at 4:01 PM, Lloyd <[hidden email]> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Ben Langfeld-2
In reply to this post by Justin Aiken
No no, never do this.


On 10 July 2014 17:06, Justin Aiken <[hidden email]> wrote:
You could always monkeypatch the Call object:

module Adhearsion
  class Call
    def initialize(offer = nil)
      super
      on_end { SomeModule.some_cdr_creating_method self }
    end
  end
end

(or there might be better places to patch in, like Call#register_initial_handlers)

-Justin

On Jul 10, 2014, at 2:01 PM, Lloyd <[hidden email]> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Lloyd Hughes
Currently I am using Ben Klangs suggestion, but this doesn't seem very DRY to me. I considered the monkey patch but I don't like patching internals.

Would it be seen as acceptable to pass the call object on to another function? How long does it exist for after the call ends?

eg) on_end { SomeModule.some_cdr_creating_method self }

Thanks

On Thursday, 10 July 2014 22:35:01 UTC+2, Ben Langfeld wrote:
No no, never do this.


On 10 July 2014 17:06, Justin Aiken <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">60ton...@...> wrote:
You could always monkeypatch the Call object:

module Adhearsion
  class Call
    def initialize(offer = nil)
      super
      on_end { SomeModule.some_cdr_creating_method self }
    end
  end
end

(or there might be better places to patch in, like Call#register_initial_handlers)

-Justin

On Jul 10, 2014, at 2:01 PM, Lloyd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">hughes...@...> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Ben Klang-2


On Jul 10, 2014, at 5:02 PM, Lloyd <[hidden email]> wrote:

Currently I am using Ben Klangs suggestion, but this doesn't seem very DRY to me. I considered the monkey patch but I don't like patching internals.

You can always create a wrapper class to create your OutboundCalls; that’s what we did in my app.  You can also DRY the code by using a single method for the on_end callback.
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

/BAK/


Would it be seen as acceptable to pass the call object on to another function? How long does it exist for after the call ends?

eg) on_end { SomeModule.some_cdr_creating_method self }

Thanks

On Thursday, 10 July 2014 22:35:01 UTC+2, Ben Langfeld wrote:
No no, never do this.


On 10 July 2014 17:06, Justin Aiken <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">60ton...@...> wrote:
You could always monkeypatch the Call object:

module Adhearsion
  class Call
    def initialize(offer = nil)
      super
      on_end { SomeModule.some_cdr_creating_method self }
    end
  end
end

(or there might be better places to patch in, like Call#register_initial_handlers)

-Justin

On Jul 10, 2014, at 2:01 PM, Lloyd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">hughes...@...> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ScrMN3vS00gJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: run the same method across multiple controllers

Ben Langfeld-2
In reply to this post by Lloyd Hughes
On 10 July 2014 18:02, Lloyd <[hidden email]> wrote:
Currently I am using Ben Klangs suggestion, but this doesn't seem very DRY to me. I considered the monkey patch but I don't like patching internals.

Would it be seen as acceptable to pass the call object on to another function? How long does it exist for after the call ends?

eg) on_end { SomeModule.some_cdr_creating_method self }

Perfectly acceptable.
 


Thanks

On Thursday, 10 July 2014 22:35:01 UTC+2, Ben Langfeld wrote:
No no, never do this.


On 10 July 2014 17:06, Justin Aiken <[hidden email]> wrote:
You could always monkeypatch the Call object:

module Adhearsion
  class Call
    def initialize(offer = nil)
      super
      on_end { SomeModule.some_cdr_creating_method self }
    end
  end
end

(or there might be better places to patch in, like Call#register_initial_handlers)

-Justin

On Jul 10, 2014, at 2:01 PM, Lloyd <[hidden email]> wrote:

Hi,

I am looking for a way to execute a method when a call ends, even if it wasn't answered. The same method must be executed for both inbound and outbound calls. If I assign the on_end callback in the before_call method of the controller it won't be called on outbound calls that are rejected as the controller only runs on answer.

What is the correct way of going about this? The method will be used for creating call records for all calls, and I only wish to define the method once to keep everything DRY.

Thanks

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adhearsion+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adhearsion+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.