class Viberroo::Response
Wraps callback response and provides helper methods for easier parameter access.
Attributes
params[R]
Accessor for response parameters.
Public Class Methods
new(params)
click to toggle source
@example
class ViberController < ApplicationController skip_before_action :verify_authenticity_token def callback @response = Viberroo::Response.new(params.permit!) @bot = Viberroo::Bot.new(response: @response) head :ok end end
@param [Hash] params Parameters from API callback.
# File lib/viberroo/response.rb, line 28 def initialize(params) @params = RecursiveOpenStruct.new(params.to_h) end
Public Instance Methods
user_id()
click to toggle source
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. @return [Integer || nil]
# File lib/viberroo/response.rb, line 38 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