bing-content-api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4062aa9ffde9f2910d34254db12df2c1d3b78a01
4
- data.tar.gz: 662161cddc06d147f641b9227e7960c55289743d
3
+ metadata.gz: 0fd5b3de7484a150d6f7d3863707dcf309179975
4
+ data.tar.gz: 2cad7c87c7e9782a83579fe0da86b5e0f6c246f1
5
5
  SHA512:
6
- metadata.gz: 2bd9e62b3774b1b5e2e625ba79ecce0a92a59bc31802154eccd4fc3bbb71754d891bb165c3a6dd6d80e2e7b09cb447eeb1e3eb43723bcfe08d3a35acffe28894
7
- data.tar.gz: f8ae772b6626a0831dbb162302de38cd82abbbb26dc8944fff3eb659daf6ac658777c2b0ecd708449dd90ca0f6a13cf04859049e86f533e27b9d8cfccbffc60e
6
+ metadata.gz: 3e501749753f9667d764809ee92881f698208bd95a935032725854b848c96378d371769fe38cef15637d6088b7ad24e284641b90ed38685bda09c455c9dc1f32
7
+ data.tar.gz: c664d2daa911ca748e2e92a119a67af2af0396ac731b9e9c14cdd01ed77d28f375476e7348c7749b3a72a2e0e3994624238e712218b5022eed9a0d88656ad26a
@@ -29,6 +29,14 @@ module Bing
29
29
  def product_by_batch_id(id)
30
30
  @operations.select { |op| op.batch_id == id }.first.product
31
31
  end
32
+
33
+ def to_body
34
+ json_operations = @operations.map do |op|
35
+ op.bing_operation
36
+ end
37
+
38
+ { entries: json_operations }.to_json
39
+ end
32
40
  end
33
41
  end
34
42
  end
@@ -7,30 +7,12 @@ module Bing
7
7
  end
8
8
 
9
9
  def execute(batch)
10
- post_body = to_body(batch)
10
+ post_body = batch.to_body
11
11
  http_response = @connector.post('/products/batch', post_body)
12
12
  body = JSON.parse(http_response.body)
13
13
  entries = body["entries"]
14
14
 
15
- response = Bing::Content::Api::Response.new
16
- response.set_all_products(batch.all_products)
17
-
18
- entries.each do |entry|
19
- id = entry["batchId"].to_i
20
- response.add_success(batch.product_by_batch_id(id))
21
- end
22
-
23
- response
24
- end
25
-
26
- private
27
-
28
- def to_body(batch)
29
- operations = batch.operations.map do |op|
30
- op.bing_operation
31
- end
32
-
33
- { entries: operations }.to_json
15
+ Bing::Content::Api::Response.new(entries, batch)
34
16
  end
35
17
  end
36
18
  end
@@ -2,31 +2,7 @@ module Bing
2
2
  module Content
3
3
  module Api
4
4
  class Product
5
- attr_reader :offer_id
6
-
7
- def initialize(offer_id,
8
- title,
9
- description,
10
- price,
11
- currency,
12
- product_link,
13
- image_link,
14
- target_country="US",
15
- content_language="en",
16
- availability="in stock",
17
- channel="online")
18
- @offer_id = offer_id
19
- @title = title
20
- @description = description
21
- @price = price
22
- @currency = currency
23
- @product_link = product_link
24
- @image_link = image_link
25
- @target_country = target_country
26
- @content_language = content_language
27
- @availability = availability
28
- @channel = channel
29
- end
5
+ attr_accessor :offer_id, :title, :description, :price, :currency, :product_link, :image_link, :target_country, :content_language, :availability, :channel, :product_type, :product_category, :condition
30
6
 
31
7
  def bing_product_id
32
8
  "#{@channel}:#{@content_language}:#{@target_country}:#{@offer_id}"
@@ -44,7 +20,9 @@ module Bing
44
20
  "contentLanguage" => @content_language,
45
21
  "availability" => @availability,
46
22
  "channel" => @channel,
47
- "condition" => "new",
23
+ "condition" => @condition,
24
+ "productType" => @product_type,
25
+ "googleProductCategory" => @product_category,
48
26
  }
49
27
  end
50
28
  end
@@ -2,19 +2,20 @@ module Bing
2
2
  module Content
3
3
  module Api
4
4
  class Response
5
- def initialize
5
+ def initialize(response_entries, batch)
6
+ @failures = batch.all_products
6
7
  @successes = []
7
- @failures = []
8
+
9
+ response_entries.each do |entry|
10
+ id = entry["batchId"].to_i
11
+ add_success(batch.product_by_batch_id(id))
12
+ end
8
13
  end
9
14
 
10
15
  def add_success(product)
11
16
  @failures.delete_if { |prod| prod.offer_id == product.offer_id }
12
17
  @successes << product
13
18
  end
14
-
15
- def set_all_products(products)
16
- @failures = products
17
- end
18
19
  end
19
20
  end
20
21
  end
@@ -1,7 +1,7 @@
1
1
  module Bing
2
2
  module Content
3
3
  module Api
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing-content-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul David