Class: F00px::Request::Runner
- Inherits:
-
Object
- Object
- F00px::Request::Runner
- Defined in:
- lib/f00px/request/runner.rb
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #get(url, params = {}) ⇒ Object
-
#initialize(conn) ⇒ Runner
constructor
A new instance of Runner.
-
#post(url, params = {}) ⇒ Object
Queues a POST request.
- #request(method, url, params = {}) ⇒ Object
-
#run! ⇒ Object
Runs all queued requests.
Constructor Details
#initialize(conn) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 |
# File 'lib/f00px/request/runner.rb', line 6 def initialize(conn) @queued_requests = [] @connection = conn end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
4 5 6 |
# File 'lib/f00px/request/runner.rb', line 4 def consumer_key @consumer_key end |
#user_id ⇒ Object
Returns the value of attribute user_id.
4 5 6 |
# File 'lib/f00px/request/runner.rb', line 4 def user_id @user_id end |
Instance Method Details
#get(url, params = {}) ⇒ Object
11 12 13 |
# File 'lib/f00px/request/runner.rb', line 11 def get(url, params={}) request(:get, url, params) end |
#post(url, params = {}) ⇒ Object
Queues a POST request
16 17 18 |
# File 'lib/f00px/request/runner.rb', line 16 def post(url, params={}) request(:post, url, params) end |
#request(method, url, params = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/f00px/request/runner.rb', line 20 def request(method, url, params = {}) params = params.dup params[:consumer_key] = consumer_key Callback.new(method, url, params).tap do |r| @queued_requests << r end end |
#run! ⇒ Object
Runs all queued requests. This method will block until all requests are complete. As requests complete their callbacks will be executed.
31 32 33 34 35 36 37 38 39 |
# File 'lib/f00px/request/runner.rb', line 31 def run! execute_in_parallel do @queued_requests.each do |callback| execute_request(callback) end end ensure @queued_requests = [] end |