Sha256: fbf122812293ca96d0176c7243a439a138c1f5c70bba96cadca9366fe7a1a566

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

require 'date'
require 'jsondoc'

module RingCentralSdk
  module REST
    # MessagesRetrieve is a class that will retrieve matching records for an event
    class MessagesRetriever
      attr_accessor :range
      def initialize(client)
        @client = client
        @range = 1.0 # minutes
      end

      def retrieve_for_event(event, params = {})
        unless event.is_a? RingCentralSdk::REST::Event
          raise ArgumentError, 'retrieve_for_event requires RingCentralSdk::REST::Event argument'
        end
        url = event.doc.getAttr :event
        last_updated_s = event.doc.getAttr('body.lastUpdated')
        last_updated_dt = DateTime.iso8601(last_updated_s)

        params[:dateFrom] = (last_updated_dt - (@range / 1440.0)).to_s
        params[:dateTo] = (last_updated_dt + (@range / 1440.0)).to_s
        params[:messageType] = 'SMS' if event.new_sms_count > 0

        res = @client.http.get do |req|
          req.url url
          req.params = params
        end

        messages = []

        res.body['records'].each do |rec|
          rec_last_modified_time = rec['lastModifiedTime']
          rec_last_modified_time_dt = DateTime.iso8601(rec_last_modified_time)
          messages.push(rec) if rec_last_modified_time_dt == last_updated_dt
        end
        messages
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ringcentral_sdk-3.1.0 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-3.0.1 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-3.0.0 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.3.0 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.2.3 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.2.2 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.2.1 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.1.0 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.0.3 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.0.2 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.0.1 lib/ringcentral_sdk/rest/messages_retriever.rb
ringcentral_sdk-2.0.0 lib/ringcentral_sdk/rest/messages_retriever.rb