Class: Bolide::Q

Inherits:
Object
  • Object
show all
Defined in:
lib/bolide/q.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bolide, name) ⇒ Q

Returns a new instance of Q.



8
9
10
11
12
13
14
# File 'lib/bolide/q.rb', line 8

def initialize(bolide, name)
  @bolide = bolide
  @name = name
  @token = nil
  @expire_on = nil
  @msg_count = nil
end

Instance Attribute Details

#bolideObject

Returns the value of attribute bolide.



6
7
8
# File 'lib/bolide/q.rb', line 6

def bolide
  @bolide
end

#expire_onObject

Returns the value of attribute expire_on.



6
7
8
# File 'lib/bolide/q.rb', line 6

def expire_on
  @expire_on
end

#msg_countObject

Returns the value of attribute msg_count.



6
7
8
# File 'lib/bolide/q.rb', line 6

def msg_count
  @msg_count
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/bolide/q.rb', line 6

def name
  @name
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/bolide/q.rb', line 6

def token
  @token
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/bolide/q.rb', line 16

def expired?
  resp = bolide.session.get('/q/' + name + '.xml', bolide.headers)
  if resp.status < 400
    read_response resp
  else
    raise read_error(resp)
  end
  @expire_on && @expire_on > DateTime.now && @token
end

#marshal_dumpObject



40
41
42
43
44
45
46
47
48
# File 'lib/bolide/q.rb', line 40

def marshal_dump
  {
    :name=>@name,
    :token=>@token,
    :bolide=>@bolide,
    :msg_count=>@msg_count,
    :expire_on=>@expire_on
  }
end

#marshal_load(data) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/bolide/q.rb', line 50

def marshal_load(data)
  @name = data[:name]
  @bolide = data[:bolide]
  @msg_count = data[:msg_count]
  @token = data[:token]
  @expire_on = data[:expire_on]
end

#new_tokenObject



26
27
28
29
30
31
32
33
34
# File 'lib/bolide/q.rb', line 26

def new_token
  resp = bolide.session.put('/q/' + name + '.xml','', bolide.headers)
  if resp.status < 400
    read_response resp
  else 
    raise read_error(resp)
  end
  return @token
end

#send_msg(body) ⇒ Object



36
37
38
# File 'lib/bolide/q.rb', line 36

def send_msg(body)
  bolide.send_msg(body,  [@name])
end