Class: RingCentralSdk::REST::MessagesRetriever
- Inherits:
-
Object
- Object
- RingCentralSdk::REST::MessagesRetriever
- Defined in:
- lib/ringcentral_sdk/rest/messages_retriever.rb
Overview
MessagesRetrieve is a class that will retrieve matching records for an event
Instance Attribute Summary collapse
-
#range ⇒ Object
Returns the value of attribute range.
Instance Method Summary collapse
-
#initialize(client) ⇒ MessagesRetriever
constructor
A new instance of MessagesRetriever.
- #retrieve_for_event(event, params = {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ MessagesRetriever
Returns a new instance of MessagesRetriever.
9 10 11 12 |
# File 'lib/ringcentral_sdk/rest/messages_retriever.rb', line 9 def initialize(client) @client = client @range = 1.0 # minutes end |
Instance Attribute Details
#range ⇒ Object
Returns the value of attribute range.
8 9 10 |
# File 'lib/ringcentral_sdk/rest/messages_retriever.rb', line 8 def range @range end |
Instance Method Details
#retrieve_for_event(event, params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ringcentral_sdk/rest/messages_retriever.rb', line 14 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 = [] res.body['records'].each do |rec| rec_last_modified_time = rec['lastModifiedTime'] rec_last_modified_time_dt = DateTime.iso8601(rec_last_modified_time) .push(rec) if rec_last_modified_time_dt == last_updated_dt end end |