class Bing::Content::Api::Batch

Attributes

operations[R]

Public Class Methods

new() click to toggle source
# File lib/bing/content/api/batch.rb, line 7
def initialize
  @operations = []

  @ids = (1..1000).to_a
end

Public Instance Methods

add_deletions(products) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/bing/content/api/batch.rb, line 25
def all_products
  @operations.map(&:product)
end
product_by_batch_id(id) click to toggle source
# 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() click to toggle source
# File lib/bing/content/api/batch.rb, line 33
def to_body
  json_operations = @operations.map(&:bing_operation)
  { entries: json_operations }.to_json
end