radar_client_rb 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/radar_client_rb.rb +5 -0
- data/lib/radar_client_rb/client.rb +35 -0
- data/lib/radar_client_rb/resource.rb +79 -0
- data/lib/radar_client_rb/version.rb +5 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62e918ac1f7ec01abd79e812600ea6fa25448b24
|
4
|
+
data.tar.gz: 2b3c404476f15c234ba881f473ec9eeb8eb8f0cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97a8460b69d4c4a6e29977da1e5c7bc5b35f282902cb7253830b0e8b21afa82ce92e0e8949f6331a3217745113bf951782fd52452ef6c8d9a988b39c5e8449b0
|
7
|
+
data.tar.gz: 14e36bbd6bbc31ba5b72bbb79f5ffadf6b65981dfc186f71c0577e72021aab917edd7ad0df99cdff14781080b16d077cb6032ee51002d9d4c0f7c9ca05d4988b
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative './resource.rb'
|
2
|
+
|
3
|
+
module Radar
|
4
|
+
class Client
|
5
|
+
attr_accessor :subdomain
|
6
|
+
|
7
|
+
def self.redis_retriever_defined?
|
8
|
+
defined?(@@redis_retriever) && @@redis_retriever
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.define_redis_retriever(&blk)
|
12
|
+
@@redis_retriever = blk
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(subdomain)
|
16
|
+
@subdomain = subdomain
|
17
|
+
end
|
18
|
+
|
19
|
+
def presence(name)
|
20
|
+
Presence.new(self, name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def status(name)
|
24
|
+
Status.new(self, name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def message(name)
|
28
|
+
MessageList.new(self, name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def redis
|
32
|
+
@@redis_retriever.call(@subdomain) if Client.redis_retriever_defined?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Radar
|
4
|
+
class Resource
|
5
|
+
def initialize(client, name)
|
6
|
+
@client = client
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def logger
|
11
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new($stdout)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Presence < Resource
|
16
|
+
def initialize(client, name)
|
17
|
+
super(client, "presence:/#{client.subdomain}/#{name}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def get
|
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
|
29
|
+
end
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Status < Resource
|
35
|
+
def initialize(client, name)
|
36
|
+
super(client, "status:/#{client.subdomain}/#{name}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def get(key)
|
40
|
+
result = @client.redis.hget(@name, key)
|
41
|
+
result ? JSON.parse(result, :quirks_mode => true) : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def set(key, value)
|
45
|
+
redis = @client.redis
|
46
|
+
redis.multi do |redis|
|
47
|
+
redis.hset(@name, key, value.to_json)
|
48
|
+
redis.expire(@name, 12*60*60)
|
49
|
+
redis.publish(@name, { :to => @name, :op => 'set', :key => key, :value => value }.to_json)
|
50
|
+
end
|
51
|
+
|
52
|
+
client = redis.respond_to?(:client) && redis.client
|
53
|
+
client_info = if client && client.respond_to?(:host) && client.respond_to?(:port)
|
54
|
+
"Client: #{client.host}:#{client.port}"
|
55
|
+
else
|
56
|
+
"unknown"
|
57
|
+
end
|
58
|
+
logger.debug "Set Status: #{key}, #{value}, #{client_info}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
class MessageList < Resource
|
64
|
+
def initialize(client, name)
|
65
|
+
super(client, "message:/#{client.subdomain}/#{name}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def get
|
69
|
+
# Unfortunately we can't apply any maxAge policies.
|
70
|
+
result_arr = @client.redis.zrange(@name, -100, -1, :with_scores => true)
|
71
|
+
result = []
|
72
|
+
result_arr.each do |message_json, time|
|
73
|
+
message = JSON.parse(message_json, :quirks_mode => true)
|
74
|
+
result << [message, time]
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radar_client_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick O'Brian
|
8
|
+
- Ciaran Archer
|
9
|
+
- Vanchi K
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redis
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: minitest
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: fakeredis
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: mocha
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: private_gem
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: bump
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
description: Read/Write Radar Resources from Redis through Ruby
|
114
|
+
email: radar@zendesk.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- lib/radar_client_rb.rb
|
120
|
+
- lib/radar_client_rb/client.rb
|
121
|
+
- lib/radar_client_rb/resource.rb
|
122
|
+
- lib/radar_client_rb/version.rb
|
123
|
+
homepage: http://github.com/zendesk/radar_client_rb
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Read/Write Radar Resources from Redis through Ruby
|
146
|
+
test_files: []
|