Class: Viberroo::Response
- Inherits:
-
Object
- Object
- Viberroo::Response
- Defined in:
- lib/viberroo/response.rb
Overview
Wraps callback response and provides helper methods for easier parameter access.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Accessor for response parameters.
Instance Method Summary collapse
-
#initialize(params) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method) ⇒ Object
-
#user_id ⇒ Integer || nil
Unifies user id access.
Constructor Details
#initialize(params) ⇒ Response
Returns a new instance of Response.
36 37 38 |
# File 'lib/viberroo/response.rb', line 36 def initialize(params) @params = RecursiveOpenStruct.new(params.to_h) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
59 60 61 |
# File 'lib/viberroo/response.rb', line 59 def method_missing(method) params.public_send(method) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Accessor for response parameters.
11 12 13 |
# File 'lib/viberroo/response.rb', line 11 def params @params end |
Instance Method Details
#user_id ⇒ Integer || nil
Unifies user id access. Different callback events return user id differently. This method unifies user id access interface based on callback event type. Original user id params remain available in ‘params` attribute reader.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/viberroo/response.rb', line 46 def user_id case @params.event when 'conversation_started', 'subscribed' @params.user.id when 'unsubscribed', 'delivered', 'seen', 'failed' @params.user_id when 'message' @params.sender.id else @params.dig(:user, :id) end end |