bing-content-api 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fd5b3de7484a150d6f7d3863707dcf309179975
|
4
|
+
data.tar.gz: 2cad7c87c7e9782a83579fe0da86b5e0f6c246f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
-
|
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" =>
|
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
|
-
|
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
|