Class: HttpClient
- Inherits:
-
Object
- Object
- HttpClient
- Defined in:
- lib/blest.rb
Instance Attribute Summary collapse
-
#buffer_delay ⇒ Object
Returns the value of attribute buffer_delay.
-
#futures ⇒ Object
readonly
Returns the value of attribute futures.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#max_batch_size ⇒ Object
Returns the value of attribute max_batch_size.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, max_batch_size = 25, buffer_delay = 10, http_headers = {}) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #request(route, body = nil, headers = nil) ⇒ Object
Constructor Details
#initialize(url, max_batch_size = 25, buffer_delay = 10, http_headers = {}) ⇒ HttpClient
Returns a new instance of HttpClient.
154 155 156 157 158 159 160 161 162 |
# File 'lib/blest.rb', line 154 def initialize(url, max_batch_size = 25, buffer_delay = 10, http_headers = {}) @url = url @max_batch_size = max_batch_size @buffer_delay = buffer_delay @http_headers = http_headers @queue = Queue.new @futures = {} @lock = Mutex.new end |
Instance Attribute Details
#buffer_delay ⇒ Object
Returns the value of attribute buffer_delay.
152 153 154 |
# File 'lib/blest.rb', line 152 def buffer_delay @buffer_delay end |
#futures ⇒ Object (readonly)
Returns the value of attribute futures.
151 152 153 |
# File 'lib/blest.rb', line 151 def futures @futures end |
#headers ⇒ Object
Returns the value of attribute headers.
152 153 154 |
# File 'lib/blest.rb', line 152 def headers @headers end |
#max_batch_size ⇒ Object
Returns the value of attribute max_batch_size.
152 153 154 |
# File 'lib/blest.rb', line 152 def max_batch_size @max_batch_size end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
151 152 153 |
# File 'lib/blest.rb', line 151 def queue @queue end |
#url ⇒ Object
Returns the value of attribute url.
152 153 154 |
# File 'lib/blest.rb', line 152 def url @url end |
Instance Method Details
#request(route, body = nil, headers = nil) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/blest.rb', line 164 def request(route, body=nil, headers=nil) uuid = SecureRandom.uuid() future = Concurrent::Promises.resolvable_future @lock.synchronize do @futures[uuid] = future end @queue.push({ uuid: uuid, data: [uuid, route, body, headers] }) process_timeout() future end |