Class: Redwood::Client
- Defined in:
- lib/sup/client.rb
Instance Method Summary collapse
- #add(raw, labels, &b) ⇒ Object
- #count(qstr, &b) ⇒ Object
-
#initialize(*a) ⇒ Client
constructor
A new instance of Client.
- #label(qstr, add, remove, &b) ⇒ Object
- #mktag(&b) ⇒ Object
- #query(qstr, offset, limit, raw, &b) ⇒ Object
- #receive_message(type, tag, args) ⇒ Object
- #rmtag(tag) ⇒ Object
- #thread(msg_id, raw, &b) ⇒ Object
Constructor Details
#initialize(*a) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 |
# File 'lib/sup/client.rb', line 6 def initialize *a @next_tag = 1 @cbs = {} super *a end |
Instance Method Details
#add(raw, labels, &b) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/sup/client.rb', line 60 def add raw, labels, &b tag = mktag do |type,tag,args| b.call rmtag tag end 'add', tag, 'raw' => raw, 'labels' => labels end |
#count(qstr, &b) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/sup/client.rb', line 40 def count qstr, &b tag = mktag do |type,tag,args| b.call args['count'] rmtag tag end 'count', tag, 'query' => qstr end |
#label(qstr, add, remove, &b) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sup/client.rb', line 49 def label qstr, add, remove, &b tag = mktag do |type,tag,args| b.call rmtag tag end 'label', tag, 'query' => qstr, 'add' => add, 'remove' => remove end |
#mktag(&b) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/sup/client.rb', line 12 def mktag &b @next_tag.tap do |x| @cbs[x] = b @next_tag += 1 end end |
#query(qstr, offset, limit, raw, &b) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sup/client.rb', line 23 def query qstr, offset, limit, raw, &b tag = mktag do |type,tag,args| if type == 'message' b.call args else fail unless type == 'done' b.call nil rmtag tag end end 'query', tag, 'query' => qstr, 'offset' => offset, 'limit' => limit, 'raw' => raw end |
#receive_message(type, tag, args) ⇒ Object
86 87 88 89 |
# File 'lib/sup/client.rb', line 86 def type, tag, args cb = @cbs[tag] or fail "invalid tag #{tag.inspect}" cb[type, tag, args] end |
#rmtag(tag) ⇒ Object
19 20 21 |
# File 'lib/sup/client.rb', line 19 def rmtag tag @cbs.delete tag end |
#thread(msg_id, raw, &b) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sup/client.rb', line 70 def thread msg_id, raw, &b tag = mktag do |type,tag,args| if type == 'message' b.call args else fail unless type == 'done' b.call nil rmtag tag end end 'thread', tag, 'message_id' => msg_id, 'raw' => raw end |