Class: Bing::Content::Api::BatchProcessor
- Inherits:
-
Object
- Object
- Bing::Content::Api::BatchProcessor
- Defined in:
- lib/bing/content/api/batch_processor.rb
Instance Method Summary collapse
- #execute(batch) ⇒ Object
-
#initialize(connector) ⇒ BatchProcessor
constructor
A new instance of BatchProcessor.
Constructor Details
#initialize(connector) ⇒ BatchProcessor
Returns a new instance of BatchProcessor.
5 6 7 |
# File 'lib/bing/content/api/batch_processor.rb', line 5 def initialize(connector) @connector = connector end |
Instance Method Details
#execute(batch) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bing/content/api/batch_processor.rb', line 9 def execute(batch) post_body = to_body(batch) http_response = @connector.post('/products/batch', post_body) body = JSON.parse(http_response.body) entries = body["entries"] response = Bing::Content::Api::Response.new response.set_all_products(batch.all_products) entries.each do |entry| id = entry["batchId"].to_i response.add_success(batch.product_by_batch_id(id)) end response end |