radar_client_rb 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73ac6c931eb4277fe3b894f8a7d77cad4703bbae
4
- data.tar.gz: 2416eedb7fd0ca5dd06a476905e7d554255325be
3
+ metadata.gz: 7824fb63d8f0d67804525ccb9c3a3fe75c4ba23c
4
+ data.tar.gz: 8f7a3f8f8ce4272a563070eb568751d817ea45b5
5
5
  SHA512:
6
- metadata.gz: 86b28b604f744aac64873b31cf7ea72d3c2ce1bcdb6c129bf354f788ae7ac5a1049b2625973acdf467b073c2f2eaad92e3392b9c26a8da19bfbd8d9d30cb98c5
7
- data.tar.gz: c80b696d50947d1dd183396a658c62f3e75f1f58dad1f8a3892c4e41dba059032ca03e52be3ea0122ba3296eab28fc767cc4130ebb3dd6ded8bc3611be5288b9
6
+ metadata.gz: 298eda373afffbaca84bafa666ba8060f09316c80b23b470c5d8da6483526f56c6573c252480ce0e5463ea3e0f60ae69294cc0fdbaf3505c46ec1bc175ef9b95
7
+ data.tar.gz: 178ea51532bd587079dfe26ea27d61de669aa768d25928b097db497e57f97bbe6a7f3b59da125f90d49f0e058a42107fdedd58f04c0e7c56c043f39447ea5571
@@ -19,16 +19,39 @@ module Radar
19
19
 
20
20
  def get
21
21
  result = {}
22
- @client.redis.hgetall(@name).each do |key, value|
23
- user_id, client_id = key.split('.')
24
- message = JSON.parse(value)
25
- if message['online']
26
- result[user_id] ||= { :clients => {}, :userType => message['userType'] }
27
- result[user_id][:clients][client_id] = message['userData'] || {}
28
- end
22
+
23
+ clients = get_clients.select { |client| client['online'] }
24
+ sentries = clients.map { |client| client['sentry'] }
25
+ online_sentries = select_online_sentries(sentries)
26
+ online_clients = clients.select { |client| online_sentries.include?(client['sentry']) }
27
+
28
+ online_clients.each do |client|
29
+ user_id = client['userId']
30
+ result[user_id] ||= { :clients => {}, :userType => client['userType'] }
31
+ result[user_id][:clients][client['clientId']] = client['userData'] || {}
29
32
  end
30
33
  result
31
34
  end
35
+
36
+ private
37
+
38
+ def get_clients
39
+ @client.redis.hgetall(@name).values.map { |value| JSON.parse(value) }
40
+ end
41
+
42
+ def select_online_sentries(sentry_ids)
43
+ return [] unless sentry_ids && sentry_ids.any?
44
+ online_sentries = @client.redis.hmget('sentry:/radar', *sentry_ids.uniq)
45
+ .select { |x| !x.nil? }
46
+ .map { |data| JSON.parse(data) }
47
+ .select { |sentry| !message_is_expired?(sentry) }
48
+
49
+ online_sentries.map { |sentry| sentry['name'] }
50
+ end
51
+
52
+ def message_is_expired?(message)
53
+ !message['expiration'] || message['expiration'] <= (Time.now.to_i * 1000)
54
+ end
32
55
  end
33
56
 
34
57
  class Status < Resource
@@ -1,5 +1,5 @@
1
1
  module Radar
2
2
  class Client
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radar_client_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick O'Brien
@@ -10,104 +10,104 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-20 00:00:00.000000000 Z
13
+ date: 2016-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redis
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: minitest
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: fakeredis
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: mocha
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: private_gem
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: bump
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  description: Read/Write Radar Resources from Redis through Ruby
@@ -116,10 +116,10 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - lib/radar_client_rb.rb
120
119
  - lib/radar_client_rb/client.rb
121
120
  - lib/radar_client_rb/resource.rb
122
121
  - lib/radar_client_rb/version.rb
122
+ - lib/radar_client_rb.rb
123
123
  homepage: http://github.com/zendesk/radar_client_rb
124
124
  licenses: []
125
125
  metadata: {}
@@ -129,17 +129,17 @@ require_paths:
129
129
  - lib
130
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - ">="
132
+ - - '>='
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - ">="
137
+ - - '>='
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.2.2
142
+ rubygems_version: 2.0.14
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Read/Write Radar Resources from Redis through Ruby