Class: Computron::Client
- Inherits:
-
Object
- Object
- Computron::Client
- Defined in:
- lib/computron/client.rb
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #long_poll(url, opts = {}, &block) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Client
Returns a new instance of Client.
107 108 109 110 |
# File 'lib/computron/client.rb', line 107 def initialize @logger = Logger.new($stdout) yield self if block_given? end |
Instance Attribute Details
#cookie ⇒ Object
Returns the value of attribute cookie.
105 106 107 |
# File 'lib/computron/client.rb', line 105 def @cookie end |
#logger ⇒ Object
Returns the value of attribute logger.
105 106 107 |
# File 'lib/computron/client.rb', line 105 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
105 106 107 |
# File 'lib/computron/client.rb', line 105 def name @name end |
Instance Method Details
#long_poll(url, opts = {}, &block) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/computron/client.rb', line 112 def long_poll(url, opts={}, &block) response = Response.new request = EM::HttpRequest.new(url).get(opts) request.callback {|http| (http) repoll = Struct.new(:url).new(url) block.call(response, repoll) if block_given? response.call(http) log_request(http, "Repolling") long_poll(repoll.url, &block) } request.errback {|http| log_request(http, "Long poll timed-out. Repolling.", 'yellow') } # get url do |response| # repoll = Struct.new(:url).new(url) # block.call(response, repoll) # response.finished { # logger.info "Repolling".yellow # long_poll(repoll.url, &block) # } # end end |