Sha256: af34e87ac9183cd89105ece6755f2e44ed4bcac7f948e51ea50928696c81f4e9

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Sms77::Journal
  module Type
    INBOUND = 'inbound'
    OUTBOUND = 'outbound'
    REPLIES = 'replies'
    VOICE = 'voice'
  end

  module Validator
    def self.validate(params)
      type = params[:type]
      date_from = params[:date_from]
      date_to = params[:date_to]

      raise "Unknown type #{type}" unless Sms77::Journal::Validator::is_type?(type)
      raise "Wrong date_from #{date_from}" unless Sms77::Journal::Validator::is_date?(date_from)
      raise "Wrong date_to #{date_to}" unless Sms77::Journal::Validator::is_date?(date_to)
    end

    def self.subscribe(params)
      { :request_method => Sms77::Hooks::RequestMethod::POST }.merge!(params)

      self.event_type?(params[:event_type]) &&
        self.request_method?(params[:request_method]) &&
        self.target_url?(params[:target_url])
    end

    def self.is_type?(str)
      Sms77::Util::in_module_constants?(str, Sms77::Journal::Type)
    end

    def self.is_date?(date)
      date.is_a?(NilClass) || date.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])/)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sms77-0.4.0 lib/sms77/journal.rb
sms77-0.3.0 lib/sms77/journal.rb
sms77-0.2.0 lib/sms77/journal.rb