Class: Computron::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/computron/client.rb

Defined Under Namespace

Classes: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



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

Returns the value of attribute cookie.



105
106
107
# File 'lib/computron/client.rb', line 105

def cookie
  @cookie
end

#loggerObject

Returns the value of attribute logger.



105
106
107
# File 'lib/computron/client.rb', line 105

def logger
  @logger
end

#nameObject

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|
    persist_cookie(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