Class: Bing::Content::Api::BatchOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/bing/content/api/batch_operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(batch_id, product, action = :insert) ⇒ BatchOperation

Returns a new instance of BatchOperation.



10
11
12
13
14
15
16
# File 'lib/bing/content/api/batch_operation.rb', line 10

def initialize(batch_id, product, action=:insert)
  raise "Please select a valid operation." unless [:insert, :delete].include? action

  @batch_id = batch_id
  @product = product
  @action = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/bing/content/api/batch_operation.rb', line 8

def action
  @action
end

#batch_idObject (readonly)

Returns the value of attribute batch_id.



6
7
8
# File 'lib/bing/content/api/batch_operation.rb', line 6

def batch_id
  @batch_id
end

#productObject (readonly)

Returns the value of attribute product.



7
8
9
# File 'lib/bing/content/api/batch_operation.rb', line 7

def product
  @product
end

Instance Method Details

#bing_operationObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bing/content/api/batch_operation.rb', line 18

def bing_operation
  operation = { batchId: @batch_id }
  case @action
  when :insert
    operation[:product] = @product.to_record
    operation[:method] = "insert"
  when :delete
    operation[:productId] = @product.bing_product_id
    operation[:method] = "delete"
  end
  operation
end