Class: Bing::Content::Api::Batch
- Inherits:
-
Object
- Object
- Bing::Content::Api::Batch
- Defined in:
- lib/bing/content/api/batch.rb
Instance Attribute Summary collapse
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_deletions(products) ⇒ Object
- #add_insertions(products) ⇒ Object
- #all_products ⇒ Object
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #product_by_batch_id(id) ⇒ Object
- #to_body ⇒ Object
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
7 8 9 10 11 |
# File 'lib/bing/content/api/batch.rb', line 7 def initialize @operations = [] @ids = (1..1000).to_a end |
Instance Attribute Details
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
5 6 7 |
# File 'lib/bing/content/api/batch.rb', line 5 def operations @operations end |
Instance Method Details
#add_deletions(products) ⇒ Object
19 20 21 22 23 |
# File 'lib/bing/content/api/batch.rb', line 19 def add_deletions(products) products.each do |prod| @operations << BatchOperation.new(@ids.pop, prod, :delete) end end |
#add_insertions(products) ⇒ Object
13 14 15 16 17 |
# File 'lib/bing/content/api/batch.rb', line 13 def add_insertions(products) products.each do |prod| @operations << BatchOperation.new(@ids.pop, prod, :insert) end end |
#all_products ⇒ Object
25 26 27 |
# File 'lib/bing/content/api/batch.rb', line 25 def all_products @operations.map { |op| op.product } end |
#product_by_batch_id(id) ⇒ Object
29 30 31 |
# File 'lib/bing/content/api/batch.rb', line 29 def product_by_batch_id(id) @operations.select { |op| op.batch_id == id }.first.product end |
#to_body ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/bing/content/api/batch.rb', line 33 def to_body json_operations = @operations.map do |op| op.bing_operation end { entries: json_operations }.to_json end |