Conditions | 3 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
1 | require 'date' |
||
11 | |||
12 | def retrieve_for_event(event, params={}) |
||
13 | unless event.is_a? RingCentralSdk::REST::Event |
||
14 | fail 'retrieve_for_event requires RingCentralSdk::REST::Event argument' |
||
15 | end |
||
16 | url = event.doc.getAttr :event |
||
17 | last_updated_s = event.doc.getAttr('body.lastUpdated') |
||
18 | last_updated_dt = DateTime.iso8601(last_updated_s) |
||
19 | |||
20 | params.merge!({ |
||
21 | :dateFrom => (last_updated_dt - (@range/1440.0)).to_s, |
||
22 | :dateTo => (last_updated_dt + (@range/1440.0)).to_s |
||
23 | }) |
||
24 | if event.new_sms_count > 0 |
||
25 | params[:messageType] = 'SMS' |
||
26 | end |
||
27 | |||
28 | res = @client.http.get do |req| |
||
29 | req.url url |
||
30 | req.params = params |
||
31 | end |
||
32 | |||
33 | messages = [] |
||
34 | |||
35 | res.body['records'].each do |rec| |
||
36 | rec_last_modified_time = rec['lastModifiedTime'] |
||
37 | rec_last_modified_time_dt = DateTime.iso8601(rec_last_modified_time) |
||
38 | if rec_last_modified_time_dt == last_updated_dt |
||
39 | messages.push rec |
||
40 | end |
||
41 | end |
||
42 | return messages |
||
43 | end |
||
46 |